Delphi中从Windows资源管理器中拖放图片到TImage控件上


本文整理自网络,侵删。

 


unit Unit1;

interface

uses
Windows, Messages, SysUtils, Variants, Classes,
Graphics, Controls, Forms, Dialogs, ExtCtrls;

type
TForm1 = class(TForm)
Panel1: TPanel;
Image1: TImage;
procedure FormCreate(Sender: TObject) ;
private
originalPanelWindowProc : TWndMethod;
procedure PanelWindowProc (var Msg : TMessage) ;
procedure PanelImageDrop (var Msg : TWMDROPFILES) ;
public
{ Public declarations }
end;

var
Form1: TForm1;

implementation
{$R *.dfm}

uses ShellApi;

procedure TForm1.FormCreate(Sender: TObject) ;
begin
originalPanelWindowProc := Panel1.WindowProc;
Panel1.WindowProc := PanelWindowProc;

DragAcceptFiles(Panel1.Handle,true) ;
end; (*FormCreate*)

procedure TForm1.PanelWindowProc(var Msg: TMessage) ;
begin
if Msg.Msg = WM_DROPFILES then
PanelImageDrop(TWMDROPFILES(Msg))
else
originalPanelWindowProc(Msg) ;
end; (*PanelWindowProc*)

procedure TForm1.PanelImageDrop(var Msg: TWMDROPFILES) ;
var
numFiles : longInt;
buffer : array[0..MAX_PATH] of char;
begin
numFiles := DragQueryFile(Msg.Drop, $FFFFFFFF, nil, 0) ;
if numFiles > 1 then
begin
ShowMessage('You can drop only one image file at a time!') ;
end
else
begin
DragQueryFile(Msg.Drop, 0, @buffer, sizeof(buffer)) ;
try
Image1.Picture.LoadFromFile(buffer) ;
except
on EInvalidGraphic do ShowMessage('Unsupported image file, or not an image!') ;
end;
end;
end; (*PanelImageDrop*)

end.

相关阅读 >>

Delphi 复制文件到剪贴板

Delphi webbrowser 加载html 将html代码转换成网页

Delphi 之 标签组件(tlabel组件)

Delphi query1 导出csv txt

Delphi 提高进程自身权限

Delphi xe7组件tetheringmanager1发送消息

Delphi tstrings 过滤空行

Delphi穿墙自启动下载者4.0

Delphi 十进制十六进制转换

Delphi 处理以逗号分隔的长字符串

更多相关阅读请进入《Delphi》频道 >>



打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,您说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

分享从这里开始,精彩与您同在

评论

管理员已关闭评论功能...