A strange Windows message
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:
case WM_LBUTTONDOWN: ReleaseCapture(); SendMessage(hWnd, WM_SYSCOMMAND, 61458, 0); break;
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.
Perhaps you should have checked the docks for WM_SYSCOMMAND? Seems to talk about AND’ing the wParam value
The behavior difference you are seeing is to specifiy if the keyboard or mouse is generating the move event.
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winui/winui/windowsuserinterface/userinput/keyboardaccelerators/keyboardacceleratorreference/keyboardacceleratormessages/wm_syscommand.asp
Thank you very much! I didn’t use the current online version of the documentation, but the old one that shipped with Delphi, that’s why I didn’t read the "AND 0xFFF0" part. However, the meaning of the lower 4 bits remains unclear, as they "are used internally by the system". But your explanation sounds reasonable — the mouse cursor jumping to the center of the title bar is indeed the typical action of a keyboard-controlled move …
Wow, it helps me a lot. The misterious message is SC_MOVE + HTCAPTION anyway.