1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86
|
#if defined (UNICODE) || defined(_UNICODE)
#error Unicode not supported - use Multi-byte character set instead
#endif
#include <windows.h>
#include <iostream>
using namespace std;
const string ProgramTitle = "Hello Windows";
LRESULT CALLBACK WinProc (HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
RECT drawRect;
PAINTSTRUCT ps;
HDC hdc;
switch (message)
{
case WM_PAINT:
{
hdc = BeginPaint (hWnd, &ps);
for (int n = 0; n < 20; n++)
{
int x = n * 20;
int y = n * 20;
drawRect = { x, y, x + 100, y + 20 };
DrawText (hdc, ProgramTitle.c_str (), ProgramTitle.length (), &drawRect, DT_CENTER);
}
EndPaint (hWnd, &ps);
}
break;
case WM_DESTROY:
PostQuitMessage (0);
break;
}
return DefWindowProc (hWnd, message, wParam, lParam);
}
ATOM MyRegisterClass (HINSTANCE hInstance)
{
WNDCLASSEX wc;
wc.cbSize = sizeof (WNDCLASSEX);
wc.style = CS_HREDRAW | CS_VREDRAW;
wc.lpfnWndProc = (WNDPROC)WinProc;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hInstance = hInstance;
wc.hIcon = NULL;
wc.hCursor = LoadCursor (NULL, IDC_ARROW);
wc.hbrBackground = (HBRUSH)GetStockObject (WHITE_BRUSH);
wc.lpszMenuName = NULL;
wc.lpszClassName = ProgramTitle.c_str ();
wc.hIconSm = NULL;
return RegisterClassEx (&wc);
}
bool InitInstance (HINSTANCE hInstance, int nCmdShow)
{
HWND hWnd = CreateWindow (ProgramTitle.c_str (), ProgramTitle.c_str (),
WS_OVERLAPPED, CW_USEDEFAULT, CW_USEDEFAULT, 640, 480,
NULL, NULL, hInstance, NULL);
if (hWnd == 0)
return 0;
ShowWindow (hWnd, nCmdShow);
UpdateWindow (hWnd);
return true;
}
int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
MyRegisterClass (hInstance);
if (!InitInstance (hInstance, nCmdShow)) return 0;
MSG msg;
while (GetMessage (&msg, NULL, 0, 0))
{
TranslateMessage (&msg);
DispatchMessage (&msg);
}
return msg.wParam;
}
|