A strange Windows message

(February 18, 2006)

It is widely known that large parts of the Windows API are undocumented. However, although I’m a occasional Windows programmer, I didn’t come across such a mysterious spot until today. The source of confusion is the common explanation of how to make a window moveable by clicking into it anywhere (not just the title bar). The code basically looks like this:

  SendMessage(hWnd, WM_SYSCOMMAND, 61458, 0);

I don’t get the basic principle of how this code works, but that’s not the problem here. What really caught my attention is that numerical constant that seems to be documented nowhere.

The WM_SYSCOMMAND sub-message family contains window messages like minimize, maximize or restore. The message with the closest value is SC_MOVE, which is 61456 or 0xF010. The relationship to SC_MOVE makes sense, because moving the window is what the code is all about. But why doesn’t this off-by-2 message have a real name? I found no direct definition of this constant on either my hard disk or Google.

My last hope was WINE. If there is some information on Windows’ undocumented APIs anywhere on this planet, it’s either in Redmond or in WINE’s source code. Some research using WINE’s nice online CVS browser revealed that it simply ignores the lower 4 bits of WM_SYSCOMMAND sub-message IDs. Thus, the spooky message would be mapped into SC_MOVE, which in turn means that these two must be really closely related.

Time for some experimentation, I thought. I exchanged the 61458 with SC_MOVE and voilĂ , moving the window still worked — almost. The only visible difference was that Windows moved the mouse cursor into the middle of the title bar when dragging. Trying 61457 (SC_MOVE+1) seemed to behave exactly as the magical message, but who knows what’s going on behind the curtains … Eventually, I’ll use SC_MOVE+2 in the final code, which is somewhat clear at least. But the true names and semantics of the SC_MOVE+n messages remain mysteries.

3 Responses to »A strange Windows message«

Post a Reply

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>


By submitting the comment, you agree to the terms of the Privacy Policy.