初学者的问题:自画的基于于CComBoBox为何用GetWindowText()函数不能获得当前选定的文本内容(获取是的乱码),为何?
CString lpStr; pDC.SetBkMode(TRANSPARENT );
pDC.SetTextColor(TextColor);
pDC.SelectObject(GetStockObject(DEFAULT_GUI_FONT));
this->GetWindowText(lpStr);
pDC.DrawText(lpStr,
CRect(rcItem.left+5,rcItem.top,rcItem.right-30,rcItem.bottom),
DT_WORD_ELLIPSIS | DT_SINGLELINE | DT_VCENTER);有MSDN中的方法也是如此:Example
// The pointer to my combo box.
extern CComboBox* pmyComboBox;// Dump all of the items in the combo box.
#ifdef _DEBUG
CString str, str2;
int n;
for (int i=0;i < pmyComboBox->GetCount();i++)
{
n = pmyComboBox->GetLBTextLen( i );
pmyComboBox->GetLBText( i, str.GetBuffer(n) );
str.ReleaseBuffer(); str2.Format(_T("item %d: %s\r\n"), i, str.GetBuffer(0));
afxDump << str2;
}
#endif
谁能帮帮小弟,万分感谢
CString lpStr; pDC.SetBkMode(TRANSPARENT );
pDC.SetTextColor(TextColor);
pDC.SelectObject(GetStockObject(DEFAULT_GUI_FONT));
this->GetWindowText(lpStr);
pDC.DrawText(lpStr,
CRect(rcItem.left+5,rcItem.top,rcItem.right-30,rcItem.bottom),
DT_WORD_ELLIPSIS | DT_SINGLELINE | DT_VCENTER);有MSDN中的方法也是如此:Example
// The pointer to my combo box.
extern CComboBox* pmyComboBox;// Dump all of the items in the combo box.
#ifdef _DEBUG
CString str, str2;
int n;
for (int i=0;i < pmyComboBox->GetCount();i++)
{
n = pmyComboBox->GetLBTextLen( i );
pmyComboBox->GetLBText( i, str.GetBuffer(n) );
str.ReleaseBuffer(); str2.Format(_T("item %d: %s\r\n"), i, str.GetBuffer(0));
afxDump << str2;
}
#endif
谁能帮帮小弟,万分感谢
解决方案 »
- vs2008程序非正常退出的问题?
- 进程保护用Mutex怎么做?
- MFC 从sql数据中得到一列的值
- 用ADO 操作SQL SERVER数据库时,为什么执行delete Table1时有时成功有时执行失败。Table1中只有2万多条记录。
- 有高手知道VFW(Video for Windows)SDK的下载么?
- 一个关于gina的问题,散分...
- ★★★!!!!!!!!!!!!!!!!!!想上Google的来看!!!!!!!!!!!!!!!!!!!!!★★★
- 如何在一个定义的Rect区域内显示文字,看我的代码错在哪
- 如何调用Python脚本?
- MFC报错
- 散分!!!中级程序员考试 考C语言的位运算吗?请指教!
- ___W2K服务程序中如何模拟按键___
int nCurSel = pComboBox->GetCurSel();
CString strSelText;
pComboBox->GetLBText( nCurSel, strSelText );
//strSelText就是文本内容。
CComboBox通常要取用户选择的文本,应该:
int nCurSel = pComboBox->GetCurSel();
CString strSelText;
pComboBox->GetLBText( nCurSel, strSelText );
//strSelText就是文本内容
结果也一样,也为乱码...为知为何