Deye Posted December 29, 2015 Posted December 29, 2015 (edited) Thanks to a function called GUICtrlGetBkColor by guinnessI have managed to accomplish what I had requested for - Hereexpandcollapse popup#include <GuiConstantsEx.au3> #include <GuiConstants.au3> #include <WinAPI.au3> #include <WinAPIGdi.au3> Global $icontrol, $iNumber $hGUI = GUICreate("Select days of the month", 290, 240, -1, -1) GUISetFont(9, 0, 4, "Comic Sans MS", 2) $Button1 = GUICtrlCreateButton("Return", 55, 180, 80, 40) $Button2 = GUICtrlCreateButton("Cancel", 160, 180, 80, 40) Local $IX = 10 Local $IY = 10 Dim $iRcntrls[29][3] For $i = 1 To 28 If $IX = 290 Then $IX = 10 $IY += 40 EndIf $iRcntrls[$i][0] = GUICtrlCreateGraphic($IX, $IY, 30, 30) $iRcntrls[$i][1] = GUICtrlGetHandle($iRcntrls[$i][0]) GUICtrlSetBkColor(-1, 0xffffff) GUICtrlCreateLabel($i, $IX + 4, $IY + 4, 22, 22) GUICtrlSetBkColor(-1, 0xffffff) $IX += 40 Next GUISetState() _demo() While 1 $msg = GUIGetMsg() Switch $msg Case $GUI_EVENT_CLOSE ExitLoop Case $Button1 $icontrol = "" For $i = 1 To 28 If $iRcntrls[$i][2] Then $icontrol &= $i & "," EndIf Next MsgBox(0, "", StringTrimRight($icontrol, 1)) Case $Button2 $iRcntrls = 0 ExitLoop Case $iRcntrls[1][0] To $iRcntrls[28][0] For $i = 1 To 28 If $msg = $iRcntrls[$i][0] Then If GUICtrlGetBkColor($iRcntrls[$i][0]) = 0X1BDC8 Then $iRcntrls[$iNumber][2] = "" GUICtrlSetBkColor($iRcntrls[$iNumber][0], 0xffffff) GUICtrlSetBkColor($iRcntrls[$iNumber][0] + 1, 0xffffff) Else GUICtrlSetBkColor($iRcntrls[$iNumber][0], 0X1BDC8) GUICtrlSetBkColor($iRcntrls[$iNumber][0] + 1, 0X1BDC8) $iRcntrls[$iNumber][2] = True EndIf EndIf Next EndSwitch WEnd Func _demo() For $i = 1 To 28 ControlClick("", "", $iRcntrls[$i][1]) $i += 2 Next EndFunc ;==>_demo Func GUICtrlGetBkColor($hWnd) ; by guinness (moded) If Not IsHWnd($hWnd) Then $hWnd = GUICtrlGetHandle($hWnd) EndIf For $i = 1 To 28; mod => If $hWnd = $iRcntrls[$i][1] Then $iNumber = $i EndIf Next; mod <= Local $hDC = _WinAPI_GetDC($hWnd) Local $iColor = _WinAPI_GetPixel($hDC, 0, 0) _WinAPI_ReleaseDC($hWnd, $hDC) Return $iColor EndFunc ;==>GUICtrlGetBkColor Edited December 29, 2015 by Deye
wakillon Posted December 30, 2015 Posted December 30, 2015 No need to get the ctrl bkground color ! expandcollapse popup#Region ;************ Includes ************ #include <GuiConstantsEx.au3> #include <WinAPIGdi.au3> #EndRegion ;************ Includes ************ Opt ( 'MustDeclareVars', 1 ) Global $icontrol, $iNumber, $hGUI, $Button1, $Button2, $msg, $iDayCount = 31 $hGUI = GUICreate("Select days of the month", 290, 260, -1, -1) GUISetFont(9, 0, 4, "Comic Sans MS", 2) $Button1 = GUICtrlCreateButton("Return", 55, 210, 80, 40) $Button2 = GUICtrlCreateButton("Cancel", 160, 210, 80, 40) Local $IX = 10, $IY = 10 Dim $aRcntrls[$iDayCount+1][3] For $i = 1 To $iDayCount If $IX = 290 Then $IX = 10 $IY += 40 EndIf $aRcntrls[$i][0] = GUICtrlCreateGraphic($IX, $IY, 30, 30) $aRcntrls[$i][1] = GUICtrlGetHandle($aRcntrls[$i][0]) GUICtrlSetBkColor(-1, 0xffffff) GUICtrlCreateLabel($i, $IX + 4, $IY + 4, 22, 22) GUICtrlSetBkColor(-1, 0xffffff) If Mod ( $i -1, 3 ) = 0 Then GUICtrlSetBkColor ( $aRcntrls[$i][0], 0X1BDC8 ) GUICtrlSetBkColor ( $aRcntrls[$i][0] +1, 0X1BDC8 ) $aRcntrls[$i][2] = True EndIf $IX += 40 Next GUISetState() While 1 $msg = GUIGetMsg() Switch $msg Case $GUI_EVENT_CLOSE, $Button2 $aRcntrls = 0 Exit Case $Button1 $icontrol = "" For $i = 1 To $iDayCount If $aRcntrls[$i][2] Then $icontrol &= $i & "," Next MsgBox(0, "", StringTrimRight($icontrol, 1)) Case $aRcntrls[1][0] To $aRcntrls[$iDayCount][0] For $i = 1 To $iDayCount If $msg = $aRcntrls[$i][0] Then If $aRcntrls[$i][2] = True Then $aRcntrls[$i][2] = "" GUICtrlSetBkColor($aRcntrls[$i][0], 0xffffff) GUICtrlSetBkColor($aRcntrls[$i][0] + 1, 0xffffff) Else GUICtrlSetBkColor($aRcntrls[$i][0], 0X1BDC8) GUICtrlSetBkColor($aRcntrls[$i][0] + 1, 0X1BDC8) $aRcntrls[$i][2] = True EndIf EndIf Next EndSwitch Sleep ( 10 ) WEnd coffeeturtle 1 AutoIt 3.3.14.2 X86 - SciTE 3.6.0 - WIN 8.1 X64 - Other Example Scripts
Deye Posted December 30, 2015 Author Posted December 30, 2015 Thanks wakillon While testing, GUICtrlGetBkColor gave me a clue about adding the GUICtrlGetHandle functionalityby then I forgot that I don't need it Truly there is no need for it as shown in you're exampleCheers
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now