Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

how to make EM_SETCUEBANNER work?


  • Please log in to reply
7 replies to this topic
hughman
  • Members
  • 192 posts
  • Last active: Feb 14 2016 06:59 AM
  • Joined: 11 Feb 2007
below is my test code:
Gui, Add, Edit, w100 hwndhEdit, 
MsgBox % Edit_SetCueBanner(hEdit, "123")

Gui, Show, w600 h400
Return

GuiEscape:
GuiClose:
ExitApp


Edit_SetCueBanner(hEdit, sText, bFocusShow=0)
{
	t := Ansi4Unicode(&sText)
	SendMessage, 0x1501, bFocusSHow, &t, , ahk_id %hEdit%
	Return ErrorLevel
}

Ansi4Unicode(pString, nSize = "")
{
	If (nSize = "")
	    nSize:=DllCall("kernel32\WideCharToMultiByte", "Uint", 0, "Uint", 0, "Uint", pString, "int", -1, "Uint", 0, "int",  0, "Uint", 0, "Uint", 0)
	VarSetCapacity(sString, nSize)
	DllCall("kernel32\WideCharToMultiByte", "Uint", 0, "Uint", 0, "Uint", pString, "int", -1, "str", sString, "int", nSize + 1, "Uint", 0, "Uint", 0)
	Return	sString
}

I also create a AutoHotkey.exe.manifest file in the same folder as AutoHotkey.exe:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
<assemblyIdentity
	version="1.0.48.05" 
	processorArchitecture="X86"
	name="Microsoft.Windows.AutoHotkey"
	type="win32"
/>
<description>AutoHotkey</description>
<dependency>
	<dependentAssembly>
		<assemblyIdentity
			type="win32"
			name="Microsoft.Windows.Common-Controls"
			version="6.0.0.0"
			processorArchitecture="X86"
			publicKeyToken="6595b64144ccf1df"
			language="*"/>
	</dependentAssembly>
</dependency>
<trustInfo xmlns="urn:schemas-microsoft-com:asm.v3">
	<security>
		<requestedPrivileges>
			<requestedExecutionLevel
				level="asInvoker"
				uiAccess="false"/>
		</requestedPrivileges>
	</security>
</trustInfo>
</assembly>

But nothing is changed. Who can help me?
MSDN ref: http://msdn.microsof...9(v=VS.85).aspx

VxE
  • Moderators
  • 3622 posts
  • Last active: Dec 24 2015 02:21 AM
  • Joined: 07 Oct 2006
There is no need to specify a manifest ( I think AHK automatically detects those common windows dlls on its own ). There were two issues with your code: first, since you only had one input-capable control, it has the keyboard focus (and edit-cues won't show while the edit box has input focus... at least for me, no matter that wparam is true). Second, the API specifies that the lparam should be a pointer to a unicode string, but it really means a wide-character string.

Here's the fixed code:
Gui, Add, Edit, w300, This should start focused
Gui, Add, Edit, w300 hwndhEdit,

Gui, Show, w600 h400
MsgBox % Edit_SetCueBanner(hEdit, "123", 1)
Return

GuiEscape:
GuiClose:
ExitApp

Edit_SetCueBanner(hEdit, sText, bFocusShow=0)
{
	OEL := ErrorLevel
	VarSetCapacity( wText, 2 * len := StrLen( sText ) + 1, 0 )
   DllCall("kernel32\MultiByteToWideChar", "UInt", 65001, "UInt", 0
      , "Str", sText, "Int", -1, "Str", wText, "Int", len )
   SendMessage, 0x1501, bFocusShow, &wText, , ahk_id %hEdit%
   Return ErrorLevel+0, ErrorLevel := OEL
}


[VxE] nli
  • Guests
  • Last active:
  • Joined: --
btw: I'm going to steal this function:
Edit_SetCueBanner( control, text ) { ; -------------------------------

; Sets the text which appears in a blank edit control when the control

; does not have focus. 'Control' should either be the HWND of an edit

; control, an edit control's variable name, or the edit control's

; classNN (which will be 'EditNN'). Returns true if successful.

; IMPORTANT! Does NOT work for MULTILINE edit controls.

	Static EM_SETCUEBANNER := 5377

	OEL := ErrorLevel, OLFW := WinExist()

	If WinExist( "AHK_ID " . Abs( control ) ) = control

		hwnd := control

	Else GuiControlGet, hwnd, HWND, %control%

	VarSetCapacity( wText, 2 * len := StrLen( text ) + 1, 0 )

	DllCall("MultiByteToWideChar", "UInt", 65001, "UInt", 0

		, "Str", text, "Int", -1, "Str", wText, "Int", len )

	SendMessage, EM_SETCUEBANNER, 0, &wText, , ahk_id %hwnd%

	Return ErrorLevel+0, ErrorLevel := OEL, WinExist( "AHK_ID " OLFW )

} ; Edit_SetCueBanner( control, text ) -------------------------------


hughman
  • Members
  • 192 posts
  • Last active: Feb 14 2016 06:59 AM
  • Joined: 11 Feb 2007
thanks, VxE.

Second, the API specifies that the lparam should be a pointer to a unicode string, but it really means a wide-character string.

I copy a wrong function from sean's COM.ahk :).
It should be Ansi2Unicode, not Ansi4Unicode

But your fixed code can't display the texual cue in the second edit control in my os yet. Does it work in your place?

VxE
  • Moderators
  • 3622 posts
  • Last active: Dec 24 2015 02:21 AM
  • Joined: 07 Oct 2006
Yes, I tested the code using XP.sp3.

hughman
  • Members
  • 192 posts
  • Last active: Feb 14 2016 06:59 AM
  • Joined: 11 Feb 2007
I also use xp sp3, and I have tried it in two machines, but none can display cue text.
So what's wrong?

Edit: Doesn't work with the Asian language pack, according to MSDN comment. It's fixed in vista :(
Here is a c# project to realize the same function.
<!-- m -->http://www.codeproje...tedTextBox.aspx<!-- m -->

VxE
  • Moderators
  • 3622 posts
  • Last active: Dec 24 2015 02:21 AM
  • Joined: 07 Oct 2006
Aah, it's probably the language pack thing...

The way I used to have edit-box prompts was to position a text control on top of the edit box (with 'BackgroundTrans' style) and hide/show it programmatically.

Delusion
  • Members
  • 272 posts
  • Last active: Jul 13 2014 09:04 PM
  • Joined: 16 Jul 2008
this was posted on the german ahk forum loooooong time ago :
its for ahk basic and iv been using it without any problems at all for a while

SetCueBanner(HWND, STRING, SHOWALWAYS = 0) {
    Static EM_SETCUEBANNER := 0x1501
    IF !(HWND + 0) {
      GuiControlGet, CHWND, HWND, %HWND%
      HWND := CHWND
    }
    VarSetCapacity(WSTRING, (StrLen(STRING) * 2) + 1)
    DllCall("MultiByteToWideChar", UInt, 0, UInt, 0, UInt, &STRING, Int, -1, UInt, &WSTRING, Int, StrLen(STRING) + 1)
    DllCall("SendMessageW", "UInt", HWND, "UInt", EM_SETCUEBANNER, "UInt", SHOWALWAYS, "UInt", &WSTRING)
    RETURN
  }

QuickSubs | Popcorn Movie Catalog
All my scripts are just in AutoHotkey v1.0.48.05