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