#includeint WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) { // Create a CWindow object CWindow window; // Create a window with a specified title and size if(!window.Create(L"My Window", WS_OVERLAPPEDWINDOW, 0, 0, 640, 480)) { return 0; } // Show the window window.ShowWindow(nCmdShow); // Enter the message loop to handle events MSG msg; while(GetMessage(&msg, NULL, 0, 0)) { TranslateMessage(&msg); DispatchMessage(&msg); } // Destroy the window and exit the program window.DestroyWindow(); return msg.wParam; }
#includeThis example shows how to handle the WM_PAINT message to draw a string on the window. The MyWindow class is derived from CWindow and overrides the OnPaint function to draw the text. These examples are most likely a part of the Windows API library.class MyWindow : public CWindow { public: // Handle the WM_PAINT message void OnPaint() { PAINTSTRUCT ps; HDC hdc = BeginPaint(m_hWnd, &ps); RECT rc; GetClientRect(m_hWnd, &rc); TCHAR text[] = _T("Hello, World!"); DrawText(hdc, text, -1, &rc, DT_CENTER | DT_VCENTER | DT_SINGLELINE); EndPaint(m_hWnd, &ps); } }; int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) { // Create a MyWindow object MyWindow window; // Create a window with a specified title and size if(!window.Create(L"My Window", WS_OVERLAPPEDWINDOW, 0, 0, 640, 480)) { return 0; } // Show the window window.ShowWindow(nCmdShow); // Enter the message loop to handle events MSG msg; while(GetMessage(&msg, NULL, 0, 0)) { TranslateMessage(&msg); DispatchMessage(&msg); } // Destroy the window and exit the program window.DestroyWindow(); return msg.wParam; }