Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

How to move a window w/o caption bar?

Posted on 1997-08-21
6
Medium Priority
?
238 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 

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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

Introduction: Load and Save to file, Document-View interaction inside the SDI. Continuing from the second article about sudoku.   Open the project in visual studio. From the class view select CSudokuDoc and double click to open the header …
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
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.
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…

715 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