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