我正在尝试将一些字符串添加到列表框中。这是否可以从函数发送消息以将字符串添加到列表框中?
答案 0 :(得分:3)
我得到了正确的代码。如下......
LPTSTR lpBuffer = m_WindowTitle.GetBuffer( );
HWND listHWnd = ::GetDlgItem(AfxGetMainWnd()->m_hWnd, IDC_LIST1);
SendMessage(listHWnd, LB_ADDSTRING, 0, (LPARAM)lpBuffer);
m_WindowTitle.ReleaseBuffer ( );
感谢您的帮助。
答案 1 :(得分:2)
您可以为列表框创建成员变量,并说出m_ctrlListBox.AddString
或
CListBox *pMyList = (CListBox *) GetDlgItem(IDC_LIST1);
pMyList->AddString("My String");
如果您想发送消息,那么您可以尝试这些
SendMessage(MAKEINTRESOURCE(IDC_LIST1), LB_INSERTSTRING, Index, (LPARAM)lpBuffer);
SendMessage(hWnd, LB_ADDSTRING, NULL, (LPARAM)lpBuffer);
示例:强>
CString myString("Hi");
LPTSTR lpBuffer = myString.GetBuffer(myString.GetLength());
CWnd* cw= GetDlgItem(IDC_LIST1);
::SendMessage(cw->GetSafeHwnd(), LB_INSERTSTRING, 0, (LPARAM)lpBuffer);
myString.ReleaseBuffer ( );