How do I know if a user is dragging something when the cursor is not in my window?

We all know that you can implement the drag-and-drop function for your window so that it accepts the drag-and-drop operation, but my question is how to detect the drag-and-drop operation that is performed on other windows , for example, dragging a file in Windows Explorer? What I want to do is that when the user drags the file, my hidden window appears.

Thank!

+3
source share
3 answers

, , . , , , .

, , - SetWindowsHookEx() DLL , . , .

0

Drag & Drop, "SysDragImage". .

( , ):

procedure WinEventProc(hWinEventHook: THandle; event: DWORD;
  hwnd: HWND; idObject, idChild: Longint; idEventThread, dwmsEventTime: DWORD); stdcall;
var
  ClassName: string;
begin
  SetLength(ClassName, 255);
  SetLength(ClassName, GetClassName(hWnd, pchar(ClassName), 255));

  if pchar(ClassName) = 'SysDragImage' then
  begin
    if event = EVENT_OBJECT_CREATE then
      Form1.Memo1.Lines.Add('Drag Start')
    else
      Form1.Memo1.Lines.Add('Drag End');    
  end;
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
  FEvent1 := SetWinEventHook(EVENT_OBJECT_CREATE, EVENT_OBJECT_CREATE, 0, @WinEventProc, 0, 0, WINEVENT_OUTOFCONTEXT);
  FEvent2 := SetWinEventHook(EVENT_OBJECT_DESTROY, EVENT_OBJECT_DESTROY, 0, @WinEventProc, 0, 0, WINEVENT_OUTOFCONTEXT);
end;

procedure TForm1.FormDestroy(Sender: TObject);
begin
  UnhookWinEvent(FEvent1);
  UnhookWinEvent(FEvent2);
end;

, Escape , EVENT_OBJECT_DESTROY. EVENT_OBJECT_CREATE , .

0

Source: https://habr.com/ru/post/1747925/


All Articles