[Webinar] Streamline your web hosting managementRegister Today

x
?
Solved

Moving a dialog by clicking on it

Posted on 1999-11-04
16
Medium Priority
?
225 Views
Last Modified: 2013-11-20
How can I move a dialog box by clicking every where on it and not only the caption ?
0
Comment
Question by:mike_marquet
  • 6
  • 4
  • 4
  • +2
16 Comments
 
LVL 3

Expert Comment

by:akalmani
ID: 2182802
Hope this helps u ?
I have tried this out in About dialog please try this...
The flag is a variable in about dialog class initially its false
and then made true on left button click and so on...

void CAboutDlg::OnLButtonDown(UINT nFlags, CPoint point)
{
         flag = true;
      
      CDialog::OnLButtonDown(nFlags, point);
}

void CAboutDlg::OnLButtonUp(UINT nFlags, CPoint point)
{
      flag = false;
      
      CDialog::OnLButtonUp(nFlags, point);
}

void CAboutDlg::OnMouseMove(UINT nFlags, CPoint point)
{
      RECT r;
      GetWindowRect(&r);

      if(flag)
         ::MoveWindow(this->m_hWnd,point.x,point.y,r.right                - r.left,r.bottom - r.top,TRUE);      
      
CDialog::OnMouseMove(nFlags, point);
}
0
 

Author Comment

by:mike_marquet
ID: 2182822
I have try this in my about dialog box and it doesn't work.
When I click on the dialog, it move somewhere on the screen
 and the mouse pointer is the outside the box.
0
 
LVL 12

Expert Comment

by:migel
ID: 2182830
Hi!
There is little simple way:

override WM_NCHITTEST message:

UINT CAboutDlg::OnNcHitTest(CPoint point)
{
return HTCAPTION; //CDialog::OnNcHitTest(point);
}
0
[Webinar] Kill tickets & tabs using PowerShell

Are you tired of cycling through the same browser tabs everyday to close the same repetitive tickets? In this webinar JumpCloud will show how you can leverage RESTful APIs to build your own PowerShell modules to kill tickets & tabs using the PowerShell command Invoke-RestMethod.

 

Author Comment

by:mike_marquet
ID: 2182846
Thanks to migel, it works fine.
0
 

Author Comment

by:mike_marquet
ID: 2182864
Is it possible to do this also for a form view in a MDI application ?
0
 
LVL 12

Expert Comment

by:migel
ID: 2182966
It is possible but requie more work and it is another question :-)
0
 
LVL 31

Expert Comment

by:Zoppo
ID: 2182984
hi mike_marquet,

You can try something like this for both dialogs and formviews:

void CNCHit::OnLButtonDown(UINT nFlags, CPoint point)
{
 CDialog::OnLButtonDown(nFlags, point); // or CFormView::OnLB...
 // fake windows into thinking your clicking on the caption, BUT does not
 // maximize on double click
 PostMessage( WM_NCLBUTTONDOWN, HTCAPTION, MAKELPARAM( point.x, point.y));
}

hope that helps,

ZOPPO
0
 
LVL 12

Expert Comment

by:migel
ID: 2183003
It is possible but requie more work and it is another question :-)
0
 

Author Comment

by:mike_marquet
ID: 2183125
To Zoppo,

It doesn't work. The form is moved but not the frame attached to it. It's the same when using OnNcHitTest which return HTCAPTION.
0
 
LVL 31

Expert Comment

by:Zoppo
ID: 2183135
For MDI child windows I think it should work with

GetParent()->PostMessage( WM_NCLBUTTONDOWN, HTCAPTION, MAKELPARAM(point.x, point.y));

hope that helps,

ZOPPO
0
 
LVL 12

Expert Comment

by:migel
ID: 2183142
It is possible but requie more work and it is another question :-)
0
 
LVL 1

Accepted Solution

by:
cyberbum earned 60 total points
ID: 2183212
Super simple way to do it:

In your OnLButtonDown handler, put this line of code in:
PostMessage(WM_SYSCOMMAND, SC_MOVE+2, 0);

Bingo, all done.
0
 
LVL 31

Expert Comment

by:Zoppo
ID: 2183235
Even the same problem, has to be

GetParent()->PostMessage(WM_SYSCOMMAND, SC_MOVE+2, 0);

ZOPPO
0
 

Author Comment

by:mike_marquet
ID: 2183279
Thanks to cyberbum for the idea but you must use GetParent before posting the message. Sea comment from Zoppo.
0
 

Author Comment

by:mike_marquet
ID: 2183290
The idea from Zoppo also works :

GetParent()->PostMessage(WM_NCLBUTTONDOWN, HTCAPTION,
 MAKELPARAM(point.x, point.y));
0
 
LVL 31

Expert Comment

by:Zoppo
ID: 2183359
Therefore I locked your other question :))
0

Featured Post

The 14th Annual Expert Award Winners

The results are in! Meet the top members of our 2017 Expert Awards. Congratulations to all who qualified!

Question has a verified solution.

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

Introduction: The undo support, implementing a stack. Continuing from the eigth article about sudoku.   We need a mechanism to keep track of the digits entered so as to implement an undo mechanism.  This should be a ‘Last In First Out’ collec…
Introduction: Dialogs (1) modal - maintaining the database. Continuing from the ninth article about sudoku.   You might have heard of modal and modeless dialogs.  Here with this Sudoku application will we use one of each type: a modal dialog …
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.
How to fix display issue, screen flickering issue when I plug in power cord to the machine. Before I start explaining the solution lets check out once the issue how it looks like after I connect the power cord. most of you also have faced this…
Suggested Courses

590 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