ChrisS85 / CGUI

An object-oriented GUI library for AutoHotkey
22 stars 19 forks source link

Ability to get/set ReadOnly state of edit controls #34

Closed infogulch closed 12 years ago

ChrisS85 commented 12 years ago

Agreed, it should be a property.

infogulch commented 12 years ago

Wait, ReadOnly is already listed in the ControlStyles listing for CEditControl... but it's not working

infogulch commented 12 years ago

Even something like GuiControl, -ReadOnly, Edit1 doesn't work and produces an ErrorLevel.

I tried a normal gui script (non-CGUI) which switches the ReadOnly state of an edit control with the above line and it works fine.

ChrisS85 commented 12 years ago

That is weird, are you sure you didn't make another error?

infogulch commented 12 years ago

Yep, I just checked with your branch and it does the same thing. I'll make a simpler test case and try it again.

infogulch commented 12 years ago

Yep, not working, in both my latest and your current.

    x := new testgui()
    x.show()
return

#Include <CGUI>

class testgui extends CGUI {
    edt := this.AddControl("Edit", "edt", "readonly", "")
    btn := this.AddControl("Button", "btn", "", "Switch")

    btn_Click() {
        this.edt.ReadOnly := !this.edt.ReadOnly
    }
}

Edit: and it doesn't matter if it starts out readonly or not, the button doesn't change it.

Edit2: funny, Control doesn't report any errors and ControlGet reports that the change was applied properly...

confused

infogulch commented 12 years ago

Yep pretty much:

    Gui, Add, Edit, vedt readonly hwndedtHwnd
    Gui, Add, Button, , Change
    Gui, Show
return

ButtonChange:
    ControlGet, get, Style, , , ahk_id %edtHwnd%
    set := get & 0x800 ? "-0x800" : "+0x800"
    msgbox % "before: " get & 0x800 "`nsetting: " set
    Control, Style, % set, , ahk_id %edtHwnd%
return

It actually does toggle numerically. I.e. the style technically changes, but it has no effect... :-/

infogulch commented 12 years ago

Aha! This works great:

    Gui, Add, Edit, vedt readonly hwndedtHwnd
    Gui, Add, Button, , Change
    Gui, +LastFound
    guiHwnd := WinExist()
    Gui, Show
return

ButtonChange:
    ControlGet, get, Style, , , ahk_id %edtHwnd%
    SendMessage, 0xCF, % !(get & 0x800), , , ahk_id %edtHwnd%
return
infogulch commented 12 years ago

I'll work on this and other SendMessage-dependent style changes next.