Initialize lpdwNeeded.
[wine/multimedia.git] / libtest / hello4.c
blobb625f65167ae0493ed36f5421746a53870919660
1 #include <stdio.h>
2 #include <windows.h>
4 void Write (HDC dc, int x, int y, char *s)
6 SetBkMode(dc, TRANSPARENT);
7 TextOut (dc, x, y, s, strlen (s));
10 LRESULT WndProc (HWND wnd, UINT msg, WPARAM w, LPARAM l)
12 static short xChar, yChar;
13 static RECT rectHola;
14 static char* strHola = "Hola";
15 HDC dc;
16 PAINTSTRUCT ps;
17 TEXTMETRIC tm;
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;
30 case WM_HSCROLL:
31 case WM_VSCROLL:
32 InvalidateRect(wnd, &rectHola, TRUE );
33 ScrollChildren32(wnd, msg, w, l);
34 return 0;
36 case WM_PAINT:
37 dc = BeginPaint (wnd, &ps);
38 Write (dc, xChar, yChar, strHola);
39 EndPaint (wnd, &ps);
40 break;
42 case WM_DESTROY:
43 PostQuitMessage (0);
44 break;
46 default:
47 return DefWindowProc (wnd, msg, w, l);
49 return 0l;
52 LRESULT WndProc2 (HWND wnd, UINT msg, WPARAM w, LPARAM l)
54 static short xChar, yChar;
55 static RECT rectInfo;
56 char buf[128];
57 HDC dc;
58 PAINTSTRUCT ps;
59 TEXTMETRIC tm;
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;
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;
81 case WM_MOVE:
82 case WM_SIZE:
83 InvalidateRect( wnd, &rectInfo, TRUE );
84 CalcChildScroll( (UINT16)GetParent(wnd), SB_BOTH );
85 break;
87 case WM_DESTROY:
88 PostQuitMessage (0);
89 break;
91 default:
92 return DefWindowProc (wnd, msg, w, l);
94 return 0l;
97 int PASCAL WinMain (HANDLE inst, HANDLE prev, LPSTR cmdline, int show)
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";
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;
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);
125 if (!prev){
126 class.lpfnWndProc = WndProc2;
127 class.lpszClassName = class2Name;
128 class.hbrBackground = GetStockObject(GRAY_BRUSH);
129 if (!RegisterClass (&class))
130 return FALSE;
133 wnd2= CreateWindow (class2Name,"Child window", WS_CAPTION | WS_CHILD | WS_THICKFRAME,
134 50, 50, 350, 100, wnd, 0, inst, 0);
136 ShowWindow (wnd, show);
137 UpdateWindow (wnd);
138 ShowWindow (wnd2, show);
139 UpdateWindow (wnd2);
141 while (GetMessage (&msg, 0, 0, 0)){
142 TranslateMessage (&msg);
143 DispatchMessage (&msg);
145 return 0;