读书人

AdvStringGrid1 接受圆桌面拖拽

发布时间: 2013-01-02 13:08:44 作者: rapoo

AdvStringGrid1 接受桌面拖拽?
怎么实现
把桌面文件直接拖放到 到AdvStringGrid 制定单元格?
没思路,
大家提示提示
有例子更好,呵呵
[解决办法]

unit Unit1;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ComCtrls, ExtCtrls, Grids, BaseGrid, AdvGrid, StrUtils,
ShellAPI;

type
TForm1 = class(TForm)
AdvStringGrid1: TAdvStringGrid;
procedure FormCreate(Sender: TObject);
procedure FormDestroy(Sender: TObject);
private
{ Private declarations }
OLDWndProc: TWndMethod;
public
{ Public declarations }
procedure WmDropFiles(var Msg: TMessage); message WM_DROPFILES;
end;

var
Form1: TForm1;

implementation

procedure TForm1.FormCreate(Sender: TObject);
begin
DragAcceptFiles(AdvStringGrid1.Handle, True);
OLDWndProc := AdvStringGrid1.WindowProc;
AdvStringGrid1.WindowProc := WmDropFiles;
end;

procedure TForm1.WmDropFiles(var Msg: TMessage);
var
n: integer;
pBuffer: array[0..255] of Char;
aRect: TRect;
aPotint1, aPotint2, pMouse: TPoint;
begin
if Msg.Msg <> WM_DROPFILES then
begin
OLDWndProc(Msg);
Exit;
end;

inherited;
GetCursorPos(pMouse);
aRect := AdvStringGrid1.CellRect(2, 2);//我指定的是第3行第3列
aPotint1.X := aRect.Left;
aPotint1.Y := aRect.Top;
aPotint1 := AdvStringGrid1.ClientToScreen(aPotint1);
aPotint2.X := aRect.Right;
aPotint2.Y := aRect.Bottom;
aPotint2 := AdvStringGrid1.ClientToScreen(aPotint2);
if (pMouse.X >= aPotint1.X) and (pMouse.X <= aPotint2.X) and
(pMouse.Y >= aPotint1.Y) and (pMouse.Y <= aPotint2.Y) then
begin
n := DragQueryFile(Msg.wParam, $FFFFFFFF, pBuffer, 255);
if n > 0 then
begin
pBuffer[0] := #0;
DragQueryFile(Msg.WParam, 0, pBuffer, Sizeof(pBuffer));
AdvStringGrid1.Cells[2, 2] := pBuffer;
end;
DragFinish(Msg.WParam);
end;
end;

读书人网 >.NET

热点推荐