maniootek

Register CheckBox checking with WM_NOTIFY

6 posts in this topic

#1 ·  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

Share this post


Link to post
Share on other sites



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

 

1 person likes this

Share this post


Link to post
Share on other sites

now I found it, it's under 

Function Reference


_GUICtrlButton_Create

I was looking under checkbox functions

Thank you anyway.

Share this post


Link to post
Share on other sites

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

 

1 person likes this

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

 

Share this post


Link to post
Share on other sites

You right. It's better way in this case

Share this post


Link to post
Share on other sites

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

 

1 person likes this

Share this post


Link to post
Share on other sites

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