update for HEAD-2003021201
[reactos.git] / apps / tests / winhello / winhello.c
1 #include <windows.h>
2 #include <stdio.h>
3
4 HFONT tf;
5 LRESULT WINAPI MainWndProc(HWND, UINT, WPARAM, LPARAM);
6
7 int WINAPI 
8 WinMain(HINSTANCE hInstance,
9         HINSTANCE hPrevInstance,
10         LPSTR lpszCmdLine,
11         int nCmdShow)
12 {
13   WNDCLASS wc;
14   MSG msg;
15   HWND hWnd;
16
17   wc.lpszClassName = "HelloClass";
18   wc.lpfnWndProc = MainWndProc;
19   wc.style = CS_VREDRAW | CS_HREDRAW;
20   wc.hInstance = hInstance;
21   wc.hIcon = LoadIcon(NULL, IDI_APPLICATION);
22   wc.hCursor = LoadCursor(NULL, IDC_ARROW);
23   wc.hbrBackground = (HBRUSH)GetStockObject(GRAY_BRUSH);
24   wc.lpszMenuName = NULL;
25   wc.cbClsExtra = 0;
26   wc.cbWndExtra = 0;
27   if (RegisterClass(&wc) == 0)
28     {
29       fprintf(stderr, "RegisterClass failed (last error 0x%X)\n",
30               GetLastError());
31       return(1);
32     }
33
34   hWnd = CreateWindow("HelloClass",
35                       "Hello World",
36                       WS_OVERLAPPEDWINDOW|WS_HSCROLL|WS_VSCROLL,
37                       0,
38                       0,
39                       CW_USEDEFAULT,
40                       CW_USEDEFAULT,
41                       NULL,
42                       NULL,
43                       hInstance,
44                       NULL);
45   if (hWnd == NULL)
46     {
47       fprintf(stderr, "CreateWindow failed (last error 0x%X)\n",
48               GetLastError());
49       return(1);
50     }
51
52         tf = CreateFontA(14, 0, 0, TA_BASELINE, FW_NORMAL, FALSE, FALSE, FALSE,
53                 ANSI_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS,
54                 DEFAULT_QUALITY, FIXED_PITCH|FF_DONTCARE, "Timmons");
55
56   ShowWindow(hWnd, nCmdShow);
57
58   while(GetMessage(&msg, NULL, 0, 0))
59   {
60     TranslateMessage(&msg);
61     DispatchMessage(&msg);
62   }
63
64   DeleteObject(tf);
65
66   return msg.wParam;
67 }
68
69 LRESULT CALLBACK MainWndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
70 {
71         PAINTSTRUCT ps;
72         HDC hDC;
73         RECT clr, wir;
74         char spr[100], sir[100];
75
76         switch(msg)
77         {
78         case WM_LBUTTONUP:
79           {
80             ULONG x, y;
81             RECT Rect;
82             hDC = GetDC(hWnd);
83             x = LOWORD(lParam);
84             y = HIWORD(lParam);
85             Rect.left = x - 5;
86             Rect.top = y - 5;
87             Rect.right = x + 5;
88             Rect.bottom = y + 5;
89             FillRect(hDC, &Rect, CreateSolidBrush(RGB(0xFF, 0x00, 0x00)));
90             ReleaseDC(hWnd, hDC);
91             break;
92           }
93
94         case WM_PAINT:
95           hDC = BeginPaint(hWnd, &ps);
96           SelectObject(hDC, tf);
97           TextOut(hDC, 10, 10, "Hello World from ReactOS!", strlen("Hello World from ReactOS!"));
98           GetClientRect(hWnd, &clr);
99           GetWindowRect(hWnd, &wir);
100           sprintf(spr, "%d,%d,%d,%d              ", clr.left, clr.top, clr.right, clr.bottom);
101           sprintf(sir, "%d,%d,%d,%d              ", wir.left, wir.top, wir.right, wir.bottom);
102           TextOut(hDC, 10, 30, spr, 20);
103           TextOut(hDC, 10, 50, sir, 20);
104           EndPaint(hWnd, &ps);
105           break;
106
107         case WM_DESTROY:
108           PostQuitMessage(0);
109           break;
110
111         default:
112           return DefWindowProc(hWnd, msg, wParam, lParam);
113         }
114         return 0;
115 }