首页
社区
课程
招聘
[求助]发一个 坐在窗口上的(动画)软件 代码, 请大家改一改代码
发表于: 2006-9-27 04:19 4081

[求助]发一个 坐在窗口上的(动画)软件 代码, 请大家改一改代码

2006-9-27 04:19
4081
【求助】发一个 坐在窗口上的(动画)软件 代码,

因为还有二个问题..
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日开班!

上传的附件:
收藏
免费 0
支持
分享
最新回复 (2)
雪    币: 3594
活跃值: (6336)
能力值: ( LV3,RANK:20 )
在线值:
发帖
回帖
粉丝
2
顶一下...................
2006-9-28 01:20
0
雪    币: 3594
活跃值: (6336)
能力值: ( LV3,RANK:20 )
在线值:
发帖
回帖
粉丝
3
顶一下...................
2006-9-30 03:30
0
游客
登录 | 注册 方可回帖
返回