AHK Gui, readonly edit, white background?

Get help with using AutoHotkey and its commands and hotkeys
User avatar
PuzzledGreatly
Posts: 1215
Joined: 29 Sep 2013, 22:18

AHK Gui, readonly edit, white background?

23 Feb 2014, 10:32

How to create a readonly gui edit control with a white background? When I use the readonly option the background goes grey. Thanks.
User avatar
Blackholyman
Posts: 1293
Joined: 29 Sep 2013, 22:57
Facebook: socialjsz
Google: +Jszapp
Location: Denmark
Contact:

Re: AHK Gui, readonly edit, white background?

23 Feb 2014, 11:53

Hmm on my phone but how about just disabling the control

GuiControl, Disable, MyControl

That may work
Also check out:
Courses on AutoHotkey

My Autohotkey Blog
:dance:
User avatar
jNizM
Posts: 3091
Joined: 30 Sep 2013, 01:33
GitHub: jNizM
Contact:

Re: AHK Gui, readonly edit, white background?

23 Feb 2014, 12:17

[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)
    }
}
[AHK] v2.0-beta.15 | [WIN] 11 Pro (Version 22H2) | [GitHub] Profile
tmplinshi
Posts: 1604
Joined: 01 Oct 2013, 14:57

Re: AHK Gui, readonly edit, white background?

23 Feb 2014, 13:22

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
User avatar
PuzzledGreatly
Posts: 1215
Joined: 29 Sep 2013, 22:18

Re: AHK Gui, readonly edit, white background?

23 Feb 2014, 20:03

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.
just me
Posts: 8600
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: AHK Gui, readonly edit, white background?

24 Feb 2014, 03:10

Are you sure that you saved both CtlColors_sample.ahk and Class_CtlColors.ahk into the same folder?

Return to “Ask For Help”

Who is online

Users browsing this forum: Google [Bot], loumizhu, Rohwedder, ThePeter and 58 guests