I added a Listbox control to a dialog resource called IDC_LIST1
. Should I be interacting with this control using SendDlgItemMessage()
, or is there a better way with WTL? Here are my event handlers. It is nothing fancy yet!
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;
}
The WTL suggested way is as follow:
WTL support classes for common and Windows controls are in atlctrls.h, you may also have a look at WTL for MFC Programmers, Part IV - Dialogs and Controls.