| 導購 | 订阅 | 在线投稿
分享
 
 
 

接受外部拖動

來源:互聯網網民  2006-09-16 05:50:25  評論

最近在CSDN經常碰到有人問如何在DELPHI編程的時候,讓程序接受外部拖動而來的內容並處理。

就是處理wm_dropfiles消息以及使用DragAcceptFiles、dragqueryfile、dragfinish來操作,這些內容在DELPHI中被封裝在shellapi中,編程的時候,要uses這個單元。

在這裏用一個例子演示,以後再回答此問題的時候就不用再寫了。


接受外部拖動
unit Unit1;
接受外部拖動

接受外部拖動
interface
接受外部拖動

接受外部拖動
uses
接受外部拖動
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
接受外部拖動
Dialogs, StdCtrls,shellapi;//要使用到shellapi中的內容
接受外部拖動

接受外部拖動
type
接受外部拖動
TForm1 = class(TForm)
接受外部拖動
Memo1: TMemo;
接受外部拖動
Label1: TLabel;
接受外部拖動
procedure FormCreate(Sender: TObject);
接受外部拖動
private
接受外部拖動
//處理WM_DROPFILES消息
接受外部拖動
procedure dragdropfile(var msg : tmessage);message wm_dropfiles;
接受外部拖動
public
接受外部拖動
接受外部拖動
...{ Public declarations }
接受外部拖動
end;
接受外部拖動

接受外部拖動
var
接受外部拖動
Form1: TForm1;
接受外部拖動

接受外部拖動
implementation
接受外部拖動

接受外部拖動
接受外部拖動
...{$R *.dfm}
接受外部拖動

接受外部拖動
procedure TForm1.dragdropfile(var msg: tmessage);
接受外部拖動
var
接受外部拖動
char1:array[0..128] Of char;
接受外部拖動
char2 : pchar;
接受外部拖動
i,sum :integer;
接受外部拖動
begin
接受外部拖動
//獲得拖動的數量
接受外部拖動
sum := dragqueryfile(msg.wparam,$FFFFFFFF,nil,0);
接受外部拖動
//用一個label顯示此數量
接受外部拖動
label1.caption := inttostr(sum);
接受外部拖動
char2 := @char1;
接受外部拖動
for i := 0 to sum-1 do
接受外部拖動
begin
接受外部拖動
//將拖動文件的路徑存放到char2並通過一個memo來顯示
接受外部拖動
DragQueryFile(msg.wparam,i,char2,128);
接受外部拖動
memo1.lines.add(char2);
接受外部拖動
end;
接受外部拖動
dragfinish(msg.wparam);//結束
接受外部拖動
end;
接受外部拖動

接受外部拖動
procedure TForm1.FormCreate(Sender: TObject);
接受外部拖動
begin
接受外部拖動
//讓程序接受外部拖動
接受外部拖動
DragAcceptFiles(Handle,true);
接受外部拖動
end;
接受外部拖動

接受外部拖動
end.
接受外部拖動

注:WINXP+D7,轉載請注明出處

 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
 
最近在CSDN經常碰到有人問如何在DELPHI編程的時候,讓程序接受外部拖動而來的內容並處理。 就是處理wm_dropfiles消息以及使用DragAcceptFiles、dragqueryfile、dragfinish來操作,這些內容在DELPHI中被封裝在shellapi中,編程的時候,要uses這個單元。 在這裏用一個例子演示,以後再回答此問題的時候就不用再寫了。 [url=/bbs/detail_501488.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url]unit Unit1; [url=/bbs/detail_501488.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] [url=/bbs/detail_501488.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url]interface [url=/bbs/detail_501488.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] [url=/bbs/detail_501488.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url]uses [url=/bbs/detail_501488.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, [url=/bbs/detail_501488.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] Dialogs, StdCtrls,shellapi;//要使用到shellapi中的內容 [url=/bbs/detail_501488.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] [url=/bbs/detail_501488.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url]type [url=/bbs/detail_501488.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] TForm1 = class(TForm) [url=/bbs/detail_501488.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] Memo1: TMemo; [url=/bbs/detail_501488.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] Label1: TLabel; [url=/bbs/detail_501488.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] procedure FormCreate(Sender: TObject); [url=/bbs/detail_501488.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] private [url=/bbs/detail_501488.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] //處理WM_DROPFILES消息 [url=/bbs/detail_501488.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] procedure dragdropfile(var msg : tmessage);message wm_dropfiles; [url=/bbs/detail_501488.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] public [url=/bbs/detail_501488.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif[/img][/url][url=/bbs/detail_501488.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif[/img][/url] ...{ Public declarations } [url=/bbs/detail_501488.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] end; [url=/bbs/detail_501488.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] [url=/bbs/detail_501488.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url]var [url=/bbs/detail_501488.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] Form1: TForm1; [url=/bbs/detail_501488.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] [url=/bbs/detail_501488.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url]implementation [url=/bbs/detail_501488.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] [url=/bbs/detail_501488.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif[/img][/url][url=/bbs/detail_501488.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif[/img][/url]...{$R *.dfm} [url=/bbs/detail_501488.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] [url=/bbs/detail_501488.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url]procedure TForm1.dragdropfile(var msg: tmessage); [url=/bbs/detail_501488.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url]var [url=/bbs/detail_501488.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] char1:array[0..128] Of char; [url=/bbs/detail_501488.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] char2 : pchar; [url=/bbs/detail_501488.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] i,sum :integer; [url=/bbs/detail_501488.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url]begin [url=/bbs/detail_501488.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] //獲得拖動的數量 [url=/bbs/detail_501488.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] sum := dragqueryfile(msg.wparam,$FFFFFFFF,nil,0); [url=/bbs/detail_501488.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] //用一個label顯示此數量 [url=/bbs/detail_501488.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] label1.caption := inttostr(sum); [url=/bbs/detail_501488.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] char2 := @char1; [url=/bbs/detail_501488.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] for i := 0 to sum-1 do [url=/bbs/detail_501488.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] begin [url=/bbs/detail_501488.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] //將拖動文件的路徑存放到char2並通過一個memo來顯示 [url=/bbs/detail_501488.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] DragQueryFile(msg.wparam,i,char2,128); [url=/bbs/detail_501488.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] memo1.lines.add(char2); [url=/bbs/detail_501488.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url]end; [url=/bbs/detail_501488.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] dragfinish(msg.wparam);//結束 [url=/bbs/detail_501488.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url]end; [url=/bbs/detail_501488.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] [url=/bbs/detail_501488.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url]procedure TForm1.FormCreate(Sender: TObject); [url=/bbs/detail_501488.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url]begin [url=/bbs/detail_501488.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] //讓程序接受外部拖動 [url=/bbs/detail_501488.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] DragAcceptFiles(Handle,true); [url=/bbs/detail_501488.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url]end; [url=/bbs/detail_501488.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] [url=/bbs/detail_501488.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url]end. [url=/bbs/detail_501488.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] 注:WINXP+D7,轉載請注明出處
󰈣󰈤
王朝萬家燈火計劃
期待原創作者加盟
 
 
 
>>返回首頁<<
 
 
 
 
 
 熱帖排行
 
 
靜靜地坐在廢墟上,四周的荒凉一望無際,忽然覺得,淒涼也很美
© 2005- 王朝網路 版權所有