Window message parameters do not come with metaphysical certitude

Raymond Chen

The MSDN documentation for window messages describes what each of the parameters means, but just because it means something doesn’t mean that it is that something; it merely means it. But you knew this already. If you have a window handle, you can send it whatever message you like, with whatever parameters you like, even if those parameters contradict reality. For example, you could write some code that seeks out a target window and sends it a WM_COMMAND with parameters that claim that the message was generated from a keyboard accelerator, when in fact it was generated by code contained within your custom control. But you send the message with the accelerator parameters because your goal is to fool the target program into thinking that it came from a keyboard accelerator. Similarly, if your control wants to simulate a menu click, you should package the parameters in the same way a menu delivers them. There are some people, however, who have difficulty wrapping their brains around this concept, that if you are trying to simulate something, then you have to behave as the thing you are trying to simulate and not as your actual self. If the documentation says that “A control sends the message with these parameters” and you’re a control but you want to pretend that you’re a menu, then you need to send the message the way a menu would. That’s why it’s called pretending.

Message parameter documentation is written on the assumption that nobody is pretending anything. What other choice is there? There’s no point discussing the possibility that the sender of the message is playing tricks and lying to you because (1) your program should just go along with the ruse and respond to fake menu messages as if they were real menu messages, because (2) there’s no way to tell that you’re being lied to anyway. To detect lying, you’d have to be able to read into the mindset of the programmer who sent you the message. “Gosh, this code is generating a message and claiming that it was triggered by a menu selection. Is the code is implementing a menu-like window, or is it just trying to trick me?”

0 comments

Discussion is closed.

Feedback usabilla icon