I've written a DialogClass which supports Drag & Drop.
First I will describe how you can add the Drag&Drop behaviour to an existing
dialog - That's really simple
Copy the DragDialog.h and DragDialog.cpp to your project directory.
For example, the name of my dialog class is
CTestDragDlg. Include DragDialog.h in your StdAfx.h or in the .h and .cpp file of your dialog.
Open the header file of your dialog and search for a line looking like this:
class CTestDragDlg : public CDialog
, it should then look like this:
class CTestDragDlg : public CDragDialog
Now open the .cpp file of your dialog and search for a line looking like this:
CTestDragDlg::CTestDragDlg(CWnd* pParent )
: CDialog(CTestDragDlg::IDD, pParent)
Now search the code for something look like this:
Now try to compile it!
If you get any errors with a precompiled header, go to the project options and
say that you won't use precompiled headers.
Congratulations, you have now a Drag&Drop Dialog!
Now you can change the drag behaviour of your DragDialog, here are some examples.
Normally the dialog can be dragged with the left mouse button, if you want to use
the right mouse button, call
SetDragButtons(FALSE, TRUE); Now the right
mouse button can drag the dialog around.
SetDragButtons(TRUE, FALSE); and the left mouse button is activated for dragging.
If the user shouldn't be allowed to drag the dialog out of sight (out of the visible screen).
If you want to get the dialog back on screen, cause user dragged it out or something like this, simply call
Are you bored of the standard mouse cursor while dragging? No problem, simply call
You must replace IDC_CURSOR_DRAG with the ID of your mouse cursor. And now, if you're scared of the new cursor, call
Here is a cool effect, if you want to have a 'look-through' effect on your dialog while dragging, call
the value, in this case 100, will regulate how much other windows shine through.
If the value is 0 the dialog is completely invisible, if it is 255 or the parameter NOFADE the dialog will be painted normal while dragging.
Have a lot of fun with it!