好友
阅读权限40
听众
最后登录1970-1-1
|
楼主|
冥界3大法王
发表于 2024-12-21 21:50
@pzx521521
procedure TWinTitle.hotykey(var msg: TMessage);
var
pid: Cardinal;
pHandle: THandle;
buf: array[0..MAX_PATH] of Char;
ps: array[0..254] of Char; // 这个是定义激活的窗口的控件名
path: string; // 激活窗口的路径
arr: array[0..254] of Char;
h: HWND;
pt: TPoint;
c: TColor;
Point: TPoint;
类名: array[0..255] of Char;
Buffer: array[0..1023] of Char;
AHandle: THandle;
begin
if (GetAsyncKeyState(VK_LWIN) and (GetAsyncKeyState(Ord('A'))) < 0) then // Win+A
begin
h := GetForegroundWindow; // 这个是句柄
GetWindowThreadProcessId(h, @pid);
pHandle := OpenProcess(PROCESS_ALL_ACCESS, false, pid);
GetModuleFileNameEx(pHandle, 0, buf, Length(buf));
CloseHandle(pHandle);
GetWindowText(h, @arr, SizeOf(arr));
GetClassName(h, ps, 255);
// aWnd := WindowFromPoint(Mouse.CursorPos);
path := GetProcessExePath(h);
WinTitle.窗口标题Edit1.Text := arr;
WinTitle.窗口类名_Edit2.Text := ps;
WinTitle.窗口句柄_Edit4.Text := '0x' + PChar(IntToHex(StrToInt(IntToStr(h))));
WinTitle.完整路径_Edit5.Text := PChar(path);
WinTitle.窗口PID_Edit6.Text := Format('%u', [pid]);
//ShowMessage('当前激活的窗口标题是:' + arr + #13#10 + '得到激活的窗口类名是:' + ps + #13#10 + '得到激活窗口的完整路径是:' + PChar(path) + #13#10 + '当前窗口的句柄是:' + PChar(IntToHex(StrToInt(IntToStr(h)))));
//ShowMessage(Format('%u', [pid])); //得到激活窗口的pid可行
WinTitle.进程名_Edit7.Text := TRegEx.Replace(WinTitle.完整路径_Edit5.Text, '.*\\', '');
GetCursorPos(pt); //取得鼠标位置
WinTitle.KJ_Edit8.Text := IntToStr(pt.X) + ',' + IntToStr(pt.Y);
c := GetPixel(GetDC(0), pt.X, pt.Y);
WinTitle.KJ_Edit3.Color := c;
WinTitle.KJ_Edit3.Text := Format('#%.6x', [c]);
AHandle := WindowFromPoint(Point); // 取得当前窗口句柄
GetClassName(AHandle, 类名, Length(类名));
if AHandle = Self.Handle then
Exit;
SendMessage(AHandle, WM_GETTEXT, 1023, Integer(@Buffer));
WinTitle.KJ_Edit9.Text := StrPas(类名);
WinTitle.kj_Memo1.Lines.Text := StrPas(Buffer); //得到类名
===>>> 到这里!不知如何取得那个其他外部程序中类名对应的当前光标下的那个控件的名称了。
@pzx521521 不明白如何套用了,搞了好久没成功。
end;
end; |
|