Page 1 of 1

SetStringGadgetTip, SETCUEBANNER

Posted: Wed Nov 30, 2011 11:27 am
by em_uk
I am reposting this from Danilo (thanks!) as I searched high and low but struggled to find the snippet, as it was placed within a topic about overwriting/inserting text.

Code: Select all

Procedure SetStringGadgetTip(gadget,text$)
    Protected temp$
    CompilerIf #PB_Compiler_Unicode
        tmp$ = text$
    CompilerElse
        Protected len  = Len(text$)
        tmp$ = Space(len*2+2)
        PokeS(@tmp$,text$,len,#PB_Unicode)
    CompilerEndIf
    SendMessage_(GadgetID(gadget),#EM_SETCUEBANNER,#True,@tmp$)
EndProcedure

If OpenWindow(0, 0, 0, 322, 205, "StringGadget Flags", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)

    StringGadget(0, 8,  10, 306, 20, "")
    SetStringGadgetTip(0,"Enter your name")

    StringGadget(1, 8,  35, 306, 20, "", #PB_String_Numeric)
    SetStringGadgetTip(1,"Enter your phone number")

    Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow
EndIf

Re: SetStringGadgetTip, SETCUEBANNER

Posted: Wed Nov 30, 2011 2:16 pm
by MachineCode
Oooh, nice! Me like, me like! :lol:

Re: SetStringGadgetTip, SETCUEBANNER

Posted: Wed Nov 30, 2011 3:19 pm
by Tomi
nice code! thanks :)

Re: SetStringGadgetTip, SETCUEBANNER

Posted: Wed Nov 30, 2011 10:01 pm
by Demivec
Requires XP skin support be enabled.

Re: SetStringGadgetTip, SETCUEBANNER

Posted: Thu Dec 01, 2011 11:11 am
by Kwai chang caine
Thanks for sharing 8)

Code: Select all

Requires XP skin support be enabled.
Yes because without the XP option, it's a simple StringGadget, so i have not understand what is really super :lol: :lol:

Re: SetStringGadgetTip, SETCUEBANNER

Posted: Sat Dec 03, 2011 2:06 am
by Rescator

Re: SetStringGadgetTip, SETCUEBANNER

Posted: Thu Apr 23, 2020 8:30 am
by BarryG
Updated due to the IDE always being Unicode now:

Code: Select all

; Requires XP skins to be enabled.

OpenWindow(0, 100, 200, 322, 70, "StringGadget Tips", #PB_Window_SystemMenu)

StringGadget(0, 8, 10, 306, 20, "")
SendMessage_(GadgetID(0),#EM_SETCUEBANNER,#True,@"Enter your name")

StringGadget(1, 8, 35, 306, 20, "", #PB_String_Numeric)
SendMessage_(GadgetID(1), #EM_SETCUEBANNER, #True, @"Enter your phone number")

Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow
Image

Re: SetStringGadgetTip, SETCUEBANNER

Posted: Thu Apr 23, 2020 8:52 am
by mk-soft
Very nice, Thanks :wink:

Code: Select all

; Requires XP skins to be enabled.

Macro SetCueBanner(Gadget, Text)
  SendMessage_(GadgetID(Gadget),#EM_SETCUEBANNER,#True,@Text)
EndMacro

OpenWindow(0, 100, 200, 322, 70, "StringGadget Tips", #PB_Window_SystemMenu)

StringGadget(0, 8, 10, 306, 20, "")
SetCueBanner(0, "Enter your name")

StringGadget(1, 8, 35, 306, 20, "", #PB_String_Numeric)
SetCueBanner(1, "Enter your phone number")

Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow

Re: SetStringGadgetTip, SETCUEBANNER

Posted: Thu Apr 23, 2020 9:04 am
by BarryG
mk-soft wrote:Very nice, Thanks :wink:
I only updated it to remove the Ascii/Unicode tests. The original was by Danilo, then updated by em_uk, then by myself, and now by you with a macro. Good to see the interest in it.

Re: SetStringGadgetTip, SETCUEBANNER

Posted: Fri Apr 24, 2020 3:39 pm
by charvista
Can we also specify a color for the tip-text ?
Often, it might be desirable to put it in another color so we see that the field is still empty (nothing entered).

And as extension, can we change the background color as well ?

Thanks.

Re: SetStringGadgetTip, SETCUEBANNER

Posted: Fri Apr 24, 2020 4:16 pm
by skywalk
Nice 8)
And it coexists with traditional ToolTip after changes made to string gadget. :wink:

Code: Select all

; Requires XP skins to be enabled.
Macro SetCueBanner(Gadget, Text)
  SendMessage_(GadgetID(Gadget),#EM_SETCUEBANNER,#True,@Text)
EndMacro
OpenWindow(0, 100, 200, 322, 70, "StringGadget Tips", #PB_Window_SystemMenu|#PB_Window_ScreenCentered)
StringGadget(0, 8, 10, 306, 20, "")
SetCueBanner(0, "Enter your name")
GadgetToolTip(0, "Enter your name")
StringGadget(1, 8, 35, 306, 20, "", #PB_String_Numeric)
SetCueBanner(1, "Enter your phone number")
GadgetToolTip(1, "Enter your phone number")
Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow

Re: SetStringGadgetTip, SETCUEBANNER

Posted: Wed Mar 22, 2023 6:49 pm
by novablue
Is it possible to change the color of the #EM_SETCUEBANNER text?

Re: SetStringGadgetTip, SETCUEBANNER

Posted: Wed Mar 22, 2023 8:24 pm
by jacdelad
novablue wrote: Wed Mar 22, 2023 6:49 pm Is it possible to change the color of the #EM_SETCUEBANNER text?
Not with traditional tools, maybe with subclassing/ownerdrawing.

Re: SetStringGadgetTip, SETCUEBANNER

Posted: Thu Mar 23, 2023 6:09 pm
by Axolotl
maybe this quick & dirty snippet can do the trick....
Please keep in mind, that only the first and the third gadget are colored in the callback and the numeric field is not.

Code: Select all

; This little piece of software is presented to you by Axolotl. 

EnableExplicit 

; Requires XP skins to be enabled.


;/---------------------------------------------------------------------------------------------------------------------
;| Help text EM_SETCUEBANNER  according to MSDN 
;| 
;|  wParam 
;|  	TRUE if the cue banner should show even when the edit control has focus; otherwise, FALSE. 
;|  	FALSE is the default behavior - the cue banner disappears when the user clicks in the control. 
;| 
;|  Remoarks 
;| 	 You cannot set a cue banner on a multiline edit control or on a rich edit control. 
;| 
;\---

Macro StringGadget_SetCueBannerTextFocused(Gadget, Text, xDrawFocused=#True) 
	SendMessage_(GadgetID(Gadget), #EM_SETCUEBANNER, xDrawFocused, @Text) 
EndMacro 

Macro StringGadget_SetCueBannerText(Gadget, Text) 
  SendMessage_(GadgetID(Gadget), #EM_SETCUEBANNER, #False, @Text) 
EndMacro


; ---== Window Callback Procedure ==-----------------------------------------------------------------------------------

Procedure WindowCallbackProc(hWnd, uMsg, wParam, lParam)
	Protected cuebanner.s{#MAX_PATH}, text.s{#MAX_PATH}, t.s 

	Select uMsg 
		Case #WM_CTLCOLOREDIT 
			If lParam = GadgetID(0) Or lParam = GadgetID(3) ; the StringGadget we are looking for 
				SendMessage_(lParam, #WM_GETTEXT, #MAX_PATH, @text) 
				SendMessage_(lParam, #EM_GETCUEBANNER, @cuebanner, #MAX_PATH) 

				If cuebanner <> "" And (text = "" Or text = cuebanner)  ; in this case we want a different background color 
					SetDCBrushColor_(wParam, $00E0FFFF) 									; Color is a WORD and it's format is 0x00BBGGRR 
					ProcedureReturn GetStockObject_(#DC_BRUSH) 						; return a DC brush, dont need to delete it.  
				EndIf 
			EndIf 

	EndSelect 
	ProcedureReturn #PB_ProcessPureBasicEvents 
EndProcedure 

; ---== Main Procedure ==----------------------------------------------------------------------------------------------

Procedure main() 
	If OpenWindow(0, 100, 200, 322, 96, "StringGadget Tips", #PB_Window_SystemMenu|#PB_Window_ScreenCentered) 
	  StickyWindow(0, 1) 
	  SetWindowCallback(@WindowCallbackProc(), 0) 

		StringGadget(0, 8, 8, 306, 20, "")
;		SetCueBanner(0, "Enter your name")
		StringGadget_SetCueBannerTextFocused(0, "Enter your name") 
		GadgetToolTip(0, "Enter your name")

		StringGadget(1, 8, 32, 306, 20, "", #PB_String_Numeric) 
		StringGadget_SetCueBannerText(1, "Enter your phone number")
		GadgetToolTip(1, "Enter your phone number")
;		SetGadgetColor(1, #PB_Gadget_BackColor, $00E0FFFF) 

		StringGadget(3, 8, 56, 306, 20, "")
		StringGadget_SetCueBannerText(3, "Enter your profession") 
		GadgetToolTip(3, "Enter your profession") 

		Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow
	EndIf 
EndProcedure 

End main() 

Happy coding and stay healthy.