ENABLING Drag-and-Drop without OLE

Environment: ASP .NET, ASP -->

The drag-and-drop can be obtained in two ways; the first is OLE and the second is using the MFC. MFC supports the functionality of drag-and-drop without using OLE. To enable drag-and-drop in your application, you'll have to perform the following tasks:

  • The CWnd::DragAcceptFiles () enables you to accept the drag-and-drop functionality for your application. The only parameter to the function is of the BOOL type and which, by default, is set to FALSE to disable the drag-and-drop functionality. Setting it to TRUE will enable your application to handle WM_DROPFILES message for the CWND class.
  • The DragAcceptFiles function can be called of any CWnd derived class; handling the WM_DROPFILES will enable your application for drag-and-drop.

The steps involved are the following (I'm writing the code segment for an SDI application):

  1. Go in the CMainFrame::OnCreate function of your SDI application and make a call to DragAcceptFiles:
  2. int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct){
      // MFC code goes here
    
      DragAcceptFile(true)    // call the Drag Accept files
      // rest of MFC code generated by ClassWizard
    }
    

    You must keep in mind that you must call this function after the CWnd object has been created.

  3. Map the WM_DROPFILES message for your CMainFrame class and modify the code like the following:
  4. void CMainFrame::OnDropFiles(HDROP hDropInfo)
    {
    UINT i = 0;
    UINT nFiles = ::DragQueryFile(hDropInfo, (UINT) -1, NULL, 0);
    for (i = 0; i < nFiles; i++)
    {
        TCHAR szFileName[_MAX_PATH];
        ::DragQueryFile(hDropInfo, i, szFileName, _MAX_PATH);
    
        ProcessMyFile(szFileName);
    
    }
    
      ::DragFinish(hDropInfo);
      CFrameWnd::OnDropFiles(hDropInfo);
    }
    

    The first call to DragQueryFile will return you the total number of files dropped at your application. Each next call, the DragQueryFiles will return the name of the file to you in the szFileName parameter.

    After that, you have the name of the file. You can process it any way you like.

  5. The next important thing is to call the DragFinish function; otherwise, your application will leak a little bit of memory every time some drag-and-drop operation is made.

Written by:

Danish Qamar is a student of Computer Sciences in Lahore, Pakistan. He's been developing Web applications for three years and started working with Visual C++ in February, 2002. Other interests includes playing games, messing up 3d models integration in OpenGL, and is a badminton freak. He can be reached at:

sahil_2@hotmail.com or chicken_in_the_kitchen@yahoo.com



Comments

  • This kept causing an Access Violation until

    Posted by muscicapa on 10/27/2006 06:06am

    An extra parameter was added to make the signature look like long OnDropFiles(HDROP, long)

    Reply
  • Thanks for the useful article !!

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

    Originally posted by: weeds

    Ignore the folks who complain.

    Reply
  • It's funny. I can't shift <<60 It was helpful.

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

    Originally posted by: Jin

    thanks

    Reply
  • Ha ha. IQ = 30?

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

    Originally posted by: anon

    Whoever posted the 30 IQ must be a moron because that isn't enough to sustain life! ha ha! and you think YOU are so smart!

    Reply
  • This is exactly the code given in jeff prosise book for MFC programming.

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

    Originally posted by: Digvijay

    This is exactly the code given in jeff prosise book for MFC programming.And one should not be using other's code for the purpose of mere fame.
    
    

    If you're original come up with something innovative yourself and you'll be honoured for that.

    To misrepresentation of the origin of code is the most shameful thing any real programmer would ever commit.

    tell me how would you fell like if somebody takes your code and declare it his own creation. }:-0

    Hope you post something original next time.

    regards,

    Digvijay

    Reply
  • if (Paul's Comment == IQ << 30) then (Paul's IQ <= 30)

    Posted by Legacy on 05/27/2003 12:00am

    Originally posted by: S Martarse

    Paul, I wondered if you could validate your previous comments for us all.
    You commented earlier that a persons IQ was "<< 30".
    Now I am guessing that you meant to say that the persons IQ was less then 30, if so you should have written "IQ < 30", but never mind its an easy mistake for a newbie to make.
    However, if of course you were using a bitwise left shift operator or even overloading the << operator in some clever algorithm that I have not understood, then I stand corrected.
    Yours,
    S. Martarse

    Reply
  • I think the info is helpful

    Posted by Legacy on 05/23/2003 12:00am

    Originally posted by: Karl

    I think what you wrote is helpful. I'm always interested in anything I haven't used before. Yea it's simple, but that's what makes it useful and worth posting. I find it strange that other coders would post negative comments without adding anything constructive.

    Reply
  • if u've worked for 3 yrs, and told us about this stuff in WM_DROPFILES , yr IQ must be <<60

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

    Originally posted by: Paul

    useless stuff, man

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

Top White Papers and Webcasts

  • Live Event Date: November 20, 2014 @ 2:00 p.m. ET / 11:00 a.m. PT Are you wanting to target two or more platforms such as iOS, Android, and/or Windows? You are not alone. 90% of enterprises today are targeting two or more platforms. Attend this eSeminar to discover how mobile app developers can rely on one IDE to create applications across platforms and approaches (web, native, and/or hybrid), saving time, money, and effort and introducing apps to market faster. You'll learn the trade-offs for gaining long …

  • 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 …

Most Popular Programming Stories

More for Developers

Latest Developer Headlines

RSS Feeds