Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

How to move a window w/o caption bar?

Posted on 1997-08-21
6
Medium Priority
?
239 Views
Last Modified: 2013-11-20
Hi:

I have a window without decorations (border and caption bar), only the client area. As a reaction on some user action (say, double click) I want to switch into move window mode. I tried PostMessage( WM_SYSCOMMAND, SC_MOVE, 0 ) and it works: cursor changes and the frame appears, but the window is not moved when I drag it.

I have found that it is by design: even if the window has a caption bar, it can be dragged only by the caption bar (you may try it on any window).

Does anybody how to change this and allow dragging from the client area?

Regards,
Asker.
0
Comment
Question by:asker
  • 3
  • 2
6 Comments
 

Expert Comment

by:Amaresh080997
ID: 1304400
Hi Asker,
   I am sorry that I could not give you a tried working solution.But immediately all that I can think of is: Just try to override "OnMouseMove()" (WM_MOUSEMOVE message) function to get the units by which you have dragged the mouse on the window.Then add this much to the present windows coordinates and then do MoveWindow() or SetWindowPos().I am not sure if this will be satisfactory.There my be a flickering.But you can give it a try.

Bye!
Amaresh
0
 

Author Comment

by:asker
ID: 1304401
I would not want that my window be always dragged as a whole (full drag).
Frankly speaking, I understand that there may be different approaches to implement move mode manually. What I am trying to do is to use the internal Windows possibilities (move mode).
0
 
LVL 15

Expert Comment

by:Tommy Hui
ID: 1304402
Try maintaining a flag that says whether or not the window is in move mode. Then in that window catch the WM_NCHITTEST message. If you're in the move mode, return HT_CAPTION. If not, return the base class behavior:

  CMyWindow::OnNcHitTest(CPoint point)
  {
    if (m_InMoveMode)
      return HT_CAPTION;
    else
      return CWnd::OnNcHitTest(point);
   }

Of course, you will need to turn on m_InMoveMode when the user double clicks (WM_LBUTTONDBLCLK). Also, you will need to catch WM_NCLBUTTONDOWN to turn off m_InMoveMode.
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:asker
ID: 1304403
Hi, Thui:

I initiate the move mode by posting WM_SYSCOMMAND with SC_MOVE. The WM_NCHITTEST message is not sent to the window being moved after I've posted WM_SYSCOMMAND (I checked it with Spy++, you may also check this if you try Spy++ on any window, just select Move item from the system menu).
0
 
LVL 15

Accepted Solution

by:
Tommy Hui earned 320 total points
ID: 1304404
No, don't initiate the move mode by posting WM_SYSCOMMAND. As I mentioned, you need to handle the move mode yourself.

The WM_SYSCOMMAND message is posted to enable the window to go into a modal loop where the tracking of the mouse can occur. However, a keystroke must be hit before the tracking of the mouse can be enabled. So after posting the WM_SYSCOMMAND, try posting a WM_KEYUP and WM_KEYDOWN message immediately after and see what happens.
0
 

Author Comment

by:asker
ID: 1304405
Yes, this sequence lead to the success:

      PostMessage( WM_SYSCOMMAND, SC_MOVE, 0 );
      PostMessage( WM_KEYDOWN, VK_LEFT, 0 );
      PostMessage( WM_KEYUP, VK_LEFT, 0 );
      PostMessage( WM_KEYDOWN, VK_RIGHT, 0 );
      PostMessage( WM_KEYUP, VK_RIGHT, 0 );

Thank you!

0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Here is how to use MFC's automatic Radio Button handling in your dialog boxes and forms.  Beginner programmers usually start with a OnClick handler for each radio button and that's just not the right way to go.  MFC has a very cool system for handli…
Introduction: Dialogs (2) modeless dialog and a worker thread.  Handling data shared between threads.  Recursive functions. Continuing from the tenth article about sudoku.   Last article we worked with a modal dialog to help maintain informat…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Integration Management Part 2

926 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question