Nowadays, most of them support file drag function, especially some software related software, such as: Super Solita, WinRar, etc. How do they implement file drag function, to solve this problem is the best way That is to study someone else's software, look at how it is implemented, so I took the Dumpbin tool to check the WinRar's import table, the result is as follows:
D: / program files / winrar> dumpbin / imports WinRar.exe
Shell32.dll
4D8764 Import Address Table
4D871c import name table
0 Time Date Stamp
0 Index of First Forwarder Reference
0 Dragacceptfiles
0 Dragfinish
0 DragQueryfilea
0 DragQueryFilew
......
Of course, WinRAR's Import Table is far more than this. According to my statistics, it uses 363 functions provided by 8 DLLs. It is probably known by the name of the function to know the document drag function by shell.dll's four Drag The function of the beginning is provided, you can also check MSDN to verify. Since these four functions provide a file's dragon, let's take a look at these functions, and their statements are as follows (information from MSDN):
Void Dragacceptfiles (HWND HWND, BOOL FACCEPT);
Uint Dragqueryfile (HDrop HDROP, UINT IFILE, LPTSTSTSTSZFILE, UINT CCH);
Bool DragQueryPoint (HDROP HDROP, LPPOINT LPPT);
Void Dragfinish (HDROP HDROP);
If the application wants to implement the file's drag, it should perform the following steps:
1. Call the DragAcceptFiles function, incompose the window handle HWHD, and FACCEPT as true parameters, so that the HWHD window enters the status of acceptable files.
2. After calling the DragAcceptFiles function, the application receives the WM_DropFiles message, which can be used to obtain the handle of the data drag window, which can be used to obtain the DragQuery series function to obtain information of the drag file, such as the file name, file fall Dist-coordinate, if the necessary function is completed, you can call the Dragfinish function to end the drag operation of the file.
3. Finally, you should also give the HWHD window to exit the status of the file drag.
With the above steps, the file's drag function becomes more simple, the following is a sample program that supports file drag features, its function is to display the file name and path of the file that dragged over, it is used with Borland C Builder Written, part of the code is as follows:
Activate and cancel the code of the file drag:
Void __fastcall tform1 :: formcreate (TOBJECT * SENDER)
{
DragacceptFiles (Handle, True); // Enter the status of the file drag
}
/ / -------------------------------------------------------------------------------------------- ---------------------------
Void __fastcall tform1 :: formclose (Tobject * Sender, Tclosection & Action)
{
DragacceptFiles (Handle, False); // Exit the status of the file drag
}
Processing the code of WM_Dropfiles:
Void __fastcall tform1 :: dropfiles (twmdropfiles & msg)
{
// Number of drag file INT num = DragQueryFile (HDROP) msg.drop, 0xfffffff, null, 0);
StaticText2-> CAPTION = "file number:" ANSISTRING (NUM);
// put the file name and path to the drag into the list box
Listbox1-> items-> clear ();
For (int i = 0; i Char buffer [256]; DragQueryFile ((HDROP) msg.drop, i, buffer, sizeof (buffer); Listbox1-> items-> add (buffer); } // End file drag operation Dragfinish ((HDROP) msg.drop); } Code associated with the function of the message to process the message: Begin_MESSAGE_MAP VCL_MESSAGE_HANDLER (WM_Dropfiles, Twmdropfiles, Dropfiles); END_MESSAGE_MAP (TFORM); Begin_MESSAGE_MAP, VCL_MESSAGE_HANDLER, END_MESSAGE_MAP is three to macros for implementing message and processing message functions Ok, the trailer of the file is introduced here. If you are interested in this program, you can download the project file from http://www.zccfamily.com/zqget/ URL. If you have an idea with me, my contact information: email: zqget@msn.com