Centrinar
11-03-2011, 13:57
Скрипт создания кнопок с картинками, не получается поменять цвет надписи
#Include <GuiButton.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <GuiImageList.au3>
$hImagebtn = _GUIImageList_Create(150, 100)
$hH1 = _GUIImageList_AddBitmap($hImagebtn, @ScriptDir & "\img_black.bmp")
$hH2 = _GUIImageList_AddBitmap($hImagebtn, @ScriptDir & "\img_over.bmp")
$hH3 = _GUIImageList_AddBitmap($hImagebtn, @ScriptDir & "\img_white.bmp")
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 350, 200, 100, 100)
$Button1 = GUICtrlCreateButton("Супер кнопка", 100, 50, 150, 100)
GUICtrlSetFont(-1, 16, 600, 2, 'Times New Roman')
_GUICtrlButton_SetImageList(-1, $hImagebtn, 4)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
Case $Button1
GUICtrlSetState($Button1, $GUI_DISABLE)
Sleep(2000)
GUICtrlSetState($Button1, $GUI_ENABLE)
MsgBox(0, '', 'Супер кнопка')
EndSwitch
WEnd
При использовании GUICtrlSetColor(-1,0xff0000) картинки исчезают.
Как вариант:
#include (http://www.autoitscript.com/autoit3/docs/keywords.htm##include) <GUIConstantsEx.au3>
#include (http://www.autoitscript.com/autoit3/docs/keywords.htm##include) <WindowsConstants.au3>
$hGUI = GUICreate (http://www.autoitscript.com/autoit3/docs/functions/GUICreate.htm)("_GUICtrlCreateButtonEx")
$aButton = _GUICtrlCreateButtonEx("Click Me here", 50, 80, -1, 30, "shell32.dll", 23)
GUICtrlSetColor (http://www.autoitscript.com/autoit3/docs/functions/GUICtrlSetColor.htm)(-1, 0xff0000)
GUISetState (http://www.autoitscript.com/autoit3/docs/functions/GUISetState.htm)()
While (http://www.autoitscript.com/autoit3/docs/keywords.htm#While) 1
Switch (http://www.autoitscript.com/autoit3/docs/keywords.htm#Switch) GUIGetMsg (http://www.autoitscript.com/autoit3/docs/functions/GUIGetMsg.htm)()
Case (http://www.autoitscript.com/autoit3/docs/keywords.htm#Case) $GUI_EVENT_CLOSE
Exit (http://www.autoitscript.com/autoit3/docs/keywords.htm#Exit)
Case (http://www.autoitscript.com/autoit3/docs/keywords.htm#Case) $aButton[1]
$iButtonRandomIcon = Random (http://www.autoitscript.com/autoit3/docs/functions/Random.htm)(0, 50, 0)
GUICtrlSetImage (http://www.autoitscript.com/autoit3/docs/functions/GUICtrlSetImage.htm)($aButton[0], "shell32.dll", -$iButtonRandomIcon)
EndSwitch (http://www.autoitscript.com/autoit3/docs/keywords.htm#EndSwitch)
WEnd (http://www.autoitscript.com/autoit3/docs/keywords.htm#WEnd)
Func (http://www.autoitscript.com/autoit3/docs/keywords.htm#Func) _GUICtrlCreateButtonEx($sText, $iLeft, $iTop, $iWidth, $iHeight, $sIconFile="", $nIconIndex=0)
Local (http://www.autoitscript.com/autoit3/docs/keywords.htm#Local) $aRetArr[2]
$aRetArr[0] = GUICtrlCreateIcon (http://www.autoitscript.com/autoit3/docs/functions/GUICtrlCreateIcon.htm)($sIconFile, $nIconIndex, $iLeft + 5, $iTop + (($iHeight - 16) / 2), 16, 16)
GUICtrlSetState (http://www.autoitscript.com/autoit3/docs/functions/GUICtrlSetState.htm)(-1, $GUI_DISABLE)
;GUICtrlSetBkColor(-1, $GUI_BKCOLOR_TRANSPARENT)
$aRetArr[1] = GUICtrlCreateButton (http://www.autoitscript.com/autoit3/docs/functions/GUICtrlCreateButton.htm)(" " & $sText & " ", $iLeft, $iTop, $iWidth, $iHeight, 0x04000000) ;$WS_CLIPSIBLINGS
Return (http://www.autoitscript.com/autoit3/docs/keywords.htm#Return) $aRetArr
EndFunc (http://www.autoitscript.com/autoit3/docs/keywords.htm#EndFunc)
Или так:
#Include (http://www.autoitscript.com/autoit3/docs/keywords.htm##include) <Constants.au3>
#Include (http://www.autoitscript.com/autoit3/docs/keywords.htm##include) <GUIConstantsEx.au3>
#Include (http://www.autoitscript.com/autoit3/docs/keywords.htm##include) <StaticConstants.au3>
#Include (http://www.autoitscript.com/autoit3/docs/keywords.htm##include) <WindowsConstants.au3>
#Include (http://www.autoitscript.com/autoit3/docs/keywords.htm##include) <WinAPI.au3>
#include (http://www.autoitscript.com/autoit3/docs/keywords.htm##include) <GUIImageList.au3>
#include (http://www.autoitscript.com/autoit3/docs/keywords.htm##include) <GUIButton.au3>
Global (http://www.autoitscript.com/autoit3/docs/keywords.htm#Global) $hLastWndProc
Global (http://www.autoitscript.com/autoit3/docs/keywords.htm#Global) $hBtnCtrlWndProc = DllCallbackRegister (http://www.autoitscript.com/autoit3/docs/functions/DllCallbackRegister.htm)('__GUICtrlCreateButton_WndProc', 'ptr', 'hwnd;uint;wparam;lparam')
Global (http://www.autoitscript.com/autoit3/docs/keywords.htm#Global) $pBtnCtrlWndProc = DllCallbackGetPtr (http://www.autoitscript.com/autoit3/docs/functions/DllCallbackGetPtr.htm)($hBtnCtrlWndProc)
$hImgLst = _GUIImageList_Create (http://dundats.mvps.org/help/html/libfunctions/_guiimagelist_create.htm)(16, 16, 5, BitOr (http://www.autoitscript.com/autoit3/docs/functions/BitOR.htm)($ILC_MASK, $ILC_COLOR32), 0, 1)
_GUIImageList_AddIcon (http://dundats.mvps.org/help/html/libfunctions/_guiimagelist_addicon.htm)($hImgLst, "shell32.dll", -6)
$hForm = GUICreate (http://www.autoitscript.com/autoit3/docs/functions/GUICreate.htm)('Set Button Color - _GUICtrlCreateButtonEx', 370, 65)
$aButton = _GUICtrlCreateButtonEx(' Button', 70, 20, 70, 23, 1, BitOR (http://www.autoitscript.com/autoit3/docs/functions/BitOR.htm)($SS_CENTER, $SS_CENTERIMAGE), -1, 0xFF0000)
_GUICtrlButton_SetImageList (http://dundats.mvps.org/help/html/libfunctions/_guictrlbutton_setimagelist.htm)($aButton[0], $hImgLst)
GUISetState (http://www.autoitscript.com/autoit3/docs/functions/GUISetState.htm)()
While (http://www.autoitscript.com/autoit3/docs/keywords.htm#While) 1
$nMsg = GUIGetMsg (http://www.autoitscript.com/autoit3/docs/functions/GUIGetMsg.htm)()
Switch (http://www.autoitscript.com/autoit3/docs/keywords.htm#Switch) $nMsg
Case (http://www.autoitscript.com/autoit3/docs/keywords.htm#Case) $GUI_EVENT_CLOSE
_WinAPI_SetWindowLong (http://dundats.mvps.org/help/html/libfunctions/_winapi_setwindowlong.htm)($aButton[2], $GWL_WNDPROC, $hLastWndProc)
DllCallbackFree (http://www.autoitscript.com/autoit3/docs/functions/DllCallbackFree.htm)($hBtnCtrlWndProc)
Exit (http://www.autoitscript.com/autoit3/docs/keywords.htm#Exit)
Case (http://www.autoitscript.com/autoit3/docs/keywords.htm#Case) $aButton[0]
MsgBox (http://www.autoitscript.com/autoit3/docs/functions/MsgBox.htm)(64, 'Message', GUICtrlRead (http://www.autoitscript.com/autoit3/docs/functions/GUICtrlRead.htm)($nMsg+1, 1) & ' is pressed.', 0, $hForm)
EndSwitch (http://www.autoitscript.com/autoit3/docs/keywords.htm#EndSwitch)
WEnd (http://www.autoitscript.com/autoit3/docs/keywords.htm#WEnd)
Func (http://www.autoitscript.com/autoit3/docs/keywords.htm#Func) _GUICtrlCreateButtonEx($sText, $iLeft, $iTop, $iWidth = -1, $iHeight = -1, $vButton = 1, $nStyle = -1, $nExStyle = -1, $nColor = -1)
Local (http://www.autoitscript.com/autoit3/docs/keywords.htm#Local) $anButton[3]
If (http://www.autoitscript.com/autoit3/docs/keywords.htm#If) IsString (http://www.autoitscript.com/autoit3/docs/functions/IsString.htm)($vButton) Then (http://www.autoitscript.com/autoit3/docs/keywords.htm#Then)
$anButton[0] = Execute (http://www.autoitscript.com/autoit3/docs/functions/Execute.htm)("GUICtrlCreate" & $vButton & "('', $iLeft, $iTop, $iWidth, $iHeight)")
Else (http://www.autoitscript.com/autoit3/docs/keywords.htm#Else)
$anButton[0] = GUICtrlCreateButton (http://www.autoitscript.com/autoit3/docs/functions/GUICtrlCreateButton.htm)('', $iLeft, $iTop, $iWidth, $iHeight)
EndIf (http://www.autoitscript.com/autoit3/docs/keywords.htm#EndIf)
$anButton[1] = GUICtrlCreateLabel (http://www.autoitscript.com/autoit3/docs/functions/GUICtrlCreateLabel.htm)($sText, $iLeft, $iTop, $iWidth, $iHeight, BitOR (http://www.autoitscript.com/autoit3/docs/functions/BitOR.htm)($SS_CENTER, $SS_CENTERIMAGE))
$anButton[2] = GUICtrlGetHandle (http://www.autoitscript.com/autoit3/docs/functions/GUICtrlGetHandle.htm)($anButton[0])
GUICtrlSetBkColor (http://www.autoitscript.com/autoit3/docs/functions/GUICtrlSetBkColor.htm)($anButton[1], $GUI_BKCOLOR_TRANSPARENT)
GUICtrlSetColor (http://www.autoitscript.com/autoit3/docs/functions/GUICtrlSetColor.htm)($anButton[1], $nColor)
$hLastWndProc = _WinAPI_SetWindowLong (http://dundats.mvps.org/help/html/libfunctions/_winapi_setwindowlong.htm)($anButton[2], $GWL_WNDPROC, $pBtnCtrlWndProc)
Return (http://www.autoitscript.com/autoit3/docs/keywords.htm#Return) $anButton
EndFunc (http://www.autoitscript.com/autoit3/docs/keywords.htm#EndFunc)
Func (http://www.autoitscript.com/autoit3/docs/keywords.htm#Func) __GUICtrlCreateButton_WndProc($hWnd, $iMsg, $wParam, $lParam)
Switch (http://www.autoitscript.com/autoit3/docs/keywords.htm#Switch) $iMsg
Case (http://www.autoitscript.com/autoit3/docs/keywords.htm#Case) $WM_PAINT
Local (http://www.autoitscript.com/autoit3/docs/keywords.htm#Local) $tRECT = DllStructCreate (http://www.autoitscript.com/autoit3/docs/functions/DllStructCreate.htm)($tagRECT)
Local (http://www.autoitscript.com/autoit3/docs/keywords.htm#Local) $Ret = DllCall (http://www.autoitscript.com/autoit3/docs/functions/DllCall.htm)('user32.dll', 'int', 'GetUpdateRect', 'hwnd', $hWnd, 'ptr', DllStructGetPtr (http://www.autoitscript.com/autoit3/docs/functions/DllStructGetPtr.htm)($tRECT), 'int', 1)
If (http://www.autoitscript.com/autoit3/docs/keywords.htm#If) $Ret[0] Then (http://www.autoitscript.com/autoit3/docs/keywords.htm#Then)
_WinAPI_InvalidateRect (http://dundats.mvps.org/help/html/libfunctions/_winapi_invalidaterect.htm)(GUICtrlGetHandle (http://www.autoitscript.com/autoit3/docs/functions/GUICtrlGetHandle.htm)(_WinAPI_GetDlgCtrlID (http://dundats.mvps.org/help/html/libfunctions/_winapi_getdlgctrlid.htm)($hWnd) + 1), $tRECT)
EndIf (http://www.autoitscript.com/autoit3/docs/keywords.htm#EndIf)
EndSwitch (http://www.autoitscript.com/autoit3/docs/keywords.htm#EndSwitch)
Return (http://www.autoitscript.com/autoit3/docs/keywords.htm#Return) _WinAPI_CallWindowProc (http://dundats.mvps.org/help/html/libfunctions/_winapi_callwindowproc.htm)($hLastWndProc, $hWnd, $iMsg, $wParam, $lParam)
EndFunc (http://www.autoitscript.com/autoit3/docs/keywords.htm#EndFunc)
Centrinar
11-03-2011, 20:41
А можно тогда еще пример создания кнопки из GUICtrlCreateLabel
можно тогда еще пример создания кнопки из GUICtrlCreateLabel »
Зачем?
Для общего развития »
Не вижу тут развития. Label это строка, Button это кнопка. Зачем путать и делать из одного другое?
Centrinar
12-03-2011, 00:05
а как правильно делают кнопки в стиле надписи?
как правильно делают кнопки в стиле надписи? »
Это уже не кнопки, а надписи :)
Если нужно просто создать надпись, и чтобы была реакция при нажатий на неё, то точно также как проверяется нажатие кнопки - проверяется нажатие Label'а (Case $nMsg = $nLabel).
vBulletin v3.6.4, Copyright ©2000-2025, Jelsoft Enterprises Ltd.