1. Initialize a window class structure WNDCLASSEX and register it.
2. Call CreateWindowEx and show it.
#include <windows.h>
HWND hWnd=NULL;
HINSTANCE hInstance;
BOOL FullScreen=TRUE;
BOOL InitApplication(HINSTANCE hinstance); BOOL InitInstance(HINSTANCE hinstance, int nCmdShow); LRESULT CALLBACK MainWndProc(HWND, UINT, WPARAM, LPARAM);
WINAPI WinMain(HINSTANCE hinstance, HINSTANCE, LPSTR, int nCmdShow) { MSG msg;
if (!InitApplication(hinstance)) return FALSE; if (!InitInstance(hinstance, nCmdShow)) return FALSE;
while (GetMessage(&msg, (HWND) NULL, 0, 0) != 0 && GetMessage(&msg, (HWND) NULL, 0, 0) != -1) { TranslateMessage(&msg); DispatchMessage(&msg); } return 0; }
BOOL InitApplication(HINSTANCE hinstance) { WNDCLASSEX wcx; memset(&wcx, 0, sizeof(wcx)); wcx.cbSize = sizeof(wcx); // size of WNDCLASSEX structure wcx.style = CS_HREDRAW | CS_VREDRAW; wcx.lpfnWndProc = MainWndProc; // suuply pointer to the window procedure wcx.cbClsExtra = 0; wcx.cbWndExtra = 0; wcx.hInstance = hinstance; // handle to application instance wcx.hIcon = LoadIcon(NULL,IDI_APPLICATION); wcx.hCursor = LoadCursor(NULL,IDC_ARROW); wcx.hbrBackground = (HBRUSH) GetStockObject(BLACK_BRUSH); // a window with a black background wcx.lpszMenuName = 0; // name associated with the menu resource wcx.lpszClassName = "MainWClass"; // name associated with this window class
return RegisterClassEx(&wcx); }
BOOL InitInstance(HINSTANCE hinstance, int nCmdShow) { // Save the application-instance handle. hInstance = hinstance; // Create the main window. hWnd = CreateWindowEx(WS_EX_OVERLAPPEDWINDOW, "MainWClass", "Window created with CreateWindowEx", WS_OVERLAPPEDWINDOW, 0,0, CW_USEDEFAULT, CW_USEDEFAULT, NULL, NULL, hinstance, NULL); if (!hWnd) return FALSE; ShowWindow(hWnd, nCmdShow); UpdateWindow(hWnd); return TRUE; } LRESULT CALLBACK MainWndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) { LRESULT lResult;
switch (msg) { case WM_CREATE: lResult = 0; break;
case WM_DESTROY: PostQuitMessage(0); lResult = 0; break;
case WM_PAINT: lResult = 0; break; default: lResult = DefWindowProc(hwnd, msg, wParam, lParam); break; } return lResult; }: : go back : :