Click here to Skip to main content
Licence 
First Posted 17 Nov 2003
Views 65,976
Bookmarked 25 times

Drag and Drop in a Dialog

By | 17 Nov 2003 | Article
Simple Drag and Drop Facility in a Dialog

Introduction

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

Message Handler

//
 BEGIN_MESSAGE_MAP(CComGuidFinderDlg, CDialog)
  //{{AFX_MSG_MAP(CComGuidFinderDlg)
  ON_WM_PAINT()
  ON_WM_LBUTTONDOWN()
  ON_MESSAGE(WM_DROPFILES,OnDropFiles)// Message Handler for Drang and Drop
  //}}AFX_MSG_MAP
END_MESSAGE_MAP()
//

Now its 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. The wParam is a handle to the HDROP structure describing the dropped files. To get the 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 did all possible coding in our dialog based application to handle 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()
  {
    ......
    .....
    DragAcceptFile(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 the our dialog by clicking on anywhere on the window. This can be do by posting WM_NCLBUTTONDOWN message to HTCAPTION Handle this statement in OnLButtonDownMessage(...)

PostMessage(WM_NCLBUTTONDOWN,HTCAPTION,MAKELPARAM(point.x,point.y))

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

About the Author

jibesh

Web Developer

India India

Member

Working as a software Engg in INDIA..


Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page   
  Refresh
QuestionGreat Article PinmemberJosephFox2:38 19 Feb '12  
GeneralMy vote of 5 Pinmember ThatsAlok 21:16 7 Jul '11  
Questionnice article Pinmember ThatsAlok 21:16 7 Jul '11  
GeneralMy vote of 5 PinmemberDemiG18:16 19 Jul '10  
GeneralDragAcceptFile PinmemberGernot Frisch23:06 17 Nov '08  
GeneralSolution: How to move your dialog by clicking on anywhere on the window in a Win32 API Non MFC App Pinmembercffhgfdf1:34 22 Sep '06  
Generalsimple, good, usable PinmemberMessnerEW20:21 11 Oct '04  
GeneralI really like the simplicity Pinmemberhockeyman8:26 13 Sep '04  
GeneralRe: I really like the simplicity Pinmemberhockeyman8:31 13 Sep '04  
Generalgood job Pinmembershaitan18@yahoo.com10:32 18 Feb '04  
QuestionWhom this article is targeted? Pinmembersuper20:14 18 Nov '03  
AnswerRe: Whom this article is targeted? Pinmemberjibesh20:35 18 Nov '03  
GeneralRe: Whom this article is targeted? Pinmemberarmentage3:50 19 Nov '03  
GeneralRe: Whom this article is targeted? Pinmemberjibesh4:20 19 Nov '03  
QuestionHow the rating is found? Pinmemberkezhu12:18 18 Nov '03  
AnswerRe: How the rating is found? PinmemberAlex Farber6:44 19 Nov '03  
GeneralMissing File. PinmemberWREY20:22 17 Nov '03  
GeneralRe: Missing File. Pinmemberjibesh20:34 17 Nov '03  

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    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 | Mobile
Web03 | 2.5.120517.1 | Last Updated 18 Nov 2003
Article Copyright 2003 by jibesh
Everything else Copyright © CodeProject, 1999-2012
Terms of Use
Layout: fixed | fluid