Jump to content
Sign in to follow this  
Edifice

GUICtrlCreateCheckbox

Recommended Posts

Edifice

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?

Share this post


Link to post
Share on other sites
Nahuel

Try:

GuiCtrlSetState($CheckBoxID,$GUI_DISABLE)

Share this post


Link to post
Share on other sites
WideBoyDixon

#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

Share this post


Link to post
Share on other sites
Nahuel

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

Share this post


Link to post
Share on other sites
WideBoyDixon

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

Share this post


Link to post
Share on other sites
Nahuel

Good point. I stand corrected.

Share this post


Link to post
Share on other sites
Edifice

Better late than never: Thanks guys! Really helped me out! :D

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
Sign in to follow this  

×