Moving a dialog by clicking on it

How can I move a dialog box by clicking every where on it and not only the caption ?
mike_marquetAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

akalmaniCommented:
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
mike_marquetAuthor Commented:
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
migelCommented:
Hi!
There is little simple way:

override WM_NCHITTEST message:

UINT CAboutDlg::OnNcHitTest(CPoint point)
{
return HTCAPTION; //CDialog::OnNcHitTest(point);
}
0
Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

mike_marquetAuthor Commented:
Thanks to migel, it works fine.
0
mike_marquetAuthor Commented:
Is it possible to do this also for a form view in a MDI application ?
0
migelCommented:
It is possible but requie more work and it is another question :-)
0
ZoppoCommented:
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
migelCommented:
It is possible but requie more work and it is another question :-)
0
mike_marquetAuthor Commented:
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
ZoppoCommented:
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
migelCommented:
It is possible but requie more work and it is another question :-)
0
cyberbumCommented:
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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
ZoppoCommented:
Even the same problem, has to be

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

ZOPPO
0
mike_marquetAuthor Commented:
Thanks to cyberbum for the idea but you must use GetParent before posting the message. Sea comment from Zoppo.
0
mike_marquetAuthor Commented:
The idea from Zoppo also works :

GetParent()->PostMessage(WM_NCLBUTTONDOWN, HTCAPTION,
 MAKELPARAM(point.x, point.y));
0
ZoppoCommented:
Therefore I locked your other question :))
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
System Programming

From novice to tech pro — start learning today.