September 6th, 2018

What does it mean for a window to be Unicode?

The Is­Window­Unicode function reports whether the current window procedure expects Unicode window messages. What specifically does this mean?

It means that messages like WM_CHAR will report characters as Unicode code units rather than as ANSI code units.

Okay, so what determines whether a window procedure receives Unicode messages?

When a window is created, its initial window procedure comes from the class registration. If the class was registered with Register­Class[Ex]W, then it is a Unicode window procedure; otherwise it was registered with Register­Class[Ex]A and is an ANSI window procedure.

If a window is subclassed with a function pointer, then the new window procedure is Unicode if it was set with Set­Window­Long­PtrW(GWLP_WNDPROC) and ANSI if it was set with Set­Window­Long­PtrA(GWLP_WNDPROC).

As we saw some time ago, Get­Window­Long­Ptr(GWLP_WNDPROC) returns a thunk if you use the ANSI version but the current window procedure is Unicode, or vice versa. Suppose the window procedure is Unicode and you call Get­Window­Long­PtrA(GWLP_WNDPROC). This will return you a thunk, and if you later set that thunk back as the window procedure with Set­Window­Long­PtrA(GWLP_WNDPROC), then the original Unicode window procedure is restored, and the window is a Unicode window again.

Note that calling Set­Window­Long­PtrA(GWLP_WNDPROC) can result in a window procedure that is Unicode.

As a window message travels from one window procedure to another window procedure (via Call­Window­Proc), the character set may flip between Unicode and ANSI. The Is­Window­Unicode function tells you only about the window’s current window procedure.

Topics
Code

Author

Raymond has been involved in the evolution of Windows for more than 30 years. In 2003, he began a Web site known as The Old New Thing which has grown in popularity far beyond his wildest imagination, a development which still gives him the heebie-jeebies. The Web site spawned a book, coincidentally also titled The Old New Thing (Addison Wesley 2007). He occasionally appears on the Windows Dev Docs Twitter account to tell stories which convey no useful information.

0 comments

Discussion are closed.