Alexandre Julliard | 0c126c7 | 1996-02-18 18:44:41 +0000 | [diff] [blame] | 1 | #include <stdio.h> |
| 2 | #include <windows.h> |
Pavel Roskin | 734247b | 1999-04-03 13:52:04 +0000 | [diff] [blame] | 3 | /* Win32 counterpart for CalcChildScroll16 is not implemented */ |
| 4 | /* even in MS Visual C++ */ |
Jeremy White | d3e22d9 | 2000-02-10 19:03:02 +0000 | [diff] [blame] | 5 | #include "windef.h" |
| 6 | #include "wingdi.h" |
Alexandre Julliard | 8d5ace3 | 2000-11-10 20:33:59 +0000 | [diff] [blame] | 7 | /*#include <wine/winuser16.h>*/ |
Alexandre Julliard | 0c126c7 | 1996-02-18 18:44:41 +0000 | [diff] [blame] | 8 | |
| 9 | void Write (HDC dc, int x, int y, char *s) |
| 10 | { |
Alexandre Julliard | a0d7731 | 1998-09-13 16:32:00 +0000 | [diff] [blame] | 11 | SetBkMode(dc, TRANSPARENT); |
Alexandre Julliard | 0c126c7 | 1996-02-18 18:44:41 +0000 | [diff] [blame] | 12 | TextOut (dc, x, y, s, strlen (s)); |
| 13 | } |
| 14 | |
Pavel Roskin | 734247b | 1999-04-03 13:52:04 +0000 | [diff] [blame] | 15 | LRESULT CALLBACK WndProc (HWND wnd, UINT msg, WPARAM w, LPARAM l) |
Alexandre Julliard | 0c126c7 | 1996-02-18 18:44:41 +0000 | [diff] [blame] | 16 | { |
| 17 | static short xChar, yChar; |
Alexandre Julliard | a0d7731 | 1998-09-13 16:32:00 +0000 | [diff] [blame] | 18 | static RECT rectHola; |
| 19 | static char* strHola = "Hola"; |
Alexandre Julliard | 0c126c7 | 1996-02-18 18:44:41 +0000 | [diff] [blame] | 20 | 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 Julliard | a0d7731 | 1998-09-13 16:32:00 +0000 | [diff] [blame] | 30 | GetTextExtentPoint32( dc, strHola, strlen(strHola), ((LPSIZE)&rectHola) + 1 ); |
| 31 | OffsetRect( &rectHola, xChar, yChar ); |
Alexandre Julliard | 0c126c7 | 1996-02-18 18:44:41 +0000 | [diff] [blame] | 32 | ReleaseDC (wnd, dc); |
| 33 | break; |
| 34 | |
Alexandre Julliard | a0d7731 | 1998-09-13 16:32:00 +0000 | [diff] [blame] | 35 | case WM_HSCROLL: |
| 36 | case WM_VSCROLL: |
| 37 | InvalidateRect(wnd, &rectHola, TRUE ); |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 38 | ScrollChildren(wnd, msg, w, l); |
Alexandre Julliard | a0d7731 | 1998-09-13 16:32:00 +0000 | [diff] [blame] | 39 | return 0; |
| 40 | |
Alexandre Julliard | 0c126c7 | 1996-02-18 18:44:41 +0000 | [diff] [blame] | 41 | case WM_PAINT: |
| 42 | dc = BeginPaint (wnd, &ps); |
Alexandre Julliard | a0d7731 | 1998-09-13 16:32:00 +0000 | [diff] [blame] | 43 | Write (dc, xChar, yChar, strHola); |
Alexandre Julliard | 0c126c7 | 1996-02-18 18:44:41 +0000 | [diff] [blame] | 44 | 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 Roskin | 734247b | 1999-04-03 13:52:04 +0000 | [diff] [blame] | 57 | LRESULT CALLBACK WndProc2 (HWND wnd, UINT msg, WPARAM w, LPARAM l) |
Alexandre Julliard | 0c126c7 | 1996-02-18 18:44:41 +0000 | [diff] [blame] | 58 | { |
| 59 | static short xChar, yChar; |
Alexandre Julliard | a0d7731 | 1998-09-13 16:32:00 +0000 | [diff] [blame] | 60 | static RECT rectInfo; |
Alexandre Julliard | 0c126c7 | 1996-02-18 18:44:41 +0000 | [diff] [blame] | 61 | 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 Julliard | a0d7731 | 1998-09-13 16:32:00 +0000 | [diff] [blame] | 79 | rectInfo.left = rectInfo.top = 0; |
| 80 | GetTextExtentPoint32 (dc, buf, strlen(buf), ((LPSIZE)&rectInfo) + 1 ); |
| 81 | OffsetRect (&rectInfo, xChar, yChar ); |
Alexandre Julliard | 0c126c7 | 1996-02-18 18:44:41 +0000 | [diff] [blame] | 82 | Write (dc, xChar, yChar, buf); |
| 83 | EndPaint (wnd, &ps); |
| 84 | break; |
| 85 | |
Alexandre Julliard | a0d7731 | 1998-09-13 16:32:00 +0000 | [diff] [blame] | 86 | case WM_MOVE: |
| 87 | case WM_SIZE: |
| 88 | InvalidateRect( wnd, &rectInfo, TRUE ); |
Alexandre Julliard | 8d5ace3 | 2000-11-10 20:33:59 +0000 | [diff] [blame] | 89 | /*CalcChildScroll16( (UINT16)GetParent(wnd), SB_BOTH );*/ |
Alexandre Julliard | a0d7731 | 1998-09-13 16:32:00 +0000 | [diff] [blame] | 90 | break; |
| 91 | |
Alexandre Julliard | 0c126c7 | 1996-02-18 18:44:41 +0000 | [diff] [blame] | 92 | 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 Gouget | 28fc36d | 2000-07-23 19:32:11 +0000 | [diff] [blame] | 102 | int PASCAL WinMain (HINSTANCE inst, HINSTANCE prev, LPSTR cmdline, int show) |
Alexandre Julliard | 0c126c7 | 1996-02-18 18:44:41 +0000 | [diff] [blame] | 103 | { |
| 104 | HWND wnd,wnd2; |
| 105 | MSG msg; |
| 106 | WNDCLASS class; |
Alexandre Julliard | 1285c2f | 1996-05-06 16:06:24 +0000 | [diff] [blame] | 107 | char className[] = "class"; /* To make sure className >= 0x10000 */ |
| 108 | char class2Name[] = "class2"; |
| 109 | char winName[] = "Test app"; |
Alexandre Julliard | 0c126c7 | 1996-02-18 18:44:41 +0000 | [diff] [blame] | 110 | |
| 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 Roskin | 734247b | 1999-04-03 13:52:04 +0000 | [diff] [blame] | 121 | class.lpszClassName = className; |
Alexandre Julliard | 0c126c7 | 1996-02-18 18:44:41 +0000 | [diff] [blame] | 122 | if (!RegisterClass (&class)) |
| 123 | return FALSE; |
| 124 | } |
| 125 | |
Alexandre Julliard | a0d7731 | 1998-09-13 16:32:00 +0000 | [diff] [blame] | 126 | wnd = CreateWindow (className, winName, WS_OVERLAPPEDWINDOW | WS_CLIPCHILDREN | WS_VSCROLL | WS_HSCROLL, |
Alexandre Julliard | 0c126c7 | 1996-02-18 18:44:41 +0000 | [diff] [blame] | 127 | CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, 0, |
| 128 | 0, inst, 0); |
| 129 | |
| 130 | if (!prev){ |
| 131 | class.lpfnWndProc = WndProc2; |
Alexandre Julliard | 1285c2f | 1996-05-06 16:06:24 +0000 | [diff] [blame] | 132 | class.lpszClassName = class2Name; |
Alexandre Julliard | a0d7731 | 1998-09-13 16:32:00 +0000 | [diff] [blame] | 133 | class.hbrBackground = GetStockObject(GRAY_BRUSH); |
Alexandre Julliard | 0c126c7 | 1996-02-18 18:44:41 +0000 | [diff] [blame] | 134 | if (!RegisterClass (&class)) |
| 135 | return FALSE; |
| 136 | } |
| 137 | |
Alexandre Julliard | a0d7731 | 1998-09-13 16:32:00 +0000 | [diff] [blame] | 138 | wnd2= CreateWindow (class2Name,"Child window", WS_CAPTION | WS_CHILD | WS_THICKFRAME, |
| 139 | 50, 50, 350, 100, wnd, 0, inst, 0); |
Alexandre Julliard | 0c126c7 | 1996-02-18 18:44:41 +0000 | [diff] [blame] | 140 | |
| 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 | } |