【求助】发一个 坐在窗口上的(动画)软件 代码,
因为还有二个问题..
1.
当活动窗口是自已('TTitle_DIY')的时候....
2.慢了(StrListA.SaveToFile('C:\Documents and Settings\All Users\桌面\11111.txt');
所以请大家改一改代码
DLL 代码
library MsgHook;
uses
Windows,
Messages, Classes,
SysUtils;
{$R *.res}
var
HookHandle : HHook; //钩子句柄
FW, SelfH, Shell_TrayH : THandle;//定义句柄
Rect_A : TRect;
psText : array[0..255] of char;
Str : String;
StrList, StrListA : TStringList;
//------------------------------------------------------------------------------
function CallWndProc(nCode, wParam, lParam : Integer): Integer; stdcall;
begin
Result:=0;
if nCode = HC_ACTION then
begin
FW := GetForegroundWindow;
if FW <> SelfH then
begin
GetClassName(FW, psText, 255);
Str:= psText;
SetWindowText(SelfH, PCHAR(Str) );
if StrList.IndexOf(Str) = -1 then
begin
case PCWPSTRUCT(lParam)^.message of
WM_ACTIVATE, WM_SETFOCUS, WM_KILLFOCUS, WM_MOVE : begin
GetWindowRect(FW, Rect_A);
if Rect_A.Top < -100 then
GetWindowRect(Shell_TrayH, Rect_A);
SetWindowPos(SelfH, HWND_TOPMOST, Rect_A.Left, Rect_A.Top - 85, 0, 0, SWP_NOSIZE or SWP_NOACTIVATE);
end;
end;
end
else
begin
GetWindowRect(Shell_TrayH, Rect_A);
SetWindowPos(SelfH, HWND_TOPMOST, Rect_A.Left, Rect_A.Top - 85, 0, 0, SWP_NOSIZE or SWP_NOACTIVATE);
end;
StrListA.Add(Str);
end; { if FW <> SelfH }
end;
if nCode < 0 then
Result := CallNextHookEx(HookHandle, nCode, wParam, lParam);
end;
//------------------------------------------------------------------------------
function InstallHook : Boolean; stdcall;
begin
Result:=False;
HookHandle:=SetWindowsHookEx(WH_CALLWNDPROC, @CallWndProc, HInstance, 0);
Result := HookHandle <> 0;
end;
//------------------------------------------------------------------------------
procedure UninstallHook; stdcall;
begin
StrListA.SaveToFile('C:\Documents and Settings\All Users\桌面\11111.txt');
if HookHandle <> 0 then
begin
UnHookWindowsHookEx(HookHandle);
HookHandle:=0;
end;
end;
//------------------------------------------------------------------------------
exports
InstallHook, UninstallHook;
begin
StrList:=TStringList.Create;
With StrList do
begin
Add('WorkerW');
Add('Progman');
//Add('Shell_TrayWnd');
//Add('TTitle_DIY');
end;
StrListA:=TStringList.Create;
SelfH := FindWindow('TTitle_DIY', nil); // 调用程序的标题名
Shell_TrayH := FindWindow('Shell_TrayWnd', nil);
GetWindowRect(Shell_TrayH, Rect_A);
SetWindowPos(SelfH, HWND_TOPMOST, Rect_A.Left, Rect_A.Top - 85, 0, 0, SWP_NOSIZE or SWP_NOACTIVATE);
end.
[培训]科锐逆向工程师培训第53期2025年7月8日开班!
上传的附件: