I'd like to know how other programmers go about creating a simple window in Win32. If there's anything in my code that could be made more efficient, or which has been superseded, I'd love to know, thanks.
Code:#include <windows.h> int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR lpCmdLine,int nCmdShow); LRESULT CALLBACK WndProc(HWND hwnd,UINT msg,WPARAM wParam,LPARAM lParam); int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR lpCmdLine,int nCmdShow) { WNDCLASSEX wcx; wcx.cbClsExtra=0; wcx.cbSize=sizeof(WNDCLASSEX); wcx.cbWndExtra=0; wcx.hbrBackground=(HBRUSH)(COLOR_BTNFACE+1); wcx.hCursor=LoadCursor(NULL,IDC_ARROW); wcx.hIcon=LoadIcon(NULL,IDI_APPLICATION); wcx.hIconSm=NULL; wcx.hInstance=hInstance; wcx.lpfnWndProc=WndProc; wcx.lpszClassName="clsAccess"; wcx.lpszMenuName=NULL; wcx.style=0; if (!RegisterClassEx(&wcx)) exit(1); HWND hwnd; hwnd=CreateWindow("clsAccess","Access Manager", WS_OVERLAPPEDWINDOW, 0,0,0,0,NULL,NULL,hInstance,NULL); if (!hwnd) exit(2); ShowWindow(hwnd,SW_SHOW); UpdateWindow(hwnd); MSG msg; while (GetMessage(&msg,hwnd,0,0)>0) { TranslateMessage(&msg); DispatchMessage(&msg); } return msg.wParam; } LRESULT CALLBACK WndProc(HWND hwnd,UINT msg,WPARAM wParam,LPARAM lParam) { switch (msg) { case WM_DESTROY: PostQuitMessage(0); return 0; case WM_CREATE: SetWindowPos(hwnd,NULL, GetSystemMetrics(SM_CXSCREEN)/4, GetSystemMetrics(SM_CYSCREEN)/4, GetSystemMetrics(SM_CXSCREEN)/2, GetSystemMetrics(SM_CYSCREEN)/2, SWP_NOOWNERZORDER); break; default: break; } return DefWindowProc(hwnd,msg,wParam,lParam); }



LinkBack URL
About LinkBacks



