Click here to Skip to main content
13,147,183 members (29,131 online)
Click here to Skip to main content
Add your own
alternative version


45 bookmarked
Posted 17 Nov 2003

Drag and Drop in a Dialog

, 6 Dec 2012
Rate this:
Please Sign up or sign in to vote.
Simple Drag and Drop functionality in a dialog.


Here is a simple method to have a Drag and Drop feature in your dialog based applications. To provide Drag and Drop we have a Windows Message Handler called WM_DROPFILES. Handle this message through the ON_MESSAGE message map to capture the dropped files.

Message Handler

 BEGIN_MESSAGE_MAP(CComGuidFinderDlg, CDialog)
  ON_MESSAGE(WM_DROPFILES,OnDropFiles)// Message Handler for Drang and Drop

Now it is time to handle the WM_DROPFILES messages through a user defined method. The function prototype should be like this:

LRESULT  OnDropFiles(WPARAM wParam,LPARAM lParam);

Finally we have a function to capture the drop events. wParam is a handle to the HDROP structure describing the dropped files. To get info about the dropped file, i.e., the file name used:

DragQueryFile(hDrop,    // Struture Identifier
        -1,        // -1 to Drop more than one file or ( integer 0 to max )
                   // to drop selected No of files
        szDroppedFile,// Droped File Name
        MAX_PATH);   // Max char

So now we have done all possible coding in our dialog based application to handle the Drag & Drop feature. But still it is handicapped. Handling the Drop event is not enough to ensure the Drag & Drop feature. We need to register our window to accept the dropped file using:

BOOL CComGuidFinderDlg::OnInitDialog()
  DragAcceptFiles(TRUE) // To Accept Dropped file Set this TRUE

Good... That's all, and we have done well!

I added one more feature in this sample, i.e., moving our dialog by clicking on anywhere on the window. This can be done by posting the WM_NCLBUTTONDOWN message to HTCAPTION handle this statement in OnLButtonDownMessage(...) .



This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Technical Lead
United States United States
a hard core developer

You may also be interested in...

Comments and Discussions

GeneralRe: DragAcceptFile Pin
jibesh6-Dec-12 11:03
memberjibesh6-Dec-12 11:03 
GeneralSolution: How to move your dialog by clicking on anywhere on the window in a Win32 API Non MFC App Pin
cffhgfdf22-Sep-06 1:34
membercffhgfdf22-Sep-06 1:34 
Generalsimple, good, usable Pin
MessnerEW11-Oct-04 20:21
memberMessnerEW11-Oct-04 20:21 
GeneralI really like the simplicity Pin
hockeyman13-Sep-04 8:26
memberhockeyman13-Sep-04 8:26 
GeneralRe: I really like the simplicity Pin
hockeyman13-Sep-04 8:31
memberhockeyman13-Sep-04 8:31 
Generalgood job Pin
shaitan18@yahoo.com18-Feb-04 10:32
membershaitan18@yahoo.com18-Feb-04 10:32 
QuestionWhom this article is targeted? Pin
super18-Nov-03 20:14
membersuper18-Nov-03 20:14 
AnswerRe: Whom this article is targeted? Pin
jibesh18-Nov-03 20:35
memberjibesh18-Nov-03 20:35 
GeneralRe: Whom this article is targeted? Pin
armentage19-Nov-03 3:50
memberarmentage19-Nov-03 3:50 
GeneralRe: Whom this article is targeted? Pin
jibesh19-Nov-03 4:20
memberjibesh19-Nov-03 4:20 
QuestionHow the rating is found? Pin
kezhu18-Nov-03 12:18
memberkezhu18-Nov-03 12:18 
AnswerRe: How the rating is found? Pin
Alex Farber19-Nov-03 6:44
memberAlex Farber19-Nov-03 6:44 
GeneralMissing File. Pin
WREY17-Nov-03 20:22
memberWREY17-Nov-03 20:22 
GeneralRe: Missing File. Pin
jibesh17-Nov-03 20:34
memberjibesh17-Nov-03 20:34 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.170915.1 | Last Updated 6 Dec 2012
Article Copyright 2003 by Jibesh
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid