With the help of API functions Callwindowproc,dragacceptfiles,dragqueryfile,dragfinish can also implement drag-and-drop files from the Explorer explore to the application, another way is to use OLE drag and drop, You can refer to the interesting programming section of the relevant content. Let's take a look at the process of program writing.
For each API function that needs to be referenced, we need to state in the program that if it is declared and used only within a certain window, it is declared as private, and if it is declared in a module and needs to be used throughout the project, it must be declared as public.
Public Declare Function callwindowproc& Lib "user32" Alias "Callwindowproca" (ByVal lpprevwndfunc&, ByVal hwnd&am p;, ByVal Msg&, ByVal Wparam&, ByVal lparam&) Public Declare Sub dragacceptfiles Lib "Shell32.dll" (ByVal hwnd&, ByVal faccept&) Public Declare Function dragqueryfile& Lib "Shell32.dll" Alias "Dragqueryfilea" (ByVal hdrop&, ByVal ifile&,b Yval lpszfile$, ByVal cch&) Public Declare Sub dragfinish Lib "Shell32.dll" (ByVal hdrop&) Private Declare Function setwindowlong& Lib "user32" Alias "Setwindowlonga" (ByVal hwnd&,byval nindex&, ByVal dwnewlong&) |
The role of the SetWindowLong function is to set the properties for the specified window in the window structure and use it to change the window's attribute parameters, where the meanings of each parameter are shown in the following table:
Parameters |
Significance |
hwnd |
Long, the handle of the window for which to get information |
NIndex |
Long, where Gwl_wndproc is taken to indicate the address of the window function that sets the window |
Dwnewlong |
Long, the new value of the window information specified by nindex |
return value |
A Long that specifies the previous value of the data |
By default, the Windows operating system specifies a window function to accept and process Windows messages, while changing the address of a window function by using the SetWindowLong function to point to a function windowproc that we write ourselves. The Windows message is then forwarded to be received and processed by the WindowProc function. So we can judge the file drag and drop the message and handle it. The statements that change the properties of the window are as follows:
Procold = SetWindowLong (Me.hwnd, GWL_WNDPROC, AddressOf WindowProc) |
DragAcceptFiles, Dragqueryfile, dragfinish Three functions are: set a window to receive the drag and drop of the container, return the number of drag and drop files and information, stop drag and drop.
File drag and drop with API implementation