许杨苑:为什么不显示出窗口呢?win API问题>>>>>>>>>>>>>

来源:百度文库 编辑:高校问答 时间:2024/04/29 18:35:07
下面的程序,在VC++中运行下。为什么不出现窗口呢》帮忙看看错那了。

谢谢各位了。新手刚学!!!!!!!

#include <windows.h>
#include <windowsx.h>
LRESULT CALLBACK WinProc(HWND hwnd,
UINT msg,
WPARAM wparam,
LPARAM lparam)
{
switch (msg) //msg中保存的就是正要处理的消息
{
case WM_DESTROY: //这是我们自行处理的第一个消息
{
PostQuitMessage(0); //发出一个WM_QUIT消息
return 0; //然后直接返回。
}break;
default:break;
}
return DefWindowProc(hwnd, msg, wparam, lparam);
}

int WINAPI WinMain(HINSTANCE hinstance,
HINSTANCE hprevinstance,
LPSTR lpcmdline,
int nCmdShow)
{
HWND hWnd;
MSG msg;
WNDCLASSEX wndclass;
wndclass.cbSize = sizeof(WNDCLASSEX);
wndclass.cbClsExtra=0;
wndclass.cbWndExtra =0;
wndclass.lpfnWndProc = WinProc;
wndclass.style = CS_VREDRAW | CS_HREDRAW | CS_OWNDC | CS_DBLCLKS;
wndclass.hInstance = hinstance;
wndclass.hCursor =LoadCursor(NULL, IDC_ARROW);
wndclass.hIcon = LoadIcon(NULL,IDI_APPLICATION);

wndclass.lpszMenuName = NULL;
wndclass.hbrBackground =(HBRUSH) GetStockObject(BLACK_BRUSH);
wndclass.lpszClassName ="WINCLASS1";
//
hWnd=CreateWindowEx(NULL,"WINCLASS1",
"这是我的第一个窗口",
WS_OVERLAPPEDWINDOW|WS_VISIBLE ,
CW_USEDEFAULT, 0,
400,400,
NULL,
NULL,
hinstance,
NULL );
if (!hWnd)
return 0;
ShowWindow(hWnd, nCmdShow);
UpdateWindow(hWnd);
while(GetMessage(&msg, NULL, 0, 0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return 0;
}

忘了 RegisterClassEx(&wndclass); 啦.加在CreateWindowEx 前面呀

没发现你的wndclass 没用上吗~~~~~~~~~~~

还有不是错误的,DefWindowProc 要放在default: 中啊。
最后要return 0; 就行啦