AHK Gui, readonly edit, white background?
- PuzzledGreatly
- Posts: 1251
- Joined: 29 Sep 2013, 22:18
AHK Gui, readonly edit, white background?
How to create a readonly gui edit control with a white background? When I use the readonly option the background goes grey. Thanks.
- Blackholyman
- Posts: 1293
- Joined: 29 Sep 2013, 22:57
- Facebook: socialjsz
- Google: +Jszapp
- Location: Denmark
- Contact:
Re: AHK Gui, readonly edit, white background?
Hmm on my phone but how about just disabling the control
GuiControl, Disable, MyControl
That may work
GuiControl, Disable, MyControl
That may work
Courses on AutoHotkey
My Autohotkey Blog

Re: AHK Gui, readonly edit, white background?
[CLASS] CtlColors - color your controls - by just me
or an example made by SKAN
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)
}
}
[AHK] v2.0.2 | [WIN] 11 Pro (Version 22H2) | [GitHub] Profile
Re: AHK Gui, readonly edit, white background?
Or use a sub GUI:
But I recommend using [CLASS] CtlColors - color your controls - by just me
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
}
- PuzzledGreatly
- Posts: 1251
- Joined: 29 Sep 2013, 22:18
Re: AHK Gui, readonly edit, white background?
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:
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.
---------------------------
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?
Are you sure that you saved both CtlColors_sample.ahk and Class_CtlColors.ahk into the same folder?
Who is online
Users browsing this forum: Bing [Bot], Descolada, felix_liter, Google [Bot], Rohwedder and 48 guests