Must AutoIt
Сообщения: 3054
Благодарности: 1009
|
Профиль
|
Сайт
|
Отправить PM
| Цитировать
Как вариант:
Код: 
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
$hGUI = GUICreate("_GUICtrlCreateButtonEx")
$aButton = _GUICtrlCreateButtonEx("Click Me here", 50, 80, -1, 30, "shell32.dll", 23)
GUICtrlSetColor(-1, 0xff0000)
GUISetState()
While 1
Switch GUIGetMsg()
Case $GUI_EVENT_CLOSE
Exit
Case $aButton[1]
$iButtonRandomIcon = Random(0, 50, 0)
GUICtrlSetImage($aButton[0], "shell32.dll", -$iButtonRandomIcon)
EndSwitch
WEnd
Func _GUICtrlCreateButtonEx($sText, $iLeft, $iTop, $iWidth, $iHeight, $sIconFile="", $nIconIndex=0)
Local $aRetArr[2]
$aRetArr[0] = GUICtrlCreateIcon($sIconFile, $nIconIndex, $iLeft + 5, $iTop + (($iHeight - 16) / 2), 16, 16)
GUICtrlSetState(-1, $GUI_DISABLE)
;GUICtrlSetBkColor(-1, $GUI_BKCOLOR_TRANSPARENT)
$aRetArr[1] = GUICtrlCreateButton(" " & $sText & " ", $iLeft, $iTop, $iWidth, $iHeight, 0x04000000) ;$WS_CLIPSIBLINGS
Return $aRetArr
EndFunc
Или так:
Код: 
#Include <Constants.au3>
#Include <GUIConstantsEx.au3>
#Include <StaticConstants.au3>
#Include <WindowsConstants.au3>
#Include <WinAPI.au3>
#include <GUIImageList.au3>
#include <GUIButton.au3>
Global $hLastWndProc
Global $hBtnCtrlWndProc = DllCallbackRegister('__GUICtrlCreateButton_WndProc', 'ptr', 'hwnd;uint;wparam;lparam')
Global $pBtnCtrlWndProc = DllCallbackGetPtr($hBtnCtrlWndProc)
$hImgLst = _GUIImageList_Create(16, 16, 5, BitOr($ILC_MASK, $ILC_COLOR32), 0, 1)
_GUIImageList_AddIcon($hImgLst, "shell32.dll", -6)
$hForm = GUICreate('Set Button Color - _GUICtrlCreateButtonEx', 370, 65)
$aButton = _GUICtrlCreateButtonEx(' Button', 70, 20, 70, 23, 1, BitOR($SS_CENTER, $SS_CENTERIMAGE), -1, 0xFF0000)
_GUICtrlButton_SetImageList($aButton[0], $hImgLst)
GUISetState()
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
_WinAPI_SetWindowLong($aButton[2], $GWL_WNDPROC, $hLastWndProc)
DllCallbackFree($hBtnCtrlWndProc)
Exit
Case $aButton[0]
MsgBox(64, 'Message', GUICtrlRead($nMsg+1, 1) & ' is pressed.', 0, $hForm)
EndSwitch
WEnd
Func _GUICtrlCreateButtonEx($sText, $iLeft, $iTop, $iWidth = -1, $iHeight = -1, $vButton = 1, $nStyle = -1, $nExStyle = -1, $nColor = -1)
Local $anButton[3]
If IsString($vButton) Then
$anButton[0] = Execute("GUICtrlCreate" & $vButton & "('', $iLeft, $iTop, $iWidth, $iHeight)")
Else
$anButton[0] = GUICtrlCreateButton('', $iLeft, $iTop, $iWidth, $iHeight)
EndIf
$anButton[1] = GUICtrlCreateLabel($sText, $iLeft, $iTop, $iWidth, $iHeight, BitOR($SS_CENTER, $SS_CENTERIMAGE))
$anButton[2] = GUICtrlGetHandle($anButton[0])
GUICtrlSetBkColor($anButton[1], $GUI_BKCOLOR_TRANSPARENT)
GUICtrlSetColor($anButton[1], $nColor)
$hLastWndProc = _WinAPI_SetWindowLong($anButton[2], $GWL_WNDPROC, $pBtnCtrlWndProc)
Return $anButton
EndFunc
Func __GUICtrlCreateButton_WndProc($hWnd, $iMsg, $wParam, $lParam)
Switch $iMsg
Case $WM_PAINT
Local $tRECT = DllStructCreate($tagRECT)
Local $Ret = DllCall('user32.dll', 'int', 'GetUpdateRect', 'hwnd', $hWnd, 'ptr', DllStructGetPtr($tRECT), 'int', 1)
If $Ret[0] Then
_WinAPI_InvalidateRect(GUICtrlGetHandle(_WinAPI_GetDlgCtrlID($hWnd) + 1), $tRECT)
EndIf
EndSwitch
Return _WinAPI_CallWindowProc($hLastWndProc, $hWnd, $iMsg, $wParam, $lParam)
EndFunc
|