blob: a633db29b39c130aded2bf9b8af94deff505c38e [file] [log] [blame]
Alexandre Julliard0c126c71996-02-18 18:44:41 +00001#include <stdio.h>
2#include <windows.h>
Pavel Roskin734247b1999-04-03 13:52:04 +00003/* Win32 counterpart for CalcChildScroll16 is not implemented */
4/* even in MS Visual C++ */
Jeremy Whited3e22d92000-02-10 19:03:02 +00005#include "windef.h"
6#include "wingdi.h"
Alexandre Julliard8d5ace32000-11-10 20:33:59 +00007/*#include <wine/winuser16.h>*/
Alexandre Julliard0c126c71996-02-18 18:44:41 +00008
9void Write (HDC dc, int x, int y, char *s)
10{
Alexandre Julliarda0d77311998-09-13 16:32:00 +000011 SetBkMode(dc, TRANSPARENT);
Alexandre Julliard0c126c71996-02-18 18:44:41 +000012 TextOut (dc, x, y, s, strlen (s));
13}
14
Pavel Roskin734247b1999-04-03 13:52:04 +000015LRESULT CALLBACK WndProc (HWND wnd, UINT msg, WPARAM w, LPARAM l)
Alexandre Julliard0c126c71996-02-18 18:44:41 +000016{
17 static short xChar, yChar;
Alexandre Julliarda0d77311998-09-13 16:32:00 +000018 static RECT rectHola;
19 static char* strHola = "Hola";
Alexandre Julliard0c126c71996-02-18 18:44:41 +000020 HDC dc;
21 PAINTSTRUCT ps;
22 TEXTMETRIC tm;
23
24 switch (msg){
25 case WM_CREATE:
26 dc = GetDC (wnd);
27 GetTextMetrics (dc, &tm);
28 xChar = tm.tmAveCharWidth;
29 yChar = tm.tmHeight;
Alexandre Julliarda0d77311998-09-13 16:32:00 +000030 GetTextExtentPoint32( dc, strHola, strlen(strHola), ((LPSIZE)&rectHola) + 1 );
31 OffsetRect( &rectHola, xChar, yChar );
Alexandre Julliard0c126c71996-02-18 18:44:41 +000032 ReleaseDC (wnd, dc);
33 break;
34
Alexandre Julliarda0d77311998-09-13 16:32:00 +000035 case WM_HSCROLL:
36 case WM_VSCROLL:
37 InvalidateRect(wnd, &rectHola, TRUE );
Alexandre Julliarda3960291999-02-26 11:11:13 +000038 ScrollChildren(wnd, msg, w, l);
Alexandre Julliarda0d77311998-09-13 16:32:00 +000039 return 0;
40
Alexandre Julliard0c126c71996-02-18 18:44:41 +000041 case WM_PAINT:
42 dc = BeginPaint (wnd, &ps);
Alexandre Julliarda0d77311998-09-13 16:32:00 +000043 Write (dc, xChar, yChar, strHola);
Alexandre Julliard0c126c71996-02-18 18:44:41 +000044 EndPaint (wnd, &ps);
45 break;
46
47 case WM_DESTROY:
48 PostQuitMessage (0);
49 break;
50
51 default:
52 return DefWindowProc (wnd, msg, w, l);
53 }
54 return 0l;
55}
56
Pavel Roskin734247b1999-04-03 13:52:04 +000057LRESULT CALLBACK WndProc2 (HWND wnd, UINT msg, WPARAM w, LPARAM l)
Alexandre Julliard0c126c71996-02-18 18:44:41 +000058{
59 static short xChar, yChar;
Alexandre Julliarda0d77311998-09-13 16:32:00 +000060 static RECT rectInfo;
Alexandre Julliard0c126c71996-02-18 18:44:41 +000061 char buf[128];
62 HDC dc;
63 PAINTSTRUCT ps;
64 TEXTMETRIC tm;
65
66 switch (msg){
67 case WM_CREATE:
68 dc = GetDC (wnd);
69 GetTextMetrics (dc, &tm);
70 xChar = tm.tmAveCharWidth;
71 yChar = tm.tmHeight;
72 ReleaseDC (wnd, dc);
73 break;
74
75 case WM_PAINT:
76 dc = BeginPaint (wnd, &ps);
77 sprintf(buf,"ps.rcPaint = {left = %d, top = %d, right = %d, bottom = %d}",
78 ps.rcPaint.left,ps.rcPaint.top,ps.rcPaint.right,ps.rcPaint.bottom);
Alexandre Julliarda0d77311998-09-13 16:32:00 +000079 rectInfo.left = rectInfo.top = 0;
80 GetTextExtentPoint32 (dc, buf, strlen(buf), ((LPSIZE)&rectInfo) + 1 );
81 OffsetRect (&rectInfo, xChar, yChar );
Alexandre Julliard0c126c71996-02-18 18:44:41 +000082 Write (dc, xChar, yChar, buf);
83 EndPaint (wnd, &ps);
84 break;
85
Alexandre Julliarda0d77311998-09-13 16:32:00 +000086 case WM_MOVE:
87 case WM_SIZE:
88 InvalidateRect( wnd, &rectInfo, TRUE );
Alexandre Julliard8d5ace32000-11-10 20:33:59 +000089 /*CalcChildScroll16( (UINT16)GetParent(wnd), SB_BOTH );*/
Alexandre Julliarda0d77311998-09-13 16:32:00 +000090 break;
91
Alexandre Julliard0c126c71996-02-18 18:44:41 +000092 case WM_DESTROY:
93 PostQuitMessage (0);
94 break;
95
96 default:
97 return DefWindowProc (wnd, msg, w, l);
98 }
99 return 0l;
100}
101
Francois Gouget28fc36d2000-07-23 19:32:11 +0000102int PASCAL WinMain (HINSTANCE inst, HINSTANCE prev, LPSTR cmdline, int show)
Alexandre Julliard0c126c71996-02-18 18:44:41 +0000103{
104 HWND wnd,wnd2;
105 MSG msg;
106 WNDCLASS class;
Alexandre Julliard1285c2f1996-05-06 16:06:24 +0000107 char className[] = "class"; /* To make sure className >= 0x10000 */
108 char class2Name[] = "class2";
109 char winName[] = "Test app";
Alexandre Julliard0c126c71996-02-18 18:44:41 +0000110
111 if (!prev){
112 class.style = CS_HREDRAW | CS_VREDRAW;
113 class.lpfnWndProc = WndProc;
114 class.cbClsExtra = 0;
115 class.cbWndExtra = 0;
116 class.hInstance = inst;
117 class.hIcon = LoadIcon (0, IDI_APPLICATION);
118 class.hCursor = LoadCursor (0, IDC_ARROW);
119 class.hbrBackground = GetStockObject (WHITE_BRUSH);
120 class.lpszMenuName = NULL;
Pavel Roskin734247b1999-04-03 13:52:04 +0000121 class.lpszClassName = className;
Alexandre Julliard0c126c71996-02-18 18:44:41 +0000122 if (!RegisterClass (&class))
123 return FALSE;
124 }
125
Alexandre Julliarda0d77311998-09-13 16:32:00 +0000126 wnd = CreateWindow (className, winName, WS_OVERLAPPEDWINDOW | WS_CLIPCHILDREN | WS_VSCROLL | WS_HSCROLL,
Alexandre Julliard0c126c71996-02-18 18:44:41 +0000127 CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, 0,
128 0, inst, 0);
129
130 if (!prev){
131 class.lpfnWndProc = WndProc2;
Alexandre Julliard1285c2f1996-05-06 16:06:24 +0000132 class.lpszClassName = class2Name;
Alexandre Julliarda0d77311998-09-13 16:32:00 +0000133 class.hbrBackground = GetStockObject(GRAY_BRUSH);
Alexandre Julliard0c126c71996-02-18 18:44:41 +0000134 if (!RegisterClass (&class))
135 return FALSE;
136 }
137
Alexandre Julliarda0d77311998-09-13 16:32:00 +0000138 wnd2= CreateWindow (class2Name,"Child window", WS_CAPTION | WS_CHILD | WS_THICKFRAME,
139 50, 50, 350, 100, wnd, 0, inst, 0);
Alexandre Julliard0c126c71996-02-18 18:44:41 +0000140
141 ShowWindow (wnd, show);
142 UpdateWindow (wnd);
143 ShowWindow (wnd2, show);
144 UpdateWindow (wnd2);
145
146 while (GetMessage (&msg, 0, 0, 0)){
147 TranslateMessage (&msg);
148 DispatchMessage (&msg);
149 }
150 return 0;
151}