Reputation: 21
I have tried making my own ListView using the WinApi but all I get all these errors when trying to build
1>client_application\main.cpp(156): error C2065: 'WC_LISTVIEW' : undeclared identifier
1>client_application\main.cpp(156): error C2065: 'LVS_REPORT' : undeclared identifier
1>client_application\main.cpp(156): error C2065: 'LVS_EDITLABELS' : undeclared identifier
1>client_application\main.cpp(156): error C2660: 'CreateWindowExA' : function does not take 11 arguments
1>client_application\main.cpp(158): error C3861: 'ListView_InsertColumn': identifier not found
The code I have added to the file that makes it stop working is
HWND list = CreateWindow(WC_LISTVIEW,
L"",
WS_CHILD | LVS_REPORT | LVS_EDITLABELS,
0, 0,
250,
250,
hwnd,
(HMENU) NULL,
NULL,
NULL
);
ListView_InsertColumn(list, 0, "Test");
Can someone tell me what I am doing wrong?
Edit: Fixed above but I now get this error
Error 1 error C2664: 'HWND CreateWindowExA(DWORD,LPCSTR,LPCSTR,DWORD,int,int,int,int,HWND,HMENU,HINSTANCE,LPVOID)' : cannot convert argument 3 from 'const wchar_t [1]' to 'LPCSTR' C:\Users\Callum\Desktop\client_application\main.cpp
Upvotes: 0
Views: 867
Reputation: 840
A quick search determined that you need to add #include <CommCtrl.h>
, as mentioned in the documentation (see bottom of the page).
EDIT:
For your other problem, you are passing a wchar_t*
where a char*
is expected.
Winapi functions like CreateWindowEx()
are actually macros to two different functions, CreateWindowExA()
and CreateWindowExW()
, where the first requires a char*
and the latter a wchar_t*
. Either:
put #define UNICODE
at the top of your file so the CreateWindowEx()
macro resolves to the CreateWindowExW()
function
call the CreateWindowExW()
function directly.
change your second argument from L""
to TEXT("")
to match what the CreateWindowsEx()
macro expects, which is a TCHAR*
.
Also, do not forget to add WS_VISIBLE
. Otherwise your control is hidden by default.
Upvotes: 3