Jump to content
Sign in to follow this  
WideBoyDixon

Read-only checkbox

Recommended Posts

WideBoyDixon

Not sure where I stand on cross-posting a topic from the help forum here but I thought it was interesting so feel free to chastise me :D

The following example toggles a checkbox to be read only:

#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

Useful if you want to have the checkbox there for displaying a setting rather than allowing the user to change the setting. Also, a bit more elegant than simply disabling the control :o

WBD

Share this post


Link to post
Share on other sites
gseller

Nice example.. :D I have actually used this in another script that I made a few moons ago..

Share this post


Link to post
Share on other sites
Yashied
KaFu

Sorry, doesn't work for me :D, but changes style of checkbox to controlgroup :o...

Effect only visible if you redraw the window, either by api call (see code below) or if you minimize/maximize the gui...

#include <GUIConstantsEx.au3>
#include <WinAPI.au3>
#include <Constants.au3>
$gui = 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)
    _WinAPI_RedrawWindow($gui)
EndFunc

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  

×