Dragging a dialog by clicking anywhere on it

This is how you create a dialog that can be dragged by clicking anywhere on it, ie. not just the caption bar.
void CNCHitDlg::OnLButtonDown(UINT nFlags, CPoint point) 
{
	CDialog::OnLButtonDown(nFlags, point); 
	// fake windows into thinking your clicking on the caption, does not
	// maximize on double click
	PostMessage( WM_NCLBUTTONDOWN, HTCAPTION, MAKELPARAM( point.x, point.y));
} 
or
UINT CNCHitDlg::OnNcHitTest(CPoint point) 
{
	UINT nHitTest = CDialog::OnNcHitTest( point );
	// also fake windows out, but this maximizes the window when you double
	// click on it. 
	return (nHitTest == HTCLIENT) ? HTCAPTION : nHitTest;
}



Comments

  • it works excellent except clicked on menu area!

    Posted by showhigh on 01/06/2006 07:13am

    how to solve it?

    Reply
  • Elegant Simplicity!

    Posted by jgazin on 05/21/2004 06:41pm

    I was about to do this the brute force way using "LButtonDown", "LButtonUp" and "MouseMove" with a whole bunch of code. 
    I'm glad I checked CodeGuru first!
    Thanks!!!

    Reply
  • How to drag a dialog playing movie on it.?

    Posted by Legacy on 08/21/2003 12:00am

    Originally posted by: Nick

    Hi there.,

    How to drag a dialog playing movie on it (on a picture control) by grabbing anywhere .?


    Thanks .!

    Best Regards,
    Nick.

    Reply
  • Win32 only ? (no class, no MFC) Click here...

    Posted by Legacy on 06/11/2003 12:00am

    Originally posted by: maya75

    First thank for your tip.
    
    

    To do it with Win32 only, in your dialog CALLBACK function :

    case WM_LBUTTONDOWN:
    {
    int xPos = LOWORD(lParam); // horizontal position of cursor
    int yPos = HIWORD(lParam); // vertical position of cursor
    // Drag window by clicking anywhere on it
    PostMessage(dialog_handle, WM_NCLBUTTONDOWN, HTCAPTION, MAKELPARAM( xPos, yPos));
    break;
    }

    Reply
  • great

    Posted by Legacy on 04/03/2003 12:00am

    Originally posted by: beinerror

    thank you very much for this!!

    Reply
  • How can I do that with CFrameWnd

    Posted by Legacy on 02/02/2002 12:00am

    Originally posted by: Gandalf

    How can I do the same thing but catching the view in application with CFrameWnd as main window. When I try to use both methods you've mentioned I can only move the view inside the frame, not the frame.

    Reply
  • DOESNT WORK AT ALL!!!

    Posted by Legacy on 12/13/2001 12:00am

    Originally posted by: Boogly POO

    I tried both methods and no luck for me. I even tried again by starting a brand new mfc dialog app with nothing in the dialog box, and it still didnt work.

    HELP!!!

    Reply
  • But it cannot work in WinCE!

    Posted by Legacy on 12/10/2001 12:00am

    Originally posted by: jiajia

    But it cannot work in WinCE.

    MFC for Windows CE does not support the following method of the CWnd class:

    OnNcHitTest

    Reply
  • Moving dialog with button

    Posted by Legacy on 12/07/2001 12:00am

    Originally posted by: Neal

    Hi,
    
    

    I have a dialog with a button placed on it, how would I move the dialog by holding the mouse down over the button and dragging.

    I have tride lots of different things but have had no success.

    Any help would so cool.

    Reply
  • Another solution for ATL

    Posted by Legacy on 11/01/2001 12:00am

    Originally posted by: Nikolay Yankov

    I use previous solution (of Jens Rahm) to drag dynamically added ActiveX controls in client area of ATL Composite Control.
    
    The code is:

    LRESULT CStoreRow::OnMouseMove(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
    {
    if(m_iLButtonDown)
    {
    ::ReleaseCapture();
    HWND hWndParent = GetParent();
    ::SendMessage(hWndParent, WM_NCLBUTTONDOWN, HTCAPTION, 0);

    }

    return 0;
    }


    Thank you Jens Rahm

    Reply
  • Loading, Please Wait ...

Leave a Comment
  • Your email address will not be published. All fields are required.

Top White Papers and Webcasts

  • Live Event Date: October 29, 2014 @ 11:00 a.m. ET / 8:00 a.m. PT Are you interested in building a cognitive application using the power of IBM Watson? Need a platform that provides speed and ease for rapidly deploying this application? Join Chris Madison, Watson Solution Architect, as he walks through the process of building a Watson powered application on IBM Bluemix. Chris will talk about the new Watson Services just released on IBM bluemix, but more importantly he will do a step by step cognitive …

  • Agile methodologies give development and test teams the ability to build software at a faster rate than ever before. Combining DevOps with hybrid cloud architectures give teams not just the principles, but also the technology necessary to achieve their goals. By combining hybrid cloud and DevOps: IT departments maintain control, visibility, and security Dev/test teams remain agile and collaborative Organizational barriers are broken down Innovation and automation can thrive Download this white paper to …

Most Popular Programming Stories

More for Developers

Latest Developer Headlines

RSS Feeds