如题。代码如下:
#include <windows.h>
#include <commctrl.h>
#pragma comment(lib, "comctl32.lib")HWND hWnd;
HINSTANCE hInst;LRESULT CALLBACK wndproc(
  HWND hwnd,      // handle to window
  UINT uMsg,      // message identifier
  WPARAM wParam,  // first message parameter
  LPARAM lParam   // second message parameter
);int WINAPI WinMain(
  HINSTANCE hInstance,  // handle to current instance
  HINSTANCE hPrevInstance,  // handle to previous instance
  LPSTR lpCmdLine,      // pointer to command line
  int nCmdShow          // show state of window
)
{
WNDCLASS wndclass;

wndclass.cbClsExtra = 0;
wndclass.cbWndExtra = 0;
wndclass.hbrBackground = (HBRUSH)GetStockObject(GRAY_BRUSH);
wndclass.hCursor = LoadCursor(NULL,IDC_ARROW);
wndclass.hIcon = LoadIcon(NULL,IDI_APPLICATION);
wndclass.hInstance = hInstance;
wndclass.lpfnWndProc = wndproc;
wndclass.lpszClassName = "ControlTest";
wndclass.lpszMenuName = NULL;
wndclass.style = CS_HREDRAW | CS_VREDRAW; if(!RegisterClass(&wndclass))
{
MessageBox(NULL,"注册窗口类失败!","ControlTest",MB_OK);
return 0;
} hInst=hInstance;
hWnd=CreateWindow("ControlTest",
"ControlTest",
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
NULL,
NULL,
hInst,
NULL); ShowWindow(hWnd,nCmdShow);
UpdateWindow(hWnd); MSG msg;
while(GetMessage(&msg,hWnd,0,0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
} return msg.wParam;
}LRESULT CALLBACK wndproc(
  HWND hwnd,      // handle to window
  UINT uMsg,      // message identifier
  WPARAM wParam,  // first message parameter
  LPARAM lParam   // second message parameter
)
{
switch(uMsg)
{
case WM_CREATE:
{
INITCOMMONCONTROLSEX icex; 
icex.dwSize = sizeof(INITCOMMONCONTROLSEX);
icex.dwICC = ICC_LISTVIEW_CLASSES;
if(!InitCommonControlsEx(&icex))
{
MessageBox(NULL,"Fail to init common controls!","Test",MB_OK); 
return 0;
}
HWND hWndListView;
hWndListView = CreateWindowEx(0,WC_LISTVIEW, //WC_LISTVIEW不需要加引号
TEXT(""),
WS_CHILD | WS_VISIBLE|WS_BORDER | LVS_ICON | LVS_EDITLABELS | WS_EX_CLIENTEDGE ,
10,
10,
100,
100,
hWnd,
(HMENU)1200, //控件ID
hInst, //实例句柄
NULL);
if(hWndListView == NULL)
MessageBox(NULL,"Fail to create window!","Test",0); return 0;
}
case WM_CLOSE:
PostQuitMessage(0);
return 0;
case WM_DESTROY:
PostQuitMessage(0);
return 0;
}
return DefWindowProc (hwnd, uMsg, wParam, lParam) ;
}
 
代码编译没有问题。但在创建控件时失败!