Page 1 of 1

AHK Gui, readonly edit, white background?

Posted: 23 Feb 2014, 10:32
by PuzzledGreatly
How to create a readonly gui edit control with a white background? When I use the readonly option the background goes grey. Thanks.

Re: AHK Gui, readonly edit, white background?

Posted: 23 Feb 2014, 11:53
by Blackholyman
Hmm on my phone but how about just disabling the control

GuiControl, Disable, MyControl

That may work

Re: AHK Gui, readonly edit, white background?

Posted: 23 Feb 2014, 12:17
by jNizM
[CLASS] CtlColors - color your controls - by just me

or an example made by SKAN

Code: Select all

#SingleInstance   Force

BG_COLOR   := 0x995522
FG_COLOR   := 0xFAFAFA

OnMessage( 0x138, "WM_CTLCOLOR" ), OnMessage( 0x133, "WM_CTLCOLOR" )

Gui, Add, Edit, w100,          ReadWrite
Gui, Add, Edit, w100 ReadOnly, ReadOnly
Gui, Add, Edit, w100,          ReadWrite
Gui, Add, Edit, w100 ReadOnly, ReadOnly
Gui, Show

Gui +LastFound
WinSet, Redraw

Return ;                                        // end of auto-execute section //

WM_CTLCOLOR(wParam, lParam, msg, hwnd)
{
    static hBrush := ""
    if (hBrush = "")
    {
        SetEnv, hBrush, % DllCall("Gdi32.dll\CreateSolidBrush", "UInt", BG_COLOR)
    }

    WinGetClass, Class, ahk_id %lParam%

    if (Class = "Edit")
    {
        DllCall("Gdi32.dll\SetTextColor", "UInt", wParam, "UInt", FG_COLOR)
        DllCall("Gdi32.dll\SetBkColor", "UInt", wParam, "UInt", BG_COLOR)
        DllCall("Gdi32.dll\SetBkMode", "UInt", wParam, "UInt", 2)
        return hBrush
    }
    if (Class = "Static")
    {
        DllCall("Gdi32.dll\SetTextColor", "UInt", wParam, "UInt", FG_COLOR)
    }
}

Re: AHK Gui, readonly edit, white background?

Posted: 23 Feb 2014, 13:22
by tmplinshi
Or use a sub GUI:

Code: Select all

Gui, Add, Edit, w200, Normal Edit
hEdit1 := Gui_Add_Edit("w200 h200 cRed ReadOnly", "ReadOnly Edit", "Yellow")
hEdit2 := Gui_Add_Edit("wp-52 c00ff00", "Edit 3", "Black")
Gui, Add, Button, x+5 hp, Modify
Gui, Show
Return

ButtonModify:
	ControlSetText,, NewText, ahk_id %hEdit2%
Return

GuiClose:
ExitApp

Gui_Add_Edit(Options = "", Text = "", bkColor = "")
{
	Gui, Add, Edit, %Options% hwndhwnd -E0x200 -Multi, %Text%
	GuiControlGet, ctrl, pos, %hwnd%
	GuiHwnd := DllCall("GetParent", "UInt", hwnd)

	Gui, New, -Caption +Parent%hwnd%
	if (bkColor != "")
		Gui, Color, %bkColor%, %bkColor%
	Gui, Margin, 0, 0
	Gui, Add, Edit, %Options% w%ctrlW% h%ctrlH% x0 y0 hwndhEdit, %Text%
	Gui, Show, x0 y0

	Gui, %GuiHwnd%:Default
	Return hEdit
}
But I recommend using [CLASS] CtlColors - color your controls - by just me

Re: AHK Gui, readonly edit, white background?

Posted: 23 Feb 2014, 20:03
by PuzzledGreatly
Thanks for the replies, I didn't think this would be so difficult. Disabling via GuiControl just grays out the edit box. Trying to run CtlColorsSample.ahk gives this error:
---------------------------
CtlColors_sample.ahk
---------------------------
Error at line 2.

#Include file "Class_CtlColors.ahk" cannot be opened.

The program will exit.
---------------------------
OK
---------------------------

The code did run after I copied and pasted it into CtlColors_sample.ahk but not as an include. I haven't tried Skan's solution yet. Currently I'm using a listbox which is less than ideal.

Re: AHK Gui, readonly edit, white background?

Posted: 24 Feb 2014, 03:10
by just me
Are you sure that you saved both CtlColors_sample.ahk and Class_CtlColors.ahk into the same folder?