Jump to content

GUICtrlCreateCheckbox


Recommended Posts

Got a bit of dissapointment as I mis-read the helpfile, and thought I could prevent users from checking the checkbox by flagging it with

$ES_READONLY

as I discovered this flag only covers input controls.

Any other way to do this?

Link to comment
Share on other sites

#include <GUIConstantsEx.au3>
#include <WinAPI.au3>
#include <Constants.au3>
GUICreate("Test", 128, 128)
Global $chkTest = GUICtrlCreateCheckbox("Test", 8, 8, 48, 16)
Global $btnToggle = GUICtrlCreateButton("Normal", 8, 32, 96, 24)
GUISetState()
Global $uiMsg = 0
While $uiMsg <> $GUI_EVENT_CLOSE
    $uiMsg = GUIGetMsg()
    If $uiMsg = $btnToggle Then
        ToggleReadOnly(GUICtrlGetHandle($chkTest))
    EndIf
    Sleep(10)
Wend
Exit
Func ToggleReadOnly($hWnd)
    Local $iStyle = _WinAPI_GetWindowLong($hWnd, $GWL_STYLE)
    If BitAND($iStyle, 4) Then
        $iStyle -= 4
        GUICtrlSetData($btnToggle, "Normal")
    Else
        $iStyle += 4
        GUICtrlSetData($btnToggle, "Read Only")
    EndIf
    _WinAPI_SetWindowLong($hWnd, $GWL_STYLE, $iStyle)
EndFunc

Link to comment
Share on other sites

Excellent example, but using $GUI_DISABLE not only is enough, but also makes it visible that the checkbox is read-only:

#include <GUIConstantsEx.au3>
#include <Constants.au3>

GUICreate("Test", 128, 128)
Global $chkTest = GUICtrlCreateCheckbox("Test", 8, 8, 48, 16)
Global $btnToggle = GUICtrlCreateButton("Read Only", 8, 32, 96, 24)
GUISetState()
Global $uiMsg = 0
While $uiMsg <> $GUI_EVENT_CLOSE
    $uiMsg = GUIGetMsg()
    If $uiMsg = $btnToggle Then
        ToggleReadOnly($chkTest)
    EndIf
    Sleep(10)
Wend
Exit

Func ToggleReadOnly($hWnd)
    Local $iStyle = GUICtrlGetState($hWnd)
    If BitAND($iStyle,$GUI_DISABLE) Then
        GUICtrlSetState($chkTest,$GUI_ENABLE)
        GUICtrlSetData($btnToggle, "Read Only")
    Else
        GUICtrlSetState($chkTest,$GUI_DISABLE)
        GUICtrlSetData($btnToggle, "Normal")
    EndIf
EndFunc
Link to comment
Share on other sites

I was adhering to the help request which asked for a readonly checkbox, not a disabled one :D

Link to comment
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
 Share

  • Recently Browsing   0 members

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