Take a look at the top-right of the Stack Overflow site. The search box has some text in it saying "search". When you click within it, the text disappears.
I want to do something similar to this - if a win32 edit control is empty (i.e. has no text), I want to paint some text inside it, in a more subdued color than the normal text. If the control has the focus, or if there's text inside it, I don't want to paint that.
Is there any way I can do it without setting the actual text into the control and changing the text color? Maybe by intercepting the control paint or something?
Thanks.
It is possible as of XP. Check the EM_SETCUEBANNER message. However, there are certain issues that make it not work entirely as it should on XP, so it's best if you're dealing with Vista.
If you need it for Win2k or older versions, you'll need to do it yourself, at least on those platforms.
Thanks for this question, I will be able to use this in the future. FWIW (not much, probably), here is an implementation in Delphi:
procedure TForm1.FormShow(Sender: TObject);
const
ECM_FIRST = $1500;
EM_SETCUEBANNER = ECM_FIRST + 1;
begin
SendMessage(edt.Handle,EM_SETCUEBANNER,0,LParam(PWideChar(WideString('Enter search here'))));
end;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With