创建窗口后窗口的句柄返回值是0
#include <windows.h>
#define ID_ComboBox 1
LRESULT CALLBACK WndProc(HWND,UINT,WPARAM,LPARAM);
int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrvInstance,LPSTR lpCmdLine,int iCmdShow)
{
HWND hwnd;
WNDCLASS wndclass;
MSG msg;
wndclass.style = CS_VREDRAW | CS_HREDRAW;
wndclass.lpfnWndProc = WndProc;
wndclass.cbClsExtra = 0;
wndclass.cbWndExtra = 0;
wndclass.hInstance = hInstance;
wndclass.hIcon = LoadIcon(NULL,IDI_APPLICATION);
wndclass.hCursor = LoadCursor(NULL,IDC_ARROW);
wndclass.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
wndclass.lpszMenuName = NULL;
wndclass.lpszClassName = TEXT("ComboBox");
RegisterClass(&wndclass);
hwnd = CreateWindow(TEXT("PARENT"), //此处调试时 hwnd 的值为 Ox00000000
TEXT("FATHER"),
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
NULL,NULL,
hInstance,
NULL);
ShowWindow(hwnd,iCmdShow);
UpdateWindow(hwnd);
while(GetMessage(&msg,NULL,0,0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return msg.wParam;
}
LRESULT CALLBACK WndProc(HWND hwnd,UINT message,WPARAM wParam,LPARAM lParam)
{
PAINTSTRUCT ps;
HDC hdc;
HWND hwndComboBox;
TCHAR CONTENT[20] = "go go";
switch(message)
{
case WM_PAINT:
hdc = BeginPaint(hwnd,&ps);
EndPaint(hwnd,&ps);
return 0;
case WM_CREATE:
hwndComboBox = CreateWindow(TEXT("ComboBox"),
NULL,
WS_CHILD | WS_VISIBLE | CBS_DROPDOWNLIST | CBS_SORT,
200,200,
150,500,
hwnd,
(HMENU)ID_ComboBox,
((LPCREATESTRUCT) lParam) -> hInstance,
NULL);
SendMessage(hwndComboBox,CB_ADDSTRING,0,(LPARAM)CONTENT);
SendMessage(hwndComboBox,CB_ADDSTRING,0,(LPARAM)CONTENT);
SendMessage(hwndComboBox,CB_ADDSTRING,0,(LPARAM)CONTENT);
SendMessage(hwndComboBox,CB_ADDSTRING,0,(LPARAM)CONTENT);
SendMessage(hwndComboBox,CB_ADDSTRING,0,(LPARAM)CONTENT);
SendMessage(hwndComboBox,CB_ADDSTRING,0,(LPARAM)CONTENT);
SendMessage(hwndComboBox,CB_ADDSTRING,0,(LPARAM)CONTENT);
return 0;
case WM_DESTROY:
PostQuitMessage(0);
return 0;
}
return DefWindowProc (hwnd, message, wParam, lParam);
}
代码如上,编译可以通过,执行时没有窗口显示出来,但是在任务管理器中显示此程序正在运行,帮我看一下错在了哪里,不甚感谢。