Handling Input Language Change Message

From RAD Studio
Jump to: navigation, search

Go Up to Using the Windows API Messaging Solution


The Windows message WM_INPUTLANGCHANGE is sent by default to the control (window) that currently has the focus when the input language is changed. There are times when all the controls on a form need to be aware of the input language change, and not only the one with the focus. One example of such situation is when one or multiple virtual keyboards (TTouchKeyboard) are present on the form.

To avoid this issue, the custom message CM_INPUTLANGCHANGE was created and added to VCL. In addition to this message, the following actions happen in this order:

  1. The user changes the language.
  2. All TWinControl descendants listen for WM_INPUTLANGCHANGE.
  3. WM_INPUTLANGCHANGE is sent to the active control.
  4. If Application is not nil, then TWinControl sends the custom message CM_INPUTLANGCHANGE, with the same WParam and LParam, to TApplication. TApplication or the root TWinControl listens for CM_INPUTLANGCHANGE and then broadcasts the message to all children TWinControls.
  5. If Application is nil, then the root TWinControl sends the custom message CM_INPUTLANGCHANGE with the same WParam and LParam that were passed in.
  6. TApplication or the root TWinControl listens for CM_INPUTLANGCHANGE and then broadcasts the message to all children TWinControls.

To write a custom handler for the CM_INPUTLANGCHANGE event, you should declare a message method in your control:

procedure CMInputLangChange(var Message: TMessage); message CM_INPUTLANGCHANGE;