Jump to content

Recommended Posts

Posted (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 by maniootek
Posted

Use WM_COMMAND for that
Example slightly adapted from the help file :

#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

 

Posted

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

 

Nothing is so strong as gentleness. Nothing is so gentle as real strength

 

Posted

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

#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

 

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...