Added CS_PARENTDC style.
[wine] / libtest / hello.c
1 /*
2  * Copyright 1994 Miguel de Icaza
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2.1 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
17  */
18
19 #include <windows.h>
20
21 char szAppName[] = "Hello";
22
23 long FAR PASCAL WndProc(HWND, UINT, WPARAM, LPARAM);
24
25 int PASCAL WinMain (HINSTANCE hInstance, HINSTANCE hPrevInst, LPSTR lpszCmdLine,
26                          int nCmdShow)
27 {
28         HWND hwnd;
29         MSG msg;
30         WNDCLASS wndclass;
31
32         if(!hPrevInst) {
33
34                 wndclass.style =  CS_HREDRAW | CS_VREDRAW;
35                 wndclass.lpfnWndProc = WndProc;
36                 wndclass.cbClsExtra = 0;
37                 wndclass.cbWndExtra = 0;
38                 wndclass.hInstance = hInstance;
39                 wndclass.hIcon = LoadIcon(NULL, IDI_APPLICATION);
40                 wndclass.hCursor = LoadCursor(NULL, IDC_ARROW);
41                 wndclass.hbrBackground = GetStockObject(WHITE_BRUSH);
42                 wndclass.lpszMenuName = NULL;
43                 wndclass.lpszClassName = szAppName;
44
45                 RegisterClass(&wndclass);
46
47                                         
48         }
49
50         hwnd = CreateWindow(szAppName, szAppName,
51          WS_HSCROLL | WS_VSCROLL | WS_OVERLAPPEDWINDOW,
52          CW_USEDEFAULT, CW_USEDEFAULT, 600,
53          400, NULL, NULL, hInstance, NULL);
54
55         ShowWindow(hwnd, nCmdShow);
56         UpdateWindow(hwnd);
57                                                                                                                         
58                                                                         
59         while(GetMessage(&msg, NULL, 0, 0)) {
60                 TranslateMessage(&msg);
61                 DispatchMessage(&msg);
62         }                                       
63         return msg.wParam;
64 }                                       
65
66
67
68 long FAR PASCAL WndProc(HWND hwnd, UINT message, WPARAM wParam,
69                                 LPARAM lParam)
70 {
71         HDC hdc;
72         RECT rect;
73         SIZE size;
74         PAINTSTRUCT ps;
75
76         switch(message) {
77                         
78         case WM_PAINT:
79                 hdc = BeginPaint(hwnd, &ps);
80                 GetClientRect(hwnd, &rect);
81                 InflateRect(&rect, -10, -10);
82                 if( !IsRectEmpty( &rect ) )
83                 {
84                     GetTextExtentPoint32(hdc, szAppName, strlen(szAppName), &size);
85                     SelectObject(hdc, GetStockObject(LTGRAY_BRUSH));
86                     Rectangle(hdc, rect.left, rect.top, rect.right, rect.bottom);
87                     rect.left = (rect.right + rect.left - size.cx) / 2;
88                     rect.top  = (rect.bottom + rect.top - size.cy) / 2;
89                     SetBkMode(hdc, TRANSPARENT);
90                     TextOut(hdc, rect.left, rect.top, szAppName, strlen(szAppName) );
91                 }
92                 EndPaint(hwnd, &ps);
93                 return 0;
94                                                         
95         case WM_DESTROY:
96                 PostQuitMessage(0);
97                 return 0;
98         }
99         return DefWindowProc(hwnd, message, wParam, lParam);
100 }                                                                                               
101