Subclassing and Automatic Message Translation

Subclassing is a technique that allows an application to intercept and process messages sent or posted to a particular window before a window procedure has a chance to process them. The operating system automatically translates messages into Windows (ANSI) code page or Unicode form, depending on the form of the function that has subclassed the window procedure.

The following call to the SetWindowLongA function subclasses the current window procedure associated with the window identified by the hWnd parameter. Alternatively, an application can use SetWindowLongPtrA. The new window procedure NewWndProc, will receive messages with text in Windows code page format.

OldWndProc = (WNDPROC) SetWindowLongA(hWnd,
             GWL_WNDPROC, (LONG)NewWndProc); 

When NewWndProc has finished processing a message, it uses the CallWindowProc function as follows to pass the message to OldWndProc.

CallWindowProc(OldWndProc, hWnd, uMessage, wParam, lParam);

If OldWndProc was created with a class style of UNICODE, messages are translated from the Windows code page form received by NewWndProc into Unicode.

Similarly, a call to the SetWindowLongW or SetWindowLongPtrW function subclasses the current window procedure with a window procedure that expects Unicode text messages. Message translation, if necessary, is performed during the processing of the CallWindowProc function.

For more information about subclassing, see Window Procedures.

Related topics

Using Unicode and Character Sets