What does it mean for a control to be Unicode or ANSI?

325 views Asked by At

Windows controls can be Unicode or ANSI, my question is what does it mean for a control to be in one of these two categories?

Is it the following (if I assume that the control is Unicode):

  • The buffer for the control is in Unicode.
  • WM_CHAR messages are sent as Unicode (e.g. 'A' is sent as 0x0041 and not as 0x41).
1

There are 1 answers

2
tenfour On BEST ANSWER

It means the window messages sent to the window procedure will be the ANSI or Unicode versions. For example a Unicode window will receive a CREATESTRUCTW in WM_CREATE, while the ANSI windows will receive a CREATESTRUCTA.

This will apply to almost every window message containing string data.

Windows will internally marshal data accordingly. For example if you call the ANSI SendMessageA(WM_SETTEXT, ...) to a Unicode window, the window will receive WM_SETTEXT with a Unicode string.

A window will be Unicode or ANSI depending on whether its class was registered with RegisterClassExA or RegisterClassExW. You can test if a window is Unicode or not by calling IsWindowUnicode.


Some info about common controls, because that seems to be what you're talking about.

First of all, there is no problem with an ANSI window being the parent of a Unicode window. Also keep in mind that "controls" are just windows.

Common controls are always Unicode. The messages they receive will be in the native, Unicode, format. Of course you won't have visibility to this because it's all internal to the OS (exception: if you subclass a common control).

The messages you are typically dealing with will be sent to your window in the form of WM_COMMAND or WM_NOTIFY. These messages are sent from common controls to their parent window (your window). They will respect your window being Unicode or ANSI like this:

  1. First they will send your window a WM_NOTIFYFORMAT message to ask if you prefer messages to be received in ANSI or Unicode (despite your window being Unicode or ANSI).
  2. If you don't handle WM_NOTIFYFORMAT, then the control will call IsWindowUnicode to determine.
  3. Then the control will send the message accordingly.

So basically, you never need to know if a common control is Unicode or not, because 1) it always is, and 2) this question is only relevant as a matter of handling messages, which is internal to Windows, not your responsibility.

Your responsibility is to handle notifications coming from common controls to your own window. In this case the Unicode/ANSI-ness of your own window is all that matters.