Solved

How to move a window w/o caption bar?

Posted on 1997-08-21
6
227 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
Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 

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

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

This is to be the first in a series of articles demonstrating the development of a complete windows based application using the MFC classes.  I’ll try to keep each article focused on one (or a couple) of the tasks that one may meet.   Introductio…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
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 video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

743 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

12 Experts available now in Live!

Get 1:1 Help Now