SetStringGadgetTip, SETCUEBANNER

Share your advanced PureBasic knowledge/code with the community.
User avatar
em_uk
Enthusiast
Enthusiast
Posts: 366
Joined: Sun Aug 08, 2010 3:32 pm
Location: Manchester UK

SetStringGadgetTip, SETCUEBANNER

Post 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
----

R Tape loading error, 0:1
MachineCode
Addict
Addict
Posts: 1482
Joined: Tue Feb 22, 2011 1:16 pm

Re: SetStringGadgetTip, SETCUEBANNER

Post by MachineCode »

Oooh, nice! Me like, me like! :lol:
Microsoft Visual Basic only lasted 7 short years: 1991 to 1998.
PureBasic: Born in 1998 and still going strong to this very day!
User avatar
Tomi
Enthusiast
Enthusiast
Posts: 270
Joined: Wed Sep 03, 2008 9:29 am

Re: SetStringGadgetTip, SETCUEBANNER

Post by Tomi »

nice code! thanks :)
User avatar
Demivec
Addict
Addict
Posts: 4086
Joined: Mon Jul 25, 2005 3:51 pm
Location: Utah, USA

Re: SetStringGadgetTip, SETCUEBANNER

Post by Demivec »

Requires XP skin support be enabled.
User avatar
Kwai chang caine
Always Here
Always Here
Posts: 5342
Joined: Sun Nov 05, 2006 11:42 pm
Location: Lyon - France

Re: SetStringGadgetTip, SETCUEBANNER

Post 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:
ImageThe happiness is a road...
Not a destination
User avatar
Rescator
Addict
Addict
Posts: 1769
Joined: Sat Feb 19, 2005 5:05 pm
Location: Norway

Re: SetStringGadgetTip, SETCUEBANNER

Post by Rescator »

BarryG
Addict
Addict
Posts: 3292
Joined: Thu Apr 18, 2019 8:17 am

Re: SetStringGadgetTip, SETCUEBANNER

Post 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
User avatar
mk-soft
Always Here
Always Here
Posts: 5335
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: SetStringGadgetTip, SETCUEBANNER

Post 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
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
BarryG
Addict
Addict
Posts: 3292
Joined: Thu Apr 18, 2019 8:17 am

Re: SetStringGadgetTip, SETCUEBANNER

Post 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.
User avatar
charvista
Addict
Addict
Posts: 902
Joined: Tue Sep 23, 2008 11:38 pm
Location: Belgium

Re: SetStringGadgetTip, SETCUEBANNER

Post 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.
- Windows 11 Home 64-bit
- PureBasic 6.04 LTS (x64)
- 64 Gb RAM
User avatar
skywalk
Addict
Addict
Posts: 3972
Joined: Wed Dec 23, 2009 10:14 pm
Location: Boston, MA

Re: SetStringGadgetTip, SETCUEBANNER

Post 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
The nice thing about standards is there are so many to choose from. ~ Andrew Tanenbaum
novablue
Enthusiast
Enthusiast
Posts: 165
Joined: Sun Nov 27, 2016 6:38 am

Re: SetStringGadgetTip, SETCUEBANNER

Post by novablue »

Is it possible to change the color of the #EM_SETCUEBANNER text?
User avatar
jacdelad
Addict
Addict
Posts: 1431
Joined: Wed Feb 03, 2021 12:46 pm
Location: Planet Riesa
Contact:

Re: SetStringGadgetTip, SETCUEBANNER

Post 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.
PureBasic 6.04/XProfan X4a/Embarcadero RAD Studio 11/Perl 5.2/Python 3.10
Windows 11/Ryzen 5800X/32GB RAM/Radeon 7770 OC/3TB SSD/11TB HDD
Synology DS1821+/36GB RAM/130TB
Synology DS920+/20GB RAM/54TB
Synology DS916+ii/8GB RAM/12TB
Axolotl
Enthusiast
Enthusiast
Posts: 435
Joined: Wed Dec 31, 2008 3:36 pm

Re: SetStringGadgetTip, SETCUEBANNER

Post 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.
Mostly running PureBasic <latest stable version and current alpha/beta> (x64) on Windows 11 Home
Post Reply