Thema: Delphi Dropfiles und der Cursor

Einzelnen Beitrag anzeigen

Benutzerbild von chaosben
chaosben

Registriert seit: 27. Apr 2005
Ort: Görlitz
1.358 Beiträge
 
Delphi XE2 Professional
 
#3

Re: Dropfiles und der Cursor

  Alt 10. Mai 2006, 10:43
Ich glaube vom SwissDelphiCenter stammt der folgende Code, der jweils eine Zuweisung des Effektes (also auch Verbot) zulässt.

Delphi-Quellcode:
function TForm1.DragEnter(const dataObj: IDataObject; grfKeyState: Integer;
  pt: TPoint; var dwEffect: Integer): HResult;
var
  Form : tagFORMATETC;
begin
  dwEffect := DROPEFFECT_COPY; //Hier iss was
  with Form do
  begin
    cfFormat := CF_TEXT;
    ptd := nil;
    dwAspect := DVASPECT_CONTENT;
    lindex := -1;
    tymed := TYMED_HGLOBAL;
  end;
  Result := dataObj.QueryGetData(Form);
end;

function TForm1.DragLeave: HResult;
begin
  Result := S_OK;
end;

function TForm1.DragOver(grfKeyState: Integer; pt: TPoint;
  var dwEffect: Integer): HResult;
begin
  dwEffect := DROPEFFECT_COPY; //Guckst du hier
  Result := S_OK;
end;

function TForm1.Drop(const dataObj: IDataObject; grfKeyState: Integer;
  pt: TPoint; var dwEffect: Integer): HResult;
var
  aFmtEtc: TFORMATETC;
  aStgMed: TSTGMEDIUM;
  pData: PChar;
begin
  {Make certain the data rendering is available}
  if (dataObj = nil) then
    raise Exception.Create('IDataObject-Pointer is not valid!');
  with aFmtEtc do
  begin
    cfFormat := CF_TEXT;
    ptd := nil;
    dwAspect := DVASPECT_CONTENT;
    lindex := -1;
    tymed := TYMED_HGLOBAL;
  end;
  {Get the data}
  OleCheck(dataObj.GetData(aFmtEtc, aStgMed));
  try
    {Lock the global memory handle to get a pointer to the data}
    pData := GlobalLock(aStgMed.hGlobal);
    ScanTextForUrls(String(pData));
  finally
    {Finished with the pointer}
    GlobalUnlock(aStgMed.hGlobal);
    {Free the memory}
    ReleaseStgMedium(aStgMed);
  end;
  Result := S_OK;
end;
Initialisiert wird das via:
Delphi-Quellcode:
OleInitialize(nil);
  {Allow window to accept drop events}
  OleCheck(RegisterDragDrop(Handle, Self));
Und das Gegenteil ist:
Delphi-Quellcode:
{Finished accepting drops}
  RevokeDragDrop(Handle);
  OleUninitialize;
Ach so, das Formular braucht noch die IDropTarget-Unterstützung ... also:
MyNiceFormWithDropDeny = class(TForm, IDropTarget)
Benjamin Schwarze
If I have seen further it is by standing on the shoulders of Giants. (Isaac Newton)
  Mit Zitat antworten Zitat