在 Win32(非 MFC)中获取/设置组合框文本 [英] Get/set combo-box text in Win32 (not MFC)

查看:21
本文介绍了在 Win32(非 MFC)中获取/设置组合框文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以使用 GetDlgItemText 从控件中获取文本,但我想清除选择和 SetDlgItemText(IDC_CTRL,_T(""));工作.这里的正确方法是什么?

I can use GetDlgItemText to get the text from a control, but I want to clear the selection and SetDlgItemText(IDC_CTRL,_T("")); doesn't work. What is the right approach here?

推荐答案

假设我正在阅读 Combo Boxes 的 MSDN 文档和 CB_SETCURSEL 消息正确,您可以使用 wParam 向组合框发送 CB_SETCURSEL 消息(在这种情况下,它将是组合框中字符串的索引)设置为 -1.这应该会清除选择.

Assuming I'm reading the MSDN documentation for the Combo Boxes and the CB_SETCURSEL message right, you can send a CB_SETCURSEL message to the combo box with the wParam(In this case it will be the index of the string in the combo box) being set to -1. This should then clear the selection.

您也可以决定使用 ComboBox_SetCurSel 封装消息发送的宏,它可以让生活更轻松.再次 -1 将清除选择.

You can also decide to use the ComboBox_SetCurSel macro that wraps the message sending, it can make life a bit easier. Once again -1 will clear the selection.

当然,如果您没有组合框的句柄(我假设您有,但如果您没有),您当然可以使用 GetDlgItem 函数通过提供对话框的句柄和组合框的 id.

Of course that would require you to get the handle of the combo box if you don't have it(I'm assuming you do, but in case you don't) you can possibly get it using the GetDlgItem function by supplying the handle for the dialog box and the id of the combo box.

这篇关于在 Win32(非 MFC)中获取/设置组合框文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆