Demo text in Gui Edit control?

Get help with using AutoHotkey and its commands and hotkeys
Posts: 1
Joined: 08 May 2019, 00:57

Demo text in Gui Edit control?

08 May 2019, 01:11

I'm trying to figure out if it's possible to have "demo" text in some of the Edit fields in my gui. I'd like it to work like some websites do, where they have light grey text in the field until it gets focus, or has text already entered into it. I'm familiar with having default text entered, but the user has to delete that text to enter their own, which isn't what I'm hoping for. Thanks in advance if you have any insight.
Last edited by LeonJames on 09 May 2019, 15:27, edited 1 time in total.
Posts: 4947
Joined: 30 Sep 2013, 06:48

Re: Demo text in Gui Edit control?

08 May 2019, 02:03

I think what you are looking for is called a "cue banner", not "demo text" (at least in MS Windows). There are some threads in the forum about this. For example:

(I will move your thread to the "Ask for Help" forum... seems more adequate.)
User avatar
Posts: 371
Joined: 05 Oct 2015, 16:41

Re: Demo text in Gui Edit control?

08 May 2019, 02:08

You're looking for EM_SETCUEBANNER.

In the following script, notice the second parameter (wParam) of SendMessage. If True, the hint text is displayed even when the Edit control has focus.

Code: Select all

; Generated by AutoGUI 2.5.7
#SingleInstance Force
SetWorkingDir %A_ScriptDir%
SetBatchLines -1

Menu Tray, Icon, shell32.dll, 3

Gui Font, s9, Segoe UI
Gui Color, White
Gui Add, Edit, hWndhEdtValue x160 y140 w300 h21
SendMessage 0x1501, 1, "Search",, ahk_id %hEdtValue% ; EM_SETCUEBANNER
Gui Add, Edit, hWndhEdtValue2 x160 y198 w300 h21
SendMessage 0x1501, 0, "Search",, ahk_id %hEdtValue2% ; EM_SETCUEBANNER
Gui Add, ComboBox, hWndhCbxItems x160 y257 w300, ComboBox
hCbxEdit := DllCall("GetWindow", "Ptr", hCbxItems, "UInt", 5, "Ptr") ; GW_CHILD
SendMessage 0x1501, 0, "Search",, ahk_id %hCbxEdit% ; EM_SETCUEBANNER

Gui Show, w620 h420, Hint Text Example

There is an option called "Hint Text" for Edits and ComboBoxes in the GUI designer of AutoGUI.
just me
Posts: 7228
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: Demo text in Gui Edit control?

08 May 2019, 04:07



EM_SETCUEBANNER is always expecting the passed cue text as Unicode, even if you run AHK ANSI. That's why DllCall()might be the more general approach:

Code: Select all

DllCall("SendMessage", "Ptr",  hEdtValue, "UInt", 0x1501, "Ptr", 1, "WStr", "Search", "UInt") ; EM_SETCUEBANNER

Return to “Ask For Help”

Who is online

Users browsing this forum: armoz, Bing [Bot], RubbeH and 48 guests