私は Delphi プログラマーですが、質問があります。TStyleManager でフォームを作成し、アプリケーションでスキンを使用しています。しかし、アプリでもドラッグ アンド ドロップ ファイルを使用したいと考えています。どうすればこれを実現できますか?いろいろな方法を試してみましたが・・・なかなかできませんでした。あなたの助けを願っています
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 つのパラメータが必要です。1 つ目はアプリケーションのハンドルで、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 に答える