0
votes

We often see a background text on search bars i.e. "Search Here", "Type here to search" etc. and it disappears when we start typing. Have a look at the following one:

A sample of what I need

Is there any built-in method to implement the same functionality in an MFC Application for the CComboBox Control ?

1

1 Answers

3
votes

Use CComboBox::SetCueBanner

This sends window message CB_SETCUEBANNER. SetCueBanner is also available for CEdit. This feature needs at least Windows Vista.

This function is unicode only, it has to have to unicode text.

If you are targeting WinXP, SetCueBanner is not available and the program will not compile. But you can still send CB_SETCUEBANNER (0x1703) message:

::SendMessageW(myComboBox->m_hWnd, CB_SETCUEBANNER, 0, (LPARAM)L"Text");

This will compile and run on all systems, however it won't have any effect in Windows XP.