Solved

How to move a window w/o caption bar?

Posted on 1997-08-21
6
229 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

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 80 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
mixString challenge 36 112
maxBlock challenge 30 112
ASP.NET C# MessageBox.Show Showing a modal dialog box or form when the application ... 2 104
unix example issues 18 75
Introduction: Database storage, where is the exe actually on the disc? Playing a game selected randomly (how to generate random numbers).  Error trapping with try..catch to help the code run even if something goes wrong. Continuing from the seve…
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.
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.

895 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now