Non-movable window

Started by
1 comment, last by atjs 21 years, 3 months ago
What''s the window style/setting required to make a window non-movable? (Win32, C++)
Advertisement
I don''t know about a non-removable window, but you can make it stay put by waiting for a WM_MOVE event and then use the MoveWindow function to move it back to place.

The nightmare travels across the cosmos with his burning mane. The trail of ash that is produced.

?Have a nice day!?

To prevent the user from moving the window via the 'Title Bar' you can write the following into your window's 'Window Procedure'...
   switch (message_id)   {      ...      case WM_NCLBUTTONDOWN:      if (HTCAPTION == word_param)      {         return 0;      }      return DefWindowProc (window_handle, message_id, word_param, long_param);      ...   }     

Basically what you're doing is checking to see if the user tries to grab the title bar to move the window, if they do return without the message making it to the window's default processing, else pass it own to the window's default processing. You try to grab the window's title bar, it won't budge(sp?). It won't even flinch so to speak.

Handling the move command of the window's system menu can be handled in a similar fashion, I believe. You'd need to capture the WM_SYSCOMMAND message and look for SC_MOVE in the WPARAM. I haven't tried this one yet but the first method (for the title bar) works perfectly. Anywho, I hope that helps some. Later.

Edit:
Scratch the part about the 'System Menu' move command. You can actually just remove the 'Move' option from your window's system menu all together.

Just remember this when trying to alter a window's default behavour. There's a message that has to pass through YOUR window procedure before it get to the DefWindowProc() to cause the default behavour. And those messages will often spawn other messages and so on. So if you can find the message that causes the behavour you want to change, you can coerce it, maim it, slap it around, or just plain kill it, and, in doing so, bend Windows to your benevolent will.

[edited by - microdot on January 18, 2003 5:13:56 AM]
<span class="smallfont">That is not dead which can eternal lieAnd with strange aeons even death may die.   -- "The Nameless City" - H. P. Lovecraft</span>

This topic is closed to new replies.

Advertisement