Intercepting messages inside IsDialogMessage, installing the message filter
4 days ago
- #Message Hooks
- #Dialog Boxes
- #Windows API
- Intercepting ESC in standard dialog message loops can be done using a custom message loop or message filter hooks.
- IsDialogMessage includes an extensibility point via MSGF_DIALOGBOX to hook into message processing.
- A message filter hook can block default processing of ESC before it becomes IDCANCEL.
- The hook procedure checks for ESC key presses and sends a custom message (DM_ESCPRESSED) to the dialog.
- The dialog procedure can decide to process ESC key presses itself by returning TRUE.
- Global variables for dialog handles can be replaced with thread_local to support multiple threads.
- Multiple instances of the same dialog in one thread still pose a challenge.
- Future solutions may involve checking window class names in the hook.