home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The Mother of All Windows Books
/
CD-MOM.iso
/
cd_mom
/
newsletr
/
vbz
/
vbz1-3
/
dll_src.exe
/
D&DSERVE.PAS
< prev
next >
Wrap
Pascal/Delphi Source File
|
1993-02-24
|
5KB
|
183 lines
library DnDSERVE;
{DLL to provide Drag 'n Drop Server support to Visual Basic}
{by Jonathan Zuck -=- Copyright 1993 User Friendly, Inc.}
{$R D&DSERVE}
{$R D&DCURS}
uses WinTypes, WinProcs, Win31, Strings;
const
GMEM_DROP = GMEM_MOVEABLE or GMEM_ZEROINIT or GMEM_SHARE;
type
DropFileRec = record
StrucSize:Word;
MousePoint:TPoint;
InNC:WordBool;
end;
pDropFileRec = ^DropFileRec;
IntArr = array [1..5440] of Integer;
var
MousePos: TPoint;
function DragMeister (nFiles, VKButton:Integer):HWND;export;
Var
Cursor_OK, Cursor_NOTOK,
Cursor_Prev:hCursor;
TargetWnd:hWnd;
OKToDrop:WordBool;
Msg:TMSG;
Begin
if nFiles = 1 then Cursor_OK := LoadCursor (HInstance, 'OK_SINGLE')
else Cursor_OK := LoadCursor (HInstance, 'OK_MULTI');
Cursor_NOTOK := LoadCursor (HInstance, 'NOT_OK');
while Bool(GetAsyncKeyState(VKButton) and $8000) do
Begin
GetCursorPos (MousePos);
TargetWnd := WindowFromPoint (MousePos);
OkToDrop := False;
while (OkToDrop = False) and (TargetWnd <> 0) do begin
OkToDrop := Bool(GetWindowLong(TargetWnd, GWL_EXSTYLE)
and WS_EX_ACCEPTFILES);
if OkToDrop = False then TargetWnd := GetParent(TargetWnd);
end; {while}
if OkToDrop then
SetCursor (Cursor_OK)
else
SetCursor (Cursor_NOTOK);
while PeekMessage (Msg, 0, 0, 0, PM_REMOVE) do;
end;
if GetCursor = Cursor_OK then DragMeister := TargetWnd
else DragMeister := 0;
ReleaseCapture;
DestroyCursor (Cursor_OK);
DestroyCursor (Cursor_NOTOK);
End;
function InitGlobalDroppings (hTarget:HWND;nBytes:LongInt):THandle;export;
var
hMem:THandle;
pRec:pDropFileRec;
begin
hMem := GlobalAlloc (GMEM_DROP, nBytes);
pRec := GlobalLock (hMem);
pRec^.StrucSize := SizeOf(DropFileRec);
pRec^.InNC := (htClient <> SendMessage (hTarget, WM_NCHITTEST, 0,
MakeLong (MousePos.x, MousePos.y)));
ScreenToClient (hTarget, MousePos);
pRec^.MousePoint.x := MousePos.x;
pRec^.MousePoint.y := MousePos.y;
GlobalUnlock (hMem);
InitGlobalDroppings := hMem;
end;
function DropSelItems (hLBox:HWND;lpPath:PChar;Button:Integer):HWND;export;
Var
nFiles, Item,
PathLen, ItemSize:Integer;
hTarget:HWND;
MemSize:LongInt;
Pos:PChar;
lpArr:^IntArr;
hMem:THandle;
Begin
nFiles := SendMessage (hLBox, LB_GETSELCOUNT, 0, 0);
hTarget := DragMeister (nFiles, Button);
if hTarget > 0 then
Begin
GetMem (lpArr, nFiles * 2);
SendMessage (hLBox, LB_GETSELITEMS, 5440, LongInt(lpArr));
PathLen := StrLen (lpPath);
MemSize := 8;
for Item := 1 to nFiles do
Begin
ItemSize := SendMessage (hLBox, LB_GETTEXTLEN, lpArr^[Item], 0);
MemSize := MemSize + PathLen + ItemSize + 1;
end;
hMem := InitGlobalDroppings (hTarget, MemSize);
Pos := GlobalLock (hMem);
Pos := Pos + 8;
for Item := 1 to nFiles do
Begin
StrMove (Pos, lpPath, PathLen);
Pos := Pos + PathLen;
ItemSize := SendMessage (hLBox, LB_GETTEXT,
lpArr^[Item], LongInt(Pos));
Pos := Pos + ItemSize + 1;
end;
GlobalUnlock (hMem);
FreeMem (lpArr, nFiles * 2);
PostMessage (hTarget, WM_DROPFILES, hMem, 0);
end;
DropSelItems := hTarget;
end;
function DropAllItems (hLBox:HWND;Button:Integer):HWND;export;
Var
nFiles, Item,
ItemSize:Integer;
hTarget:HWND;
MemSize:LongInt;
Pos:PChar;
hMem:THandle;
Begin
nFiles := SendMessage (hLBox, LB_GETCOUNT, 0, 0);
hTarget := DragMeister (nFiles, Button);
if hTarget > 0 then
Begin
MemSize := 8;
for Item := 0 to nFiles - 1 do
Begin
ItemSize := SendMessage (hLBox, LB_GETTEXTLEN, Item, 0);
MemSize := MemSize + ItemSize + 1;
end;
hMem := InitGlobalDroppings (hTarget, MemSize);
Pos := GlobalLock (hMem);
Pos := Pos + 8;
for Item := 0 to nFiles - 1 do
Begin
ItemSize := SendMessage (hLBox, LB_GETTEXT,
Item, LongInt(Pos));
Pos := Pos + ItemSize + 1;
end;
GlobalUnlock (hMem);
PostMessage (hTarget, WM_DROPFILES, hMem, 0);
end;
DropAllItems := hTarget;
end;
function DropBuff (Buff:PChar;BuffSize,nFiles, Button:Integer):HWND;export;
Var
hTarget:HWND;
MemSize:LongInt;
Pos:PChar;
hMem:THandle;
Begin
hTarget := DragMeister (nFiles, Button);
if hTarget > 0 then
Begin
MemSize := SizeOf(DropFileRec) + BuffSize;
hMem := InitGlobalDroppings (hTarget, MemSize);
Pos := GlobalLock (hMem);
Pos := Pos + SizeOf(DropFileRec);
StrMove (Pos, Buff, BuffSize);
GlobalUnlock (hMem);
PostMessage (hTarget, WM_DROPFILES, hMem, 0);
end;
DropBuff := hTarget;
end;
Exports
DragMeister resident,
InitGlobalDroppings resident,
DropSelItems resident,
DropAllItems resident,
DropBuff resident;
Begin
End.