ReactOS 0.4.15-dev-7953-g1f49173
subclass.c
Go to the documentation of this file.
1#include <windows.h>
2#include <stdio.h>
3
7
10
11int WINAPI
13 HINSTANCE hPrevInstance,
14 LPSTR lpszCmdLine,
15 int nCmdShow)
16{
17 WNDCLASSW wc;
18 HWND hWnd;
19 WCHAR WindowTextW[256];
20 char WindowTextA[256];
21
22 wc.lpszClassName = L"UnicodeClass";
24 wc.style = 0;
26 wc.hIcon = NULL;
27 wc.hCursor = NULL;
29 wc.lpszMenuName = NULL;
30 wc.cbClsExtra = 0;
31 wc.cbWndExtra = 0;
32 if (RegisterClassW(&wc) == 0)
33 {
34 fprintf(stderr, "RegisterClassW failed (last error 0x%lx)\n",
35 GetLastError());
36 return 1;
37 }
38 printf("Unicode class registered, WndProc = 0x%p\n", wc.lpfnWndProc);
39
40 hWnd = CreateWindowA("UnicodeClass",
41 "Unicode Window",
43 0,
44 0,
47 NULL,
48 NULL,
50 NULL);
51 if (hWnd == NULL)
52 {
53 fprintf(stderr, "CreateWindowA failed (last error 0x%lx)\n",
54 GetLastError());
55 return 1;
56 }
57
58 printf("Window created, IsWindowUnicode returns %s\n", IsWindowUnicode(hWnd) ? "TRUE" : "FALSE");
59
60 printf("Calling GetWindowTextW\n");
61 if (! GetWindowTextW(hWnd, WindowTextW, sizeof(WindowTextW) / sizeof(WindowTextW[0])))
62 {
63 fprintf(stderr, "GetWindowTextW failed (last error 0x%lx)\n", GetLastError());
64 return 1;
65 }
66 printf("GetWindowTextW returned Unicode string \"%S\"\n", WindowTextW);
67
68 printf("Calling GetWindowTextA\n");
69 if (! GetWindowTextA(hWnd, WindowTextA, sizeof(WindowTextA) / sizeof(WindowTextA[0])))
70 {
71 fprintf(stderr, "GetWindowTextA failed (last error 0x%lx)\n", GetLastError());
72 return 1;
73 }
74 printf("GetWindowTextA returned Ansi string \"%s\"\n", WindowTextA);
75 printf("\n");
76
78 printf("GetWindowLongW returned 0x%p\n", SavedWndProcW);
80 printf("GetWindowLongA returned 0x%p\n", SavedWndProcA);
81 printf("\n");
82
83 printf("Subclassing window using SetWindowLongW, new WndProc 0x%p\n", UnicodeSubclassProc);
85 printf("After subclass, IsWindowUnicode %s, WndProcA 0x%lx, WndProcW 0x%lx\n",
88
89 printf("Calling GetWindowTextW\n");
90 if (! GetWindowTextW(hWnd, WindowTextW, sizeof(WindowTextW) / sizeof(WindowTextW[0])))
91 {
92 fprintf(stderr, "GetWindowTextW failed (last error 0x%lx)\n", GetLastError());
93 return 1;
94 }
95 printf("GetWindowTextW returned Unicode string \"%S\"\n", WindowTextW);
96 printf("\n");
97
98 printf("Subclassing window using SetWindowLongA, new WndProc 0x%p\n", AnsiSubclassProc);
100 printf("After subclass, IsWindowUnicode %s, WndProcA 0x%lx, WndProcW 0x%lx\n",
103
104 printf("Calling GetWindowTextW\n");
105 if (! GetWindowTextW(hWnd, WindowTextW, sizeof(WindowTextW) / sizeof(WindowTextW[0])))
106 {
107 fprintf(stderr, "GetWindowTextW failed (last error 0x%lx)\n", GetLastError());
108 return 1;
109 }
110 printf("GetWindowTextW returned Unicode string \"%S\"\n", WindowTextW);
111
113
114 return 0;
115}
116
118{
120
121 switch(msg)
122 {
123 case WM_GETTEXT:
124 printf("UnicodeWndProc calling DefWindowProcW\n");
126 printf("UnicodeWndProc Unicode window text \"%S\"\n", (LPWSTR) lParam);
127 break;
128 default:
130 break;
131 }
132
133 return Result;
134}
135
137{
139
140 switch(msg)
141 {
142 case WM_GETTEXT:
143 printf("UnicodeSubclassProc calling SavedWindowProc\n");
145 printf("UnicodeSubclassProc Unicode window text \"%S\"\n", (LPWSTR) lParam);
146 break;
147 default:
149 break;
150 }
151
152 return Result;
153}
154
156{
158
159 switch(msg)
160 {
161 case WM_GETTEXT:
162 printf("AnsiSubclassProc calling SavedWindowProcA\n");
164 printf("AnsiSubclassProc Ansi window text \"%s\"\n", (LPSTR) lParam);
165 break;
166 default:
168 break;
169 }
170
171 return Result;
172}
#define msg(x)
Definition: auth_time.c:54
HWND hWnd
Definition: settings.c:17
HINSTANCE hInstance
Definition: charmap.c:19
WPARAM wParam
Definition: combotst.c:138
LPARAM lParam
Definition: combotst.c:139
#define NULL
Definition: types.h:112
#define CALLBACK
Definition: compat.h:35
#define printf
Definition: freeldr.h:97
#define stderr
Definition: stdio.h:100
_Check_return_opt_ _CRTIMP int __cdecl fprintf(_Inout_ FILE *_File, _In_z_ _Printf_format_string_ const char *_Format,...)
__int3264 LONG_PTR
Definition: mstsclib_h.h:276
unsigned int UINT
Definition: ndis.h:50
#define L(x)
Definition: ntvdm.h:50
#define WS_OVERLAPPEDWINDOW
Definition: pedump.c:637
LPCWSTR lpszClassName
Definition: winuser.h:3185
LPCWSTR lpszMenuName
Definition: winuser.h:3184
HBRUSH hbrBackground
Definition: winuser.h:3183
HICON hIcon
Definition: winuser.h:3181
HINSTANCE hInstance
Definition: winuser.h:3180
int cbClsExtra
Definition: winuser.h:3178
UINT style
Definition: winuser.h:3176
WNDPROC lpfnWndProc
Definition: winuser.h:3177
int cbWndExtra
Definition: winuser.h:3179
HCURSOR hCursor
Definition: winuser.h:3182
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpszCmdLine, int nCmdShow)
Definition: subclass.c:12
LRESULT WINAPI AnsiSubclassProc(HWND, UINT, WPARAM, LPARAM)
Definition: subclass.c:155
LRESULT WINAPI UnicodeWndProc(HWND, UINT, WPARAM, LPARAM)
Definition: subclass.c:117
static WNDPROC SavedWndProcW
Definition: subclass.c:8
LRESULT WINAPI UnicodeSubclassProc(HWND, UINT, WPARAM, LPARAM)
Definition: subclass.c:136
static WNDPROC SavedWndProcA
Definition: subclass.c:9
#define GWLP_WNDPROC
Definition: treelist.c:66
int WINAPI GetWindowTextA(HWND hWnd, LPSTR lpString, int nMaxCount)
Definition: window.c:1330
int WINAPI GetWindowTextW(HWND hWnd, LPWSTR lpString, int nMaxCount)
Definition: window.c:1412
DWORD WINAPI GetLastError(void)
Definition: except.c:1042
LONG_PTR LPARAM
Definition: windef.h:208
LONG_PTR LRESULT
Definition: windef.h:209
UINT_PTR WPARAM
Definition: windef.h:207
#define WINAPI
Definition: msvc.h:6
#define SetWindowLongPtrA
Definition: winuser.h:5345
#define GetWindowLongPtrW
Definition: winuser.h:4829
LRESULT WINAPI DefWindowProcW(_In_ HWND, _In_ UINT, _In_ WPARAM, _In_ LPARAM)
#define CreateWindowA(a, b, c, d, e, f, g, h, i, j, k)
Definition: winuser.h:4315
ATOM WINAPI RegisterClassW(_In_ CONST WNDCLASSW *)
#define WM_GETTEXT
Definition: winuser.h:1618
#define GetWindowLongPtrA
Definition: winuser.h:4828
BOOL WINAPI IsWindowUnicode(_In_ HWND)
#define CW_USEDEFAULT
Definition: winuser.h:225
LRESULT(CALLBACK * WNDPROC)(HWND, UINT, WPARAM, LPARAM)
Definition: winuser.h:2906
#define SetWindowLongPtrW
Definition: winuser.h:5346
LRESULT WINAPI CallWindowProcW(_In_ WNDPROC, _In_ HWND, _In_ UINT, _In_ WPARAM, _In_ LPARAM)
BOOL WINAPI DestroyWindow(_In_ HWND)
LRESULT WINAPI CallWindowProcA(_In_ WNDPROC, _In_ HWND, _In_ UINT, _In_ WPARAM, _In_ LPARAM)
_At_(*)(_In_ PWSK_CLIENT Client, _In_opt_ PUNICODE_STRING NodeName, _In_opt_ PUNICODE_STRING ServiceName, _In_opt_ ULONG NameSpace, _In_opt_ GUID *Provider, _In_opt_ PADDRINFOEXW Hints, _Outptr_ PADDRINFOEXW *Result, _In_opt_ PEPROCESS OwningProcess, _In_opt_ PETHREAD OwningThread, _Inout_ PIRP Irp Result)(Mem)) NTSTATUS(WSKAPI *PFN_WSK_GET_ADDRESS_INFO
Definition: wsk.h:409
char * LPSTR
Definition: xmlstorage.h:182
__wchar_t WCHAR
Definition: xmlstorage.h:180
WCHAR * LPWSTR
Definition: xmlstorage.h:184