描述:
我在MSDN帮助中看到这个函数的Remarks
Remarks
If the target window is owned by the current process, SetWindowText causes a WM_SETTEXT message to be sent to the specified window or control. If the control is a list box control created with the WS_CAPTION style, however, SetWindowText sets the text for the control, not for the list box entries.
是说必须是用 WS_CAPTION style 建立的list box才能用这个函数赋值吗?
我用spy++查看到的IE中“打印设置”对话框的 纸张大小下拉 combox 的窗口样式中没有这个 样式,
那这样的 combox用什么函数可以给它赋值?
请大虾帮忙,谢谢了!
解决方案1:
hushuangyan74() 说光了,让别人都没得说了。
解决方案2: ComboBox有两部份组成,一个是文本框Edit,另一个是下拉框,
如果你要给Edit赋值,可以用 EnochShen(小疯子:真的好菜—知耻而后勇!) 的方法。
也可以用简单的方法:
SetDlgItemText(IDC_COMBO1,"aaa");搞定
如果你要把你的字符串加到下拉框里面。
可以用:
CString str="abc";
((CComboBox*)GetDlgItem(IDC_COMBO1))->AddString(str);
....
得到ComboBox的Edit句柄后再赋值,补充一下,这样:
CEdit *pEdit = (CEdit*)GetDlgItem(IDC_COMBO1)->GetWindow(GW_CHILD);
pEdit->SetWindowText("str");
可以直接
::SetWindowText(GetDlgItem(IDC_COMBO1)->GetSafeHwnd(),"str");
或者
得到ComboBox的Edit句柄后再赋值
CEdit *pEdit = (CEdit*)CComboBox.GetWindow(GW_CHILD);