我添加了一個Listbox控件到一個名爲IDC_LIST1
的對話框資源。我應該使用SendDlgItemMessage()
與此控件進行交互,還是WTL有更好的方法?這是我的事件處理程序。它沒什麼特別的!我應該使用SendDlgItemMessage還是在WTL中有這個包裝?
LRESULT OnAddItem(WORD /*wNotifyCode*/, WORD wID, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
{
SendDlgItemMessage(IDC_LIST1, LB_INSERTSTRING, (WPARAM) 0, (LPARAM)_T("Hi"));
return 0;
}
LRESULT OnRemoveItem(WORD /*wNotifyCode*/, WORD wID, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
{
// Get selected item
int item = SendDlgItemMessage(IDC_LIST1, LB_GETCURSEL, (WPARAM) 0, (LPARAM) 0);
// Remove the item at the index of the selected item
SendDlgItemMessage(IDC_LIST1, LB_DELETESTRING, (WPARAM) 0, (LPARAM)item);
return 0;
}