Drag your software to open a file
Author: Shuai hongjun
// Statement
Protected
Procedure wmdropfiles (var msg: tmessage); message wm_dropfiles;
Bytes ------------------------------------------------------------------------------------------------------------------------
// Implementation
Procedure tformmain. wmdropfiles (var msg: tmessage );
VaR
I, n: integer;
Buffer: array [0 .. 255] of char;
Begin
// Obtain the number of drag files
N: = dragqueryfile (msg. wparam, $ ffffffff, buffer, 255 );
// Process multiple selected files
For I: = 0 to n-1 do
Begin
// Obtain the drag Object Name
Dragqueryfile (msg. wparam, I, buffer, and 255 );
// The file name is in the buffer.
If uppercase (extractfileext (buffer) = '. bzlx' then
Begin
// Determine whether the file has been opened
If uppercase (buffer) = uppercase ('test. bzlx') then
Begin
Messagedlg ('the file test. bzlx has been opened! ', (Mtinformation), [mbok], 0 );
Exit;
End;
// Open the file
Openfile (buffer );
Exit;
End;
End;
// End dragging
Dragfinish (msg. wparam );
End;
Bytes ------------------------------------------------------------------------------------------------------------------------
// Initialization
Procedure tformmain. formcreate (Sender: tobject );
Begin
// Enable the window handle to receive the drag operation
Dragacceptfiles (handle, true );
End;