ReactOS 0.4.15-dev-7842-g558ab78
subclass.c File Reference
#include <windows.h>
#include <stdio.h>
Include dependency graph for subclass.c:

Go to the source code of this file.

Functions

LRESULT WINAPI UnicodeWndProc (HWND, UINT, WPARAM, LPARAM)
 
LRESULT WINAPI UnicodeSubclassProc (HWND, UINT, WPARAM, LPARAM)
 
LRESULT WINAPI AnsiSubclassProc (HWND, UINT, WPARAM, LPARAM)
 
int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpszCmdLine, int nCmdShow)
 

Variables

static WNDPROC SavedWndProcW
 
static WNDPROC SavedWndProcA
 

Function Documentation

◆ AnsiSubclassProc()

LRESULT CALLBACK AnsiSubclassProc ( HWND  hWnd,
UINT  msg,
WPARAM  wParam,
LPARAM  lParam 
)

Definition at line 155 of file subclass.c.

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
WPARAM wParam
Definition: combotst.c:138
LPARAM lParam
Definition: combotst.c:139
#define printf
Definition: freeldr.h:93
static WNDPROC SavedWndProcA
Definition: subclass.c:9
LONG_PTR LRESULT
Definition: windef.h:209
#define WM_GETTEXT
Definition: winuser.h:1618
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

Referenced by WinMain().

◆ UnicodeSubclassProc()

LRESULT CALLBACK UnicodeSubclassProc ( HWND  hWnd,
UINT  msg,
WPARAM  wParam,
LPARAM  lParam 
)

Definition at line 136 of file subclass.c.

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}
static WNDPROC SavedWndProcW
Definition: subclass.c:8
LRESULT WINAPI CallWindowProcW(_In_ WNDPROC, _In_ HWND, _In_ UINT, _In_ WPARAM, _In_ LPARAM)
WCHAR * LPWSTR
Definition: xmlstorage.h:184

Referenced by WinMain().

◆ UnicodeWndProc()

LRESULT CALLBACK UnicodeWndProc ( HWND  hWnd,
UINT  msg,
WPARAM  wParam,
LPARAM  lParam 
)

Definition at line 117 of file subclass.c.

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}
LRESULT WINAPI DefWindowProcW(_In_ HWND, _In_ UINT, _In_ WPARAM, _In_ LPARAM)

Referenced by WinMain().

◆ WinMain()

int WINAPI WinMain ( HINSTANCE  hInstance,
HINSTANCE  hPrevInstance,
LPSTR  lpszCmdLine,
int  nCmdShow 
)

Definition at line 12 of file subclass.c.

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}
HINSTANCE hInstance
Definition: charmap.c:19
#define NULL
Definition: types.h:112
#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
#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
LRESULT WINAPI AnsiSubclassProc(HWND, UINT, WPARAM, LPARAM)
Definition: subclass.c:155
LRESULT WINAPI UnicodeWndProc(HWND, UINT, WPARAM, LPARAM)
Definition: subclass.c:117
LRESULT WINAPI UnicodeSubclassProc(HWND, UINT, WPARAM, LPARAM)
Definition: subclass.c:136
#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
#define SetWindowLongPtrA
Definition: winuser.h:5345
#define GetWindowLongPtrW
Definition: winuser.h:4829
#define CreateWindowA(a, b, c, d, e, f, g, h, i, j, k)
Definition: winuser.h:4315
ATOM WINAPI RegisterClassW(_In_ CONST WNDCLASSW *)
#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
BOOL WINAPI DestroyWindow(_In_ HWND)
__wchar_t WCHAR
Definition: xmlstorage.h:180

Variable Documentation

◆ SavedWndProcA

WNDPROC SavedWndProcA
static

Definition at line 9 of file subclass.c.

Referenced by AnsiSubclassProc(), and WinMain().

◆ SavedWndProcW

WNDPROC SavedWndProcW
static

Definition at line 8 of file subclass.c.

Referenced by UnicodeSubclassProc(), and WinMain().