New file to test DRIVE_GetLabel.
[wine] / libtest / hello4.c
1 #include <stdio.h>
2 #include <windows.h>
3
4 void Write (HDC dc, int x, int y, char *s)
5 {
6     SetBkMode(dc, TRANSPARENT);
7     TextOut (dc, x, y, s, strlen (s));
8 }
9
10 LRESULT WndProc (HWND wnd, UINT msg, WPARAM w, LPARAM l)
11 {
12     static short xChar, yChar;
13     static RECT  rectHola;
14     static char* strHola = "Hola";
15     HDC dc;
16     PAINTSTRUCT ps;
17     TEXTMETRIC tm;
18
19     switch (msg){
20     case WM_CREATE:
21         dc = GetDC (wnd);
22         GetTextMetrics (dc, &tm);
23         xChar = tm.tmAveCharWidth;
24         yChar = tm.tmHeight;
25         GetTextExtentPoint32( dc, strHola, strlen(strHola), ((LPSIZE)&rectHola) + 1 );
26         OffsetRect( &rectHola, xChar, yChar );
27         ReleaseDC (wnd, dc);
28         break;
29
30     case WM_HSCROLL:
31     case WM_VSCROLL:
32         InvalidateRect(wnd, &rectHola, TRUE );
33         ScrollChildren32(wnd, msg, w, l);
34         return 0;
35
36     case WM_PAINT:
37         dc = BeginPaint (wnd, &ps);
38         Write (dc, xChar, yChar, strHola);
39         EndPaint (wnd, &ps);
40         break;
41
42     case WM_DESTROY:
43         PostQuitMessage (0);
44         break;
45
46     default:
47         return DefWindowProc (wnd, msg, w, l);
48     }
49     return 0l;
50 }
51
52 LRESULT WndProc2 (HWND wnd, UINT msg, WPARAM w, LPARAM l)
53 {
54     static short xChar, yChar;
55     static RECT  rectInfo;
56     char buf[128];
57     HDC dc;
58     PAINTSTRUCT ps;
59     TEXTMETRIC tm;
60
61     switch (msg){
62     case WM_CREATE:
63         dc = GetDC (wnd);
64         GetTextMetrics (dc, &tm);
65         xChar = tm.tmAveCharWidth;
66         yChar = tm.tmHeight;
67         ReleaseDC (wnd, dc);
68         break;
69
70     case WM_PAINT:
71         dc = BeginPaint (wnd, &ps);
72         sprintf(buf,"ps.rcPaint = {left = %d, top = %d, right = %d, bottom = %d}",
73                 ps.rcPaint.left,ps.rcPaint.top,ps.rcPaint.right,ps.rcPaint.bottom);
74         rectInfo.left = rectInfo.top = 0;
75         GetTextExtentPoint32 (dc, buf, strlen(buf), ((LPSIZE)&rectInfo) + 1 );
76         OffsetRect (&rectInfo, xChar, yChar );
77         Write (dc, xChar, yChar, buf);
78         EndPaint (wnd, &ps);
79         break;
80
81     case WM_MOVE:
82     case WM_SIZE:
83         InvalidateRect( wnd, &rectInfo, TRUE );
84         CalcChildScroll( (UINT16)GetParent(wnd), SB_BOTH );
85         break;
86
87     case WM_DESTROY:
88         PostQuitMessage (0);
89         break;
90
91     default:
92         return DefWindowProc (wnd, msg, w, l);
93     }
94     return 0l;
95 }
96
97 int PASCAL WinMain (HANDLE inst, HANDLE prev, LPSTR cmdline, int show)
98 {
99     HWND     wnd,wnd2;
100     MSG      msg;
101     WNDCLASS class;
102     char className[] = "class";  /* To make sure className >= 0x10000 */
103     char class2Name[] = "class2";
104     char winName[] = "Test app";
105
106     if (!prev){
107         class.style = CS_HREDRAW | CS_VREDRAW;
108         class.lpfnWndProc = WndProc;
109         class.cbClsExtra = 0;
110         class.cbWndExtra = 0;
111         class.hInstance  = inst;
112         class.hIcon      = LoadIcon (0, IDI_APPLICATION);
113         class.hCursor    = LoadCursor (0, IDC_ARROW);
114         class.hbrBackground = GetStockObject (WHITE_BRUSH);
115         class.lpszMenuName = NULL;
116         class.lpszClassName = (SEGPTR)className;
117         if (!RegisterClass (&class))
118             return FALSE;
119     }
120
121     wnd = CreateWindow (className, winName, WS_OVERLAPPEDWINDOW | WS_CLIPCHILDREN | WS_VSCROLL | WS_HSCROLL,
122                         CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, 0, 
123                         0, inst, 0);
124
125     if (!prev){
126         class.lpfnWndProc = WndProc2;
127         class.lpszClassName = class2Name;
128         class.hbrBackground = GetStockObject(GRAY_BRUSH);
129         if (!RegisterClass (&class))
130             return FALSE;
131     }
132
133     wnd2= CreateWindow (class2Name,"Child window", WS_CAPTION | WS_CHILD | WS_THICKFRAME, 
134                         50, 50, 350, 100, wnd, 0, inst, 0);
135
136     ShowWindow (wnd, show);
137     UpdateWindow (wnd);
138     ShowWindow (wnd2, show);
139     UpdateWindow (wnd2);
140
141     while (GetMessage (&msg, 0, 0, 0)){
142         TranslateMessage (&msg);
143         DispatchMessage (&msg);
144     }
145     return 0;
146 }