//声明 protected procedure WMDROPFILES(var Msg : TMessage); message WM_DROPFILES; //实现 procedure TFormMain.WMDROPFILES(var Msg: TMessage); var i, n: Integer; Buffer: Array[0..255] of Char; begin //得到拖拽文件数量 n := DragQueryFile(Msg.wParam, $FFFFFFFF, Buffer, 255); //处理选择多个文件 for i := 0 to n - 1 do begin //获取拖拽文件名 DragQueryFile(Msg.wParam, i, Buffer, 255); //文件名就在Buffer里面了 if UpperCase(ExtractFileExt(Buffer)) = '.BZLX' then begin //判断文件是否已经打开 if UpperCase(Buffer) = UpperCase('test.bzlx') then begin MessageDlg('文件test.bzlx已经打开!', (mtInformation),[mbOK],0); exit; end; //打开文件 OpenFile(Buffer); exit; end; end; //结束拖拽 DragFinish(Msg.wParam); end; //初始化 procedure TFormMain.FormCreate(Sender: TObject); begin //使窗口句柄可以接收拖拽操作 DragAcceptFiles(Handle, True); end;
http://blog.csdn.net/shuaihj/article/details/7046515