Sorry, title was a bit vague.
Basically, I am making a chat program in C++ and using windows.h API. I have most of the program working, just small things are not working correctly. I have a box that a user types what they wish to say in, and in that box it says “Enter text here” in italics. I want to set it so that when the user clicks in that box, those words disappear and the user can freely type. As it is set now, if they click within the box it goes to the end of the word “here” and they must manually delete the words.
Is there a simple way to do this? Possibly when creating the box or text? Or must I add logic of my own in order to accomplish this?
Attached is the code where I create both the box, and where I set the font:
Box:
hwSendEdit = CreateWindowEx(WS_EX_CLIENTEDGE, "Edit", "Enter Text Here",
WS_CHILD|WS_VISIBLE, 2, 215, 790, 22, hwMain, 0, hInst, 0);
Font:
chFont = CreateFont(12, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, "Tahoma");
SendMessage(hwSendEdit, WM_SETFONT, reinterpret_cast<WPARAM>(chFont), 0);
Thank you for any help you can provide.
You need to respond to the
WM_ACTIVATEmessage for the control. It has a parameter inwParamthat tells you if the control is being activated or deactivated. If it’s being activated, check the window text to see if it’s equal to your prompt string; if so set the font back to normal and useSetWindowTextto clear the text. If it’s being deactivated, useGetWindowTextto see if the text is empty and if so set the font back to italic and replace your prompt string.