Thread: drag and drop

  1. #1
    depsypher
    Guest

    drag and drop

    I'm trying to find out how to drag and drop files into a Listbox control from outside the application. What I need to do is be able to drag and drop a file or files from the desktop (or file explorer) into my listbox view, and have it create the new item(s) in the list. I just need a shove in the right direction, 'cause MSDN is confusing me more than its helping right now.

  2. #2
    Registered User Chemanuel's Avatar
    Join Date
    Aug 2001
    Posts
    13
    These are the points you have to take into account

    - The DragAcceptFiles function registers whether a window accepts dropped files

    - The WM_DROPFILES message is sent when the user releases the left mouse button while the cursor is in the window of an application that has registered itself as a recipient of dropped files.

    In the windows API documentation you can find examples if you look for these topics.

    This is the function I used to open files. Note that the functions with :: are defined in my program. use your functions instead. Don't forget to include at the beginning of the program
    PHP Code:
     DragAcceptFiles(hWndTRUE); // Prepare the application to accept dragged files


    BOOL Frame::OnDropFiles(HINSTANCE hInstHWND hWndWPARAM wParam)
    {
     
    HDROP hDrop = (HDROP)wParam;
     
    POINT pt;
     
    char szFileName[MAX_PATH]; 

     
    DragQueryPoint(hDrop, &pt);   

     if (
    DragQueryFile(hDrop0xFFFFFFFF00) > 1)  // Accept only 1 dropped file
        
    return Error::ProcessWarning(hWndIDS_DRAGONEFILE);

     
    // If there is a previous experiment close it and open a new one
     
    if (TreeView_GetCount(GetDlgItem(hWndID_TREEVIEW)))
        if (!
    Frame::CloseExperiment(hWnd))
           return 
    FALSE;
     
     
    // Get file name and open it
     
    DragQueryFile(hDrop0szFileNamesizeof(szFileName)); 
     
    Frame::OpenExperiment(hInsthWndszFileName);
     
     
    // Free memory when done
     
    DragFinish(hDrop);

     return 
    FALSE;

    Last edited by Chemanuel; 12-29-2001 at 11:49 AM.
    Chemanuel

    Lo bueno si breve dos veces bueno (Baltasar Gracián 1601-1658)

  3. #3
    depsypher
    Guest

    thanks Chemanuel

    I finally got around to trying this out and it does the trick. thanks

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. [C] Drag and drop controls
    By pc2-brazil in forum Windows Programming
    Replies: 1
    Last Post: 09-02-2008, 02:41 AM
  2. Drag & Drop files into my (and other) apps
    By Mastadex in forum Windows Programming
    Replies: 1
    Last Post: 11-07-2007, 05:59 AM
  3. DataGrid drag and drop
    By gtriarhos in forum C# Programming
    Replies: 0
    Last Post: 10-11-2005, 12:36 PM
  4. Drag and Drop using CImageList, Device contexts and BitBlt
    By MJWhiteman2 in forum Windows Programming
    Replies: 0
    Last Post: 03-03-2005, 07:22 AM
  5. Drag and drop from Internet Explorer
    By Echidna in forum Windows Programming
    Replies: 5
    Last Post: 10-02-2002, 02:14 AM