初始化windows窗口

时间:2023-12-05 09:23:02
 LRESULT WINAPI WndProc(HWND hWnd,UINT msg,WPARAM wParam,LPARAM lParam)
{
PAINTSTRUCT ps;
switch (msg)
{
case WM_PAINT:
{
BeginPaint(hWnd,&ps);
EndPaint(hWnd,&ps);
return ;
}
case WM_DESTROY:
{
PostQuitMessage();
return ;
}
} return DefWindowProc(hWnd,msg,wParam,lParam);
}
void initWndClass(HINSTANCE hInstance,WNDCLASSEX &wndClass)
{
wndClass.cbSize = sizeof(WNDCLASSEX);
wndClass.style = CS_HREDRAW | CS_VREDRAW;
wndClass.lpfnWndProc = WndProc;
wndClass.cbClsExtra = ;
wndClass.cbWndExtra = ;
wndClass.hInstance = hInstance;
wndClass.hIcon = LoadIcon(NULL,IDI_APPLICATION);
wndClass.hCursor = LoadCursor(NULL,IDC_ARROW);
wndClass.hbrBackground = (HBRUSH)GetStockObject(GRAY_BRUSH);
wndClass.lpszClassName = TEXT(CLASSNAME);
wndClass.lpszMenuName = NULL;
wndClass.hIconSm = LoadIcon(NULL,IDI_WINLOGO);
}
 int WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR lpCmdLine,int nShowCmd)
{
HWND hWnd; WNDCLASSEX wndClass;
initWndClass(hInstance,wndClass); RegisterClassEx(&wndClass); hWnd = CreateWindow(
TEXT(CLASSNAME),
TEXT(APPNAME),
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT,
CW_USEDEFAULT,
SCREEN_W,
SCREEN_H,
NULL,
NULL,
hInstance,
NULL
); if (NULL == hWnd)
{
MessageBox(NULL,TEXT("NULL == hWnd"),NULL,MB_OK);
return ;
} UpdateWindow(hWnd);
ShowWindow(hWnd,nShowCmd);
MSG msg;
while (true)
{
if ( PeekMessage(&msg,NULL,,,PM_REMOVE) )
{
if (WM_QUIT == msg.message)
{
break;
}
TranslateMessage(&msg);
DispatchMessage(&msg);
}
else
{
Render();
}
}
Release();
return msg.lParam;
}