| Header file: | dragdrop.h |
| Object name: | fDRAGANDDROP |
| Object index: | 1 of 1 Object |
It is very useful in today's Drag-and-drop environments to be able to support this funny thing... and it's not that hard to do. However, this class makes it just that much easier by handling most of the hard part for you. All you need to do is to capture the WM_DROPFILES message, or use the OnDropFiles event of a window, and away you go!
Please see the source code at the end to see how to use this component.
| Prototype | Description |
|
void Setup(HWND Handle); void Setup(fFORM* Window); | These functions set up the window specified to be able to accept dropped files, and then remembers the handle for when it needs it later. You must call this before you can intercept a drop. As you can see, you can pass either a HWND or a pointer to a Window. The second type saves you some typing, but then again you can do some neat things with the first one. You could even make a dialog able to support drag-and-drop! |
| void Disable(void); | This function disables the drag and drop capabilities of the previously registered window. |
| void GetFiles(HDROP Drop); | This function actually retrieves the files after the drop has occured. You can call this from a function specified by the OnDropFiles event on a form, or by intercepting the WM_DROPFILES message. If you use the OnDropFiles event, just pass along the HDROP which was passed to that event. If you use the WM_DROPFILES method, then pass along wParam cast to a HDROP (ie. (HDROP)wParam). You will need to call this function with the drop before you are able to do anything else with the dropped files - which means that you can not call any of the following functions until you have got the files with this function. |
| int GetDropPointX(void); | This function returns the X co-ordinate of where the user let go of the mouse button, thereby creating the event. The co-ordinate is relative of the top corner of the window onto which it was dragged. |
| int GetDropPointY(void); | This function is exactly like the above except for the fact that it returns the Y co-ordinate instead. |
| int GetNumberFiles(void); | This function retrieves the number of files that were dropped. |
| char* GetFile(int Index); | This function returns a pointer to one of the files that it got from Windows. Index starts at 0 and finishes at the number of files minus 1. (ie. if there are 5 files, the index is from 0 (Zero) to 4). |
| void Finish(void); | This function tells Windows that you have finished with the drop object. It will then go and wipe the memory associated with the drop. Please note that the object does not forget the files that it retrieved when you call this function, so they are still available after you have called this function. If you want the object to forget the files and release the memory used up by this file list, you will need to call the next function. |
| void CleanUp(void); | This function makes the object clean up it's file list and forget the files. You should call this when you are finished with the file list to recover the memory used with the list. If you do not delete the list, it will be deleted when the object is destroyed (which will ultimately be when you quit the program - but in the meantime, destroying the object as soon as you are done gives some memory back to the program). |
The following snippet gives a basic idea of how to use this component.
//In your initialisation area...
fDRAGANDDROP DragDrop;
//And a prototype for the dropped files event function...
void DroppedFiles(fFORM* Sender, HDROP Drop);
fFORM Window;
Window.Create...
DragDrop.Setup(&Window);
//You can only use this event with the GUI controller...
Window.OnDropFiles(&DroppedFiles);
//Now the function to handle the dropped files...
void DroppedFiles(fFORM* Sender, HDROP Drop)
{
//Get the files from Windows...
DragDrop.GetFiles(Drop);
//Now you can retrieve the files...
for (int Temp = 0; Temp < DragDrop.GetNumberFiles(); Temp++)
{
... = DragDrop.GetFile(Temp);
}
//And so on. When you are finished...
DragDrop.Finish();
DragDrop.CleanUp();
};
//Or, if you don't have the GUI Controller, and want to
//use this object, then in the message queue...
... message queue ...
case WM_DROPFILES:
//Get the files from Windows...
DragDrop.GetFiles((HDROP)wParam);
//Now you can retrieve the files...
for (int Temp = 0; Temp < DragDrop.GetNumberFiles(); Temp++)
{
... = DragDrop.GetFile(Temp);
}
//And so on. When you are finished...
DragDrop.Finish();
DragDrop.CleanUp();
break;
//Or, for technical correctness, return 0
return 0;
... rest of message queue ...
| Back to index | The FreeFoote Foundation Classes Documentation |