简体   繁体   English

如何在CCombobox中添加背景文本

[英]How to add background text in CCombobox

We often see a background text on search bars ie "Search Here", "Type here to search" etc. and it disappears when we start typing. 我们经常在搜索栏上看到背景文本,例如“在这里搜索”,“在这里键入要搜索的内容”等,当我们开始键入时,它就会消失。 Have a look at the following one: 看一下以下内容:

我需要的样品

Is there any built-in method to implement the same functionality in an MFC Application for the CComboBox Control ? 是否有任何built-in方法可在MFC ApplicationCComboBox控件实现相同的功能?

Use CComboBox::SetCueBanner 使用CComboBox :: SetCueBanner

This sends window message CB_SETCUEBANNER . 这将发送窗口消息CB_SETCUEBANNER SetCueBanner is also available for CEdit . SetCueBanner也可用于CEdit This feature needs at least Windows Vista. 此功能至少需要Windows Vista。

This function is unicode only, it has to have to unicode text. 此函数仅是unicode,它必须对文本进行unicode。

If you are targeting WinXP, SetCueBanner is not available and the program will not compile. 如果您以WinXP为目标,则SetCueBanner不可用,该程序将无法编译。 But you can still send CB_SETCUEBANNER ( 0x1703 ) message: 但是您仍然可以发送CB_SETCUEBANNER0x1703 )消息:

::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. 这将在所有系统上编译并运行,但是在Windows XP中不会产生任何影响。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM