2005. december 3., szombat

How to trap mouse clicks on the Desktop


Problem/Question/Abstract:

I wonder if anyone can help me. I am trying to capture when the mouse button is pressed on the desktop wallpaper (excluding icons if possible).

Answer:

This returns the same handle:

function GetDesktopListViewHandle: THandle;
var
  S: string;
begin
  Result := FindWindow('ProgMan', nil);
  Result := GetWindow(Result, GW_CHILD);
  Result := GetWindow(Result, GW_CHILD);
  SetLength(S, 40);
  GetClassName(Result, PChar(S), 39);
  if PChar(S) <> 'SysListView32' then
    Result := 0;
end;

procedure TForm1.Timer1Timer(Sender: TObject);
var
  CursorPos: TPoint;
  h: THandle;
begin
  GetCursorPos(CursorPos);
  h := WindowFromPoint(CursorPos);
  Label1.Caption := IntToStr(h);
end;

procedure TForm1.FormShow(Sender: TObject);
begin
  Label2.Caption := IntToStr(GetDesktopListViewHandle); { GetDeskTopWindow); }
  Timer1.Enabled := True;
end;

Nincsenek megjegyzések:

Megjegyzés küldése