Viktor1703
AutoIT Гуру
- Сообщения
- 1,535
- Репутация
- 413
Есть проблема, если окно убрать за пределы рабочего стола то фон кнопки пропадает, не пойму как зафиксировать применённый фон?
Код:
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <GUIButton.au3>
#include <GUIImageList.au3>
#include <WinAPIEx.au3>
#include <FontConstants.au3>
#include <GDIPlus.au3>
$hForm = GUICreate('Button', 350, 200)
$OK_Button = GUICtrlCreateButton('OK', 25, 170, 70, 23)
_GUICtrlButton_SetTextColor($OK_Button)
$Cancel_Button = GUICtrlCreateButton('Cancel', 110, 170, 70, 23)
_GUICtrlButton_SetTextColor($Cancel_Button)
GUISetState()
$hDC = _WinAPI_GetDC($hForm)
$hMemDC = _WinAPI_CreateCompatibleDC($hDC)
_WinAPI_SelectObject($hMemDC, _WinAPI_CreateCompatibleBitmap($hDC, 350, 200))
_WinAPI_Rectangle($hMemDC, _WinAPI_CreateRectEx(0, 0, 350, 200))
_WinAPI_SelectObject($hMemDC, _WinAPI_CreatePen($PS_DASH, 17, _WinAPI_SwitchColor(0xFF7F7F)))
_WinAPI_Rectangle($hMemDC, _WinAPI_CreateRectEx(110 + 10, 170 + 10, 70 - 20, 23 - 20))
While 1
_WinAPI_BitBlt($hDC, 0, 0, 350, 200, $hMemDC, 0, 0, $SRCAND)
Switch GUIGetMsg()
Case $GUI_EVENT_CLOSE
Exit
EndSwitch
WEnd
Func _GUICtrlButton_SetTextColor($iCtrlID, $iTextColor = 0x010101, $iShadowColor = 0x404040, $sText = '')
Local $hWnd, $hTheme, $hImageList, $hBitmap, $hObj, $hDC, $hMemDC, $tRect, $pRect, $Data, $Width, $Height, $Prev = -1
If $sText = '' Then
$sText = GUICtrlRead($iCtrlID, 1)
EndIf
$hWnd = GUICtrlGetHandle($iCtrlID)
If Not $hWnd Or StringStripWS($sText, 8) = '' Then
Return 0
EndIf
$hTheme = _WinAPI_OpenThemeData($hWnd, 'Button')
If @error Or Not $hTheme Then
GUICtrlSetColor($iCtrlID, $iTextColor)
GUICtrlSetData($iCtrlID, $sText)
Return $sText
EndIf
$Width = _WinAPI_GetClientWidth($hWnd)
$Height = _WinAPI_GetClientHeight($hWnd)
$hImageList = _GUIImageList_Create($Width - 8, $Height - 8, 4, 4)
$hBitmap = _WinAPI_CreateBitmap($Width - 8, $Height - 8, 1, 32)
$tRect = DllStructCreate('int[4]')
DllStructSetData($tRect, 1, -4, 1)
DllStructSetData($tRect, 1, -4, 2)
DllStructSetData($tRect, 1, $Width - 4, 3)
DllStructSetData($tRect, 1, $Height - 4, 4)
$pRect = DllStructGetPtr($tRect)
$hDC = _WinAPI_GetDC(0)
$hMemDC = _WinAPI_CreateCompatibleDC($hDC)
_WinAPI_ReleaseDC(0, $hDC)
_WinAPI_SelectObject($hMemDC, _SendMessage($hWnd, $WM_GETFONT))
_WinAPI_SetTextColor($hMemDC, BitOR(BitAND($iTextColor, 0x00FF00), BitShift(BitAND($iTextColor, 0x0000FF), -16), BitShift(BitAND($iTextColor, 0xFF0000), 16)))
_WinAPI_SetBkMode($hMemDC, $TRANSPARENT)
; PBS_NORMAL
$hObj = _WinAPI_SelectObject($hMemDC, $hBitmap)
DllCall('uxtheme.dll', 'int', 'DrawThemeBackground', 'ptr', $hTheme, 'hwnd', $hMemDC, 'int', 1, 'int', 1, 'ptr', $pRect, 'ptr', 0)
_WinAPI_DrawText($hMemDC, $sText, $tRect, BitOR($DT_CENTER, $DT_SINGLELINE, $DT_VCENTER))
_WinAPI_SelectObject($hMemDC, $hObj)
_GUIImageList_Add($hImageList, $hBitmap)
; PBS_HOT
$hObj = _WinAPI_SelectObject($hMemDC, $hBitmap)
DllCall('uxtheme.dll', 'int', 'DrawThemeBackground', 'ptr', $hTheme, 'hwnd', $hMemDC, 'int', 1, 'int', 2, 'ptr', $pRect, 'ptr', 0)
_WinAPI_DrawShadowText($hMemDC, $sText, $iTextColor, $iShadowColor, 3, 3, $tRECT, BitOR($DT_CENTER, $DT_SINGLELINE, $DT_VCENTER))
_WinAPI_SelectObject($hMemDC, $hObj)
_GUIImageList_Add($hImageList, $hBitmap)
; PBS_PRESSED
$hObj = _WinAPI_SelectObject($hMemDC, $hBitmap)
DllCall('uxtheme.dll', 'int', 'DrawThemeBackground', 'ptr', $hTheme, 'hwnd', $hMemDC, 'int', 1, 'int', 3, 'ptr', $pRect, 'ptr', 0)
_WinAPI_DrawText($hMemDC, $sText, $tRect, BitOR($DT_CENTER, $DT_SINGLELINE, $DT_VCENTER))
_WinAPI_SelectObject($hMemDC, $hObj)
_GUIImageList_Add($hImageList, $hBitmap)
; PBS_DISABLED
$hObj = _WinAPI_SelectObject($hMemDC, $hBitmap)
DllCall('uxtheme.dll', 'int', 'DrawThemeBackground', 'ptr', $hTheme, 'hwnd', $hMemDC, 'int', 1, 'int', 4, 'ptr', $pRect, 'ptr', 0)
$Data = DllCall('uxtheme.dll', 'int', 'GetThemeColor', 'ptr', $hTheme, 'int', 1, 'int', 4, 'int', 3803, 'dword*', 0)
If (Not @error) And (Not $Data[0]) Then
$Prev = _WinAPI_SetTextColor($hMemDC, $Data[5])
EndIf
_WinAPI_DrawText($hMemDC, $sText, $tRect, BitOR($DT_CENTER, $DT_SINGLELINE, $DT_VCENTER))
If $Prev > -1 Then
_WinAPI_SetTextColor($hMemDC, $Prev)
EndIf
_WinAPI_SelectObject($hMemDC, $hObj)
_GUIImageList_Add($hImageList, $hBitmap)
; PBS_DEFAULTED
$hObj = _WinAPI_SelectObject($hMemDC, $hBitmap)
DllCall('uxtheme.dll', 'int', 'DrawThemeBackground', 'ptr', $hTheme, 'hwnd', $hMemDC, 'int', 1, 'int', 5, 'ptr', $pRect, 'ptr', 0)
_WinAPI_DrawText($hMemDC, $sText, $tRect, BitOR($DT_CENTER, $DT_SINGLELINE, $DT_VCENTER))
_WinAPI_SelectObject($hMemDC, $hObj)
_GUIImageList_Add($hImageList, $hBitmap)
_WinAPI_DeleteDC($hMemDC)
_WinAPI_DeleteObject($hBitmap)
DllCall('uxtheme.dll', 'int', 'CloseThemeData', 'ptr', $hTheme)
$Data = _GUICtrlButton_GetImageList($hWnd)
If $Data[0] Then
_GUIImageList_Destroy($Data[0])
EndIf
GUICtrlSetData($iCtrlID, '')
If Not _GUICtrlButton_SetImageList($hWnd, $hImageList, 4) Then
_GUIImageList_Destroy($hImageList)
Return 0
EndIf
Return $sText
EndFunc