(CodeLib-Manager)
Registriert seit: 10. Jun 2002
4.648 Beiträge
Delphi XE Professional
|
Re: Handle einer Form aus Taskbareintrag erhalten
22. Apr 2007, 19:30
Danke erstmal. Habe das 1. Codestueck ueberarbeitet und es liefert schonmal erfolgreich den Index des Buttons unter der Maus.
Delphi-Quellcode:
var
pt: TPOINT;
TaskbarHWND: HWND;
hProc: THandle;
PID: THandle;
NumBytes: DWORD;
iButtonIndex : Integer;
lpPoint: Pointer;
begin
TaskbarHWND := getTaskbarHWND;
GetCursorPos(pt);
if (WindowFromPoint(pt) <> TaskbarHWND) then Exit;
Windows.ScreenToClient(TaskbarHWND, pt);
PID := 0;
GetWindowThreadProcessId(TaskbarHWND, @PID);
hProc := OpenProcess(PROCESS_VM_OPERATION or PROCESS_VM_READ or PROCESS_VM_WRITE, False, PID);
if hProc <> 0 then
try
lpPoint := VirtualAllocEx(hProc, nil, SizeOf(TPoint), MEM_RESERVE or MEM_COMMIT, PAGE_READWRITE);
NumBytes := 0;
WriteProcessMemory(hProc, lpPoint, @pt, SizeOf(TPOINT), NumBytes);
// Index ermittlen
iButtonIndex := SendMessage(TaskbarHWND,TB_HITTEST,0,Integer(lpPoint));
Caption := IntToStr(iButtonIndex );
if Assigned(lpPoint) then
VirtualFreeEx(hProc, lpPoint, 0, MEM_RELEASE);
finally
CloseHandle(hProc);
end;
Thomas
|
|
Zitat
|