maniootek Posted July 18, 2016 Share Posted July 18, 2016 (edited) I am new with Windows Message events. I am looking for a way to register the moment when user click on the checkbox. I could not find any example on the forum which use GUIRegisterMsg() function. Can anyone help me? Added: Of course this is about the checkbox control created with AutoIt (I have handle etc.) Edited July 18, 2016 by maniootek Link to comment Share on other sites More sharing options...
mikell Posted July 18, 2016 Share Posted July 18, 2016 Use WM_COMMAND for that Example slightly adapted from the help file : expandcollapse popup#include <GuiButton.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> Global $g_idChk, $g_idMemo Example() Func Example() Local $hGUI $hGUI = GUICreate("Buttons", 400, 400) $g_idMemo = GUICtrlCreateEdit("", 119, 10, 276, 374, $WS_VSCROLL) GUICtrlSetFont($g_idMemo, 9, 400, 0, "Courier New") $g_idChk = GUICtrlCreateCheckbox("Check1", 10, 120, 90, 50) GUIRegisterMsg($WM_COMMAND, "WM_COMMAND") GUISetState(@SW_SHOW) MemoWrite("$g_idChk : " & $g_idChk & @CRLF) While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE ExitLoop EndSwitch WEnd Exit EndFunc ;==>Example ; Write a line to the memo control Func MemoWrite($sMessage) GUICtrlSetData($g_idMemo, $sMessage & @CRLF, 1) EndFunc ;==>MemoWrite ; React on a button click Func WM_COMMAND($hWnd, $iMsg, $wParam, $lParam) #forceref $hWnd, $iMsg Local $nNotifyCode = BitShift($wParam, 16) Local $nID = BitAND($wParam, 0x0000FFFF) Local $hCtrl = $lParam Local $sText = "" Switch $nID Case $g_idChk Switch $nNotifyCode Case $BN_CLICKED $sText = "$BN_CLICKED" & @CRLF EndSwitch MemoWrite($sText & _ "-----------------------------" & @CRLF & _ "WM_COMMAND - Infos:" & @CRLF & _ "-----------------------------" & @CRLF & _ "Code" & @TAB & ":" & $nNotifyCode & @CRLF & _ "CtrlID" & @TAB & ":" & $nID & @CRLF & _ "CtrlHWnd:" & $hCtrl & @CRLF & _ (_GUICtrlButton_GetState($hCtrl) = 521 ? "checked" : "unchecked") & @CRLF) Return 0 ; Only workout clicking on the button EndSwitch Return $GUI_RUNDEFMSG EndFunc ;==>WM_COMMAND maniootek 1 Link to comment Share on other sites More sharing options...
maniootek Posted July 21, 2016 Author Share Posted July 21, 2016 now I found it, it's under Function Reference _GUICtrlButton_Create I was looking under checkbox functions Thank you anyway. Link to comment Share on other sites More sharing options...
Terenz Posted July 21, 2016 Share Posted July 21, 2016 Why complicate things? WM_COMMAND is useful but not for such task since we have GuiGetMsg if is just check if a checkbox is checked or not! #include <GUIConstantsEx.au3> $Form = GUICreate("Form1", 251, 147, -1, -1) $Checkbox = GUICtrlCreateCheckbox("Checkbox", 72, 56) GUISetState(@SW_SHOW) While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $Checkbox If GUICtrlRead($Checkbox) = $GUI_CHECKED Then ConsoleWrite("CHECKED" & @CRLF) ElseIf GUICtrlRead($Checkbox) = $GUI_UNCHECKED Then ConsoleWrite("UNCHECKED" & @CRLF) EndIf EndSwitch WEnd maniootek 1 Nothing is so strong as gentleness. Nothing is so gentle as real strength Link to comment Share on other sites More sharing options...
maniootek Posted July 21, 2016 Author Share Posted July 21, 2016 You right. It's better way in this case Link to comment Share on other sites More sharing options...
mikell Posted July 21, 2016 Share Posted July 21, 2016 If guiGetMsg() fits your needs then it's nice But - depending of the use, of course - GUIRegisterMsg() could sometimes be useful because it always work. Here is a simple test expandcollapse popup#include <GuiButton.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> Global $g_idChk, $g_idMemo Example() Func Example() Local $hGUI $hGUI = GUICreate("Buttons", 400, 400) $g_idMemo = GUICtrlCreateEdit("", 119, 10, 276, 374, $WS_VSCROLL) GUICtrlSetFont($g_idMemo, 9, 400, 0, "Courier New") $g_idChk = GUICtrlCreateCheckbox("Check1", 10, 120, 90, 50) GUIRegisterMsg($WM_COMMAND, "WM_COMMAND") GUISetState(@SW_SHOW) For $i = 1 to 50 MemoWrite($i ) Sleep(100) Next While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE ExitLoop EndSwitch WEnd Exit EndFunc ;==>Example ; Write a line to the memo control Func MemoWrite($sMessage) GUICtrlSetData($g_idMemo, $sMessage & @CRLF, 1) EndFunc ;==>MemoWrite ; React on a button click Func WM_COMMAND($hWnd, $iMsg, $wParam, $lParam) #forceref $hWnd, $iMsg Local $nNotifyCode = BitShift($wParam, 16) Local $nID = BitAND($wParam, 0x0000FFFF) Local $hCtrl = $lParam Local $sText = "" Switch $nID Case $g_idChk Switch $nNotifyCode Case $BN_CLICKED $sText = "$BN_CLICKED" & @CRLF EndSwitch MemoWrite($sText & _ "-----------------------------" & @CRLF & _ "WM_COMMAND - Infos:" & @CRLF & _ "-----------------------------" & @CRLF & _ "Code" & @TAB & ":" & $nNotifyCode & @CRLF & _ "CtrlID" & @TAB & ":" & $nID & @CRLF & _ "CtrlHWnd:" & $hCtrl & @CRLF & _ (_GUICtrlButton_GetState($hCtrl) = 521 ? "checked" : "unchecked") & @CRLF) Return 0 ; Only workout clicking on the button EndSwitch Return $GUI_RUNDEFMSG EndFunc ;==>WM_COMMAND MichaelHB 1 Link to comment Share on other sites More sharing options...
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