Work-around for gcc bug.
[wine] / libtest / hello.c
1 #include <windows.h>
2
3 char szAppName[] = "Hello";
4
5 long FAR PASCAL WndProc(HWND, UINT, WPARAM, LPARAM);
6
7 int PASCAL WinMain (HINSTANCE hInstance, HINSTANCE hPrevInst, LPSTR lpszCmdLine,
8                          int nCmdShow)
9 {
10         HWND hwnd;
11         MSG msg;
12         WNDCLASS wndclass;
13
14         if(!hPrevInst) {
15
16                 wndclass.style =  CS_HREDRAW | CS_VREDRAW;
17                 wndclass.lpfnWndProc = WndProc;
18                 wndclass.cbClsExtra = 0;
19                 wndclass.cbWndExtra = 0;
20                 wndclass.hInstance = hInstance;
21                 wndclass.hIcon = LoadIcon(NULL, IDI_APPLICATION);
22                 wndclass.hCursor = LoadCursor(NULL, IDC_ARROW);
23                 wndclass.hbrBackground = GetStockObject(WHITE_BRUSH);
24                 wndclass.lpszMenuName = NULL;
25                 wndclass.lpszClassName = szAppName;
26
27                 RegisterClass(&wndclass);
28
29                                         
30         }
31
32         hwnd = CreateWindow(szAppName, szAppName,
33          WS_HSCROLL | WS_VSCROLL | WS_OVERLAPPEDWINDOW,
34          CW_USEDEFAULT, CW_USEDEFAULT, 600,
35          400, NULL, NULL, hInstance, NULL);
36
37         ShowWindow(hwnd, nCmdShow);
38         UpdateWindow(hwnd);
39                                                                                                                         
40                                                                         
41         while(GetMessage(&msg, NULL, 0, 0)) {
42                 TranslateMessage(&msg);
43                 DispatchMessage(&msg);
44         }                                       
45         return msg.wParam;
46 }                                       
47
48
49
50 long FAR PASCAL WndProc(HWND hwnd, UINT message, WPARAM wParam,
51                                 LPARAM lParam)
52 {
53         HDC hdc;
54         RECT rect;
55         SIZE size;
56         PAINTSTRUCT ps;
57
58         switch(message) {
59                         
60         case WM_PAINT:
61                 hdc = BeginPaint(hwnd, &ps);
62                 GetClientRect(hwnd, &rect);
63                 InflateRect(&rect, -10, -10);
64                 if( !IsRectEmpty( &rect ) )
65                 {
66                     GetTextExtentPoint32(hdc, szAppName, strlen(szAppName), &size);
67                     SelectObject(hdc, GetStockObject(LTGRAY_BRUSH));
68                     Rectangle(hdc, rect.left, rect.top, rect.right, rect.bottom);
69                     rect.left = (rect.right + rect.left - size.cx) / 2;
70                     rect.top  = (rect.bottom + rect.top - size.cy) / 2;
71                     SetBkMode(hdc, TRANSPARENT);
72                     TextOut(hdc, rect.left, rect.top, szAppName, strlen(szAppName) );
73                 }
74                 EndPaint(hwnd, &ps);
75                 return 0;
76                                                         
77         case WM_DESTROY:
78                 PostQuitMessage(0);
79                 return 0;
80         }
81         return DefWindowProc(hwnd, message, wParam, lParam);
82 }                                                                                               
83