Programming Tips - Win32: make a multicolumn listbox

Date: 2008jul9 Language: C/C++ Framework: MFC Platform: win32 Q. Win32: make a multicolumn listbox A. In the resource set LB_SETTABSTOPS and add strings with tabs. (Or you can use a listctrl in report mode.)
// We first setup these two small functions inline BOOL ListBoxSetTabStops(const HWND hdlg, const int id, const int cTabs, const LPINT nTabs) { return SendDlgItemMessage(hdlg, id, LB_SETTABSTOPS, (WPARAM) cTabs, (LPARAM) nTabs); } inline int ListBoxAddString(const HWND hdlg, const int id, LPCSTR s) { return SendDlgItemMessage(hdlg, id, LB_ADDSTRING, 0, (LPARAM) s); }
void ExampleUse() { int nTabs[] = { 100, 200 }; ListBoxSetTabStops(hDlg, IDC_MYLISTBOX, 2, nTabs); ListBoxAddString(hDlg, IDC_MYLISTBOX, "one\ttwo\tthree"); }
In MFC:
void ExampleUse() { int nTabs[] = { 100, 200 }; m_Mylistbox.SetTabStops(2, nTabs); m_Mylistbox.AddString("one\ttwo\tthree"); }