Win32 API ListView Creation (C++)

das_j picture das_j · Dec 20, 2012 · Viewed 11.8k times · Source

I want to create a ListView in c++. My code so far:

InitCommonControls(); // Force the common controls DLL to be loaded.
HWND list;

// window is a handle to my window that is already created.
list = CreateWindowEx(0, (LPCSTR) WC_LISTVIEWW, NULL, WS_VISIBLE | WS_CHILD | WS_BORDER | LVS_SHOWSELALWAYS | LVS_REPORT, 0, 0, 250, 400, window, NULL, NULL, NULL);

LVCOLUMN lvc; 
lvc.mask = LVCF_FMT | LVCF_WIDTH | LVCF_TEXT | LVCF_SUBITEM;
lvc.iSubItem = 0;
lvc.pszText = "Title";
lvc.cx = 50;
lvc.fmt = LVCFMT_LEFT;
ListView_InsertColumn(list, 0, &lvc);

But if I compile and execute the code, just a blank window is beeing showed. Compiler: MinGW on Windows 7 (x86).

Can anybody help me showing the listview properly?

Answer

SChepurin picture SChepurin · Dec 20, 2012

Here is the link to original MSDN sample code of ListView control written in Windows API and C. It compiles in VC++ 2010.