Главная страница
Top.Mail.Ru    Яндекс.Метрика
Текущий архив: 2007.09.16;
Скачать: CL | DM;

Вниз

Drag из ОС и реакция на него...   Найти похожие ветки 

 
MTsv DN ©   (2007-01-25 22:33) [0]

Всем привет...

Если установить Options в [tvoDragDrop], то как отследить движение (Drag) по TreeView до момента бросания (Drop)??? Например, для того чтобы "подсвечивать" элемент под курсором...

Естесссна, Drag&Drop из системы в приложение...


 
Vladimir Kladov   (2007-01-26 15:01) [1]

мне кажется, эта опция для таскания внутри tree view. У нас есть компонент, позволяет драгать что угодно в систему. Посмотрите на него, если не получится с tvoDragDrop.


 
MTsv DN ©   (2007-01-26 22:57) [2]

Мне надо наоборот... Drag из системы. Например, я из Explorer"а тащю файл, там, видимо, срабатывает SetCаpture, я затаскиваю курсор на форму, на ней на TreeView...и вот етот момент, перемещения курсора над TreeView до момента "бросания", хочу отследить...

Вопрос: КАК?


 
Vladimir Kladov   (2007-01-27 09:16) [3]

Там вообще-то написано:
some stuff for KOL: drag and drop to and from one application to / from another via OLE.


 
MTsv DN ©   (2007-01-27 22:07) [4]

> Там вообще-то написано:
> some stuff for KOL: drag and drop to and from one application to / from another via OLE.

Владимир, то что написано в readme.txt не соответствует действительности!!! Я нашел те исходники, что портировал non, так вот DropSource.pas - это только часть, правда основная, всего комплекта. А еще там есть файл DropTarget.pas. Который я начал было портировать, но там оказалось столько ненужного, что я нашел в сети код, портировал его под KOL (если можно так сказать, несколько строчек всего изменил)...и теперь предоставляю его общественности:

unit FileDrop;

interface

uses KOL, Windows, ActiveX;
type
   TFileDropEvent=procedure(Sender:PControl;const FileList:{$IFDEF UNICODE_CTRLS}PWStrList{$ELSE}PStrList{$ENDIF})of object;
   TFileAcceptEvent=procedure(Sender:PControl;const FileList:{$IFDEF UNICODE_CTRLS}PWStrList{$ELSE}PStrList{$ENDIF};var CanAccept:boolean) of object;
   TFileDragOverEvent=procedure(Sender:PControl;grfKeyState:Longint;pt:TPoint;var dwEffect:Longint) of object;
   TFileDropAcceptor=class(TInterfacedObject,IDropTarget)
  private
     FFileList:{$IFDEF UNICODE_CTRLS}PWStrList{$ELSE}PStrList{$ENDIF};
     FOnFilesDropped:TFileDropEvent;
     FOnFileAccept:TFileAcceptEvent;
     FOnFileDragOver:TFileDragOverEvent;
  public
     constructor Create(AOnDrop:TFileDropEvent;AOnEnter:TFileAcceptEvent);
     destructor Destroy;override;
     function DragEnter(const dataObj:IDataObject;grfKeyState:Longint;pt:TPoint;var dwEffect:Longint):HResult;stdcall;
     function DragOver(grfKeyState:Longint;pt:TPoint;var dwEffect:Longint):HResult;stdcall;
     function DragLeave:HResult;stdcall;
     function Drop(const dataObj:IDataObject;grfKeyState:Longint;pt:TPoint;var dwEffect:Longint):HResult;stdcall;
     property OnFilesDropped:TFileDropEvent
       read FOnFilesDropped write FOnFilesDropped;
     property OnFilesDragOver:TFileDragOverEvent
       read FOnFileDragOver write FOnFileDragOver;
  end;

implementation

uses ShellAPI;

constructor TFileDropAcceptor.Create(AOnDrop:TFileDropEvent;AOnEnter:TFileAcceptEvent);
begin
    inherited Create;
    FFileList:=NewStrList;
    FOnFilesDropped:=AOnDrop;
    FOnFileAccept:=AOnEnter;
end;

destructor TFileDropAcceptor.Destroy;
begin
    FFileList.Free;
    inherited Destroy;
end;

function TFileDropAcceptor.DragEnter(const dataObj:IDataObject;grfKeyState:Longint;pt:TPoint;var dwEffect:Longint):HResult;stdcall;
var Medium:TSTGMedium;
   Format:TFormatETC;
   NumFiles:Integer;
   i:Integer;
   rslt:Integer;
   FileName:array [0..MAX_PATH]of char;
   S:string;
   CanDrop:boolean;
begin
    dataObj._AddRef;
    Format.cfFormat:=CF_HDROP;
    Format.ptd:=Nil;
    Format.dwAspect:=DVASPECT_CONTENT;
    Format.lindex:=-1;
    Format.tymed:=TYMED_HGLOBAL;
    rslt:=dataObj.GetData(Format,Medium);
    FFileList.Clear;
    if rslt=S_OK then
    begin
     NumFiles:=DragQueryFile(Medium.hGlobal,$FFFFFFFF,nil,0);
     for i:=0 to NumFiles-1 do
     begin
       DragQueryFile(Medium.hGlobal,i,FileName,sizeof(FileName));
       S:=FileName;
       FFileList.Add(S);
     end;
    end;
    if Medium.unkForRelease=nil then ReleaseStgMedium(Medium);
    dataObj._Release;
    CanDrop:=False;
    if FFileList.Count>0 then
    begin
      CanDrop:=True;
      if Assigned(FOnFileAccept) then FOnFileAccept(@Self,FFileList,CanDrop);
    end;
    Result:=S_OK;
end;

function TFileDropAcceptor.DragOver(grfKeyState:Longint;pt:TPoint;var dwEffect:Longint):HResult;stdcall;
begin
    if FFileList.Count>0 then
     begin
      dwEffect:=DROPEFFECT_COPY;
      GetCursorPos(pt);
      if Assigned(FOnFileDragOver) then
       FOnFileDragOver(@Self, grfKeyState, pt, dwEffect);
     end
      else dwEffect:=DROPEFFECT_NONE;
    Result:=S_OK;
end;

function TFileDropAcceptor.DragLeave:HResult;stdcall;
begin
    Result:=S_OK;
end;

function TFileDropAcceptor.Drop(const dataObj:IDataObject;grfKeyState:Longint;pt:TPoint;var dwEffect:Longint):HResult;stdcall;
begin
    if Assigned(FOnFilesDropped) and (FFileList.Count>0) then
    begin
      FOnFilesDropped(@Self,FFileList);
      dwEffect:=DROPEFFECT_COPY;
    end
    else dwEffect:=DROPEFFECT_NONE;
    Result:=S_OK;
end;

initialization
  OleInitialize(nil);

finalization
  OleUninitialize;

end.



Страницы: 1 вся ветка

Текущий архив: 2007.09.16;
Скачать: CL | DM;

Наверх




Память: 0.49 MB
Время: 0.029 c
15-1185568307
Kostafey
2007-07-28 00:31
2007.09.16
С днем рождения ! 28 июля


15-1187331871
Gydvin
2007-08-17 10:24
2007.09.16
Flatron F920B туфтовый монитор?


2-1187347440
new_chel
2007-08-17 14:44
2007.09.16
Дисконнект


2-1187804192
nord489
2007-08-22 21:36
2007.09.16
PopupMenu


3-1179317658
Цукор5
2007-05-16 16:14
2007.09.16
insert поля BCD