德尔福:Vcl Styles&拖放正下降

时间:2012-04-26 11:58:37

标签: delphi drag-and-drop delphi-xe2 vcl-styles

我是德尔福程序员,我有一个问题。我使用TStyleManager创建一个表单,并在我的应用程序上使用外观。但我也想在我的应用程序中使用Drag-n-Drop文件。我怎么能意识到这一点?我尝试了很多方法,但是......我无法做到。希望你的帮助

2 个答案:

答案 0 :(得分:5)

当您更改vcl样式时,将重新创建窗体的句柄,因此,如果在设置样式之前调用DragAcceptFiles函数,则在应用样式时使用的句柄将不同。修复它以这种方式执行DragAcceptFiles函数。

 TStyleManager.SetStyle(StyleName);
 Application.ProcessMessages;//process the message queue;
 DragAcceptFiles( Handle, True );

答案 1 :(得分:0)

使用shellApi单元的方法DragAcceptFiles来实现您的需求。它需要2个参数,第一个是Application的句柄,第二个是布尔值,用于指定是否切换开 - 关拖动功能。开启使用像DragAcceptFiles(Self.Handle,True);

这样的东西

要响应拖放文件,请使用

Procedure TForm1.RespondToMessage(var Msg : TMsg;var handled : Boolean) ;
const
   FileIndex : Cardinal = Cardinal(-1);   { return a count of dropped files }
   BuffLen   = 255;
 Var
    FileNum : Word;
   FName : String;
   BuffArr : Array[0..MAX_PATH-1] of Char;
 Begin
If Msg.message = WM_DROPFILES Then
 Begin

For FileNum := 0 To DragQueryFile(Msg.wParam,FileIndex,Nil,BuffLen)-1 Do   // first time , FileIndex is 0xFFFFFFFF , so
// the return is the number of files to be dragged
// Here the return in fileIndex is the no of files;
Begin
   DragQueryFile(Msg.wParam, FileNum , BuffArr , BuffLen);
   FName := StrPas(BuffArr);
   //AddButton(FName); -- do whatever operation you want with the fileName
End;
Try
  DragFinish(Msg.wParam);  // Free the memory given to drag operation
Except
End;  
Handled := True;
//AddScrollIfRequired;
End;
End;

现在加入Application.OnMessage := RespondToMessage以阻止阻力&放弃操作。 希望有所帮助

相关问题