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.
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
DragAcceptFiles(hWnd, TRUE); // Prepare the application to accept dragged files
BOOL Frame::OnDropFiles(HINSTANCE hInst, HWND hWnd, WPARAM wParam)
HDROP hDrop = (HDROP)wParam;
if (DragQueryFile(hDrop, 0xFFFFFFFF, 0, 0) > 1) // Accept only 1 dropped file
return Error::ProcessWarning(hWnd, IDS_DRAGONEFILE);
// If there is a previous experiment close it and open a new one
if (TreeView_GetCount(GetDlgItem(hWnd, ID_TREEVIEW)))
// Get file name and open it
DragQueryFile(hDrop, 0, szFileName, sizeof(szFileName));
Frame::OpenExperiment(hInst, hWnd, szFileName);
// Free memory when done
I finally got around to trying this out and it does the trick. thanks