1

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

4

2 回答 2

5

当您更改 vcl 样式时,表单的句柄会重新创建,因此如果您 DragAcceptFiles之前调用该函数来设置样式,则应用样式时使用的句柄将不一样。要解决这个问题,请以这种方式执行 DragAcceptFiles 函数。

 TStyleManager.SetStyle(StyleName);
 Application.ProcessMessages;//process the message queue;
 DragAcceptFiles( Handle, True );
于 2012-04-26T16:42:41.957 回答
0

使用 shellApi 单元的方法DragAcceptFiles来实现你所需要的。它需要2个参数,第一个是应用程序的句柄,第二个是一个布尔值,用于指定是否开启-关闭拖动功能。打开使用类似的东西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捕获拖放操作。希望有帮助

于 2012-04-26T12:07:02.790 回答