ReactOS  0.4.12-dev-919-gfc3b8d5
subclass.c
Go to the documentation of this file.
1 #include <windows.h>
2 #include <stdio.h>
3 
7 
10 
11 int 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;
25  wc.hInstance = hInstance;
26  wc.hIcon = NULL;
27  wc.hCursor = NULL;
28  wc.hbrBackground = 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,
49  hInstance,
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",
101  IsWindowUnicode(hWnd) ? "TRUE" : "FALSE", GetWindowLongPtrA(hWnd, GWLP_WNDPROC),
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 {
119  LRESULT Result;
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 {
138  LRESULT Result;
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 {
157  LRESULT Result;
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 }
LRESULT WINAPI UnicodeWndProc(HWND, UINT, WPARAM, LPARAM)
Definition: subclass.c:117
int WINAPI GetWindowTextA(HWND hWnd, LPSTR lpString, int nMaxCount)
Definition: window.c:1296
UINT style
Definition: winuser.h:3129
LPCWSTR lpszMenuName
Definition: winuser.h:3137
LRESULT WINAPI AnsiSubclassProc(HWND, UINT, WPARAM, LPARAM)
Definition: subclass.c:155
#define WM_GETTEXT
Definition: winuser.h:1600
#define CALLBACK
Definition: compat.h:27
HWND hWnd
Definition: settings.c:17
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1059
int cbClsExtra
Definition: winuser.h:3131
UINT_PTR WPARAM
Definition: windef.h:207
#define GetWindowLongPtrW
Definition: winuser.h:4698
char * LPSTR
Definition: xmlstorage.h:182
BOOL WINAPI DestroyWindow(_In_ HWND)
WPARAM wParam
Definition: combotst.c:138
LRESULT WINAPI DefWindowProcW(_In_ HWND, _In_ UINT, _In_ WPARAM, _In_ LPARAM)
LRESULT WINAPI CallWindowProcA(_In_ WNDPROC, _In_ HWND, _In_ UINT, _In_ WPARAM, _In_ LPARAM)
ATOM WINAPI RegisterClassW(_In_ CONST WNDCLASSW *)
HINSTANCE hInstance
Definition: charmap.c:20
_Check_return_opt_ _CRTIMP int __cdecl fprintf(_Inout_ FILE *_File, _In_z_ _Printf_format_string_ const char *_Format,...)
WNDPROC lpfnWndProc
Definition: winuser.h:3130
#define CreateWindowA(a, b, c, d, e, f, g, h, i, j, k)
Definition: winuser.h:4184
#define CW_USEDEFAULT
Definition: winuser.h:225
LRESULT WINAPI UnicodeSubclassProc(HWND, UINT, WPARAM, LPARAM)
Definition: subclass.c:136
smooth NULL
Definition: ftsmooth.c:416
_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:426
LPCWSTR lpszClassName
Definition: winuser.h:3138
LONG_PTR LPARAM
Definition: windef.h:208
BOOL WINAPI IsWindowUnicode(_In_ HWND)
#define GetWindowLongPtrA
Definition: winuser.h:4697
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpszCmdLine, int nCmdShow)
Definition: subclass.c:12
int cbWndExtra
Definition: winuser.h:3132
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define WINAPI
Definition: msvc.h:8
HICON hIcon
Definition: winuser.h:3134
static const WCHAR L[]
Definition: oid.c:1250
#define SetWindowLongPtrA
Definition: winuser.h:5214
#define GWLP_WNDPROC
Definition: treelist.c:66
HCURSOR hCursor
Definition: winuser.h:3135
LRESULT(CALLBACK * WNDPROC)(HWND, UINT, WPARAM, LPARAM)
Definition: winuser.h:2859
int WINAPI GetWindowTextW(HWND hWnd, LPWSTR lpString, int nMaxCount)
Definition: window.c:1378
HBRUSH hbrBackground
Definition: winuser.h:3136
static WNDPROC SavedWndProcW
Definition: subclass.c:8
__int3264 LONG_PTR
Definition: mstsclib_h.h:276
unsigned int UINT
Definition: ndis.h:50
static WNDPROC SavedWndProcA
Definition: subclass.c:9
HINSTANCE hInstance
Definition: winuser.h:3133
#define msg(x)
Definition: auth_time.c:54
LRESULT WINAPI CallWindowProcW(_In_ WNDPROC, _In_ HWND, _In_ UINT, _In_ WPARAM, _In_ LPARAM)
#define WS_OVERLAPPEDWINDOW
Definition: pedump.c:637
FILE * stderr
#define SetWindowLongPtrW
Definition: winuser.h:5215
WCHAR * LPWSTR
Definition: xmlstorage.h:184
LONG_PTR LRESULT
Definition: windef.h:209
LPARAM lParam
Definition: combotst.c:139
#define printf
Definition: config.h:203