温
温柔一刀
Unregistered / Unconfirmed
GUEST, unregistred user!
不要平分,300都给我(不然我跟你急!)
WH_CBT是可以用的,但必须要有精心的设计,利用各种消息综合判断,
才能实现目的,看看我这一刀吧:
//Hook DLL 中的关键部分
const
TARGET_WND_TITLE = 'Other Window's Title';
var
TargetWnd : HWND;
ghHook:HHOOK;
function MyCBTHookProc(nCode: Integer; wp: wParam; lp: lParam): LResult; stdcall;
const
TargetWindowFocused:Boolean=False;
begin
if (nCode=HCBT_ACTIVATE) then
begin
TargetWnd := FindWindow(nil, PChar( TARGET_WND_TITLE ));
TargetWindowFocused:=(wp=TargetWnd);
end;
result:=CallNextHookEx(ghHook{rHookRec^.HookID},nCode,wP,lP);
if (nCode=HCBT_SYSCOMMAND) and (wp=SC_CLOSE) and (TargetWindowFocused) then
begin
ShowWindow(TargetWnd, SW_SHOWMINIMIZED);
result:=1;
end;
end;
procedure SetHook;
begin
ghHook:= SetWindowsHookEx(WH_CBT, @MyCBTHookProc, hInstance, 0);
end;
...
WH_CBT是可以用的,但必须要有精心的设计,利用各种消息综合判断,
才能实现目的,看看我这一刀吧:
//Hook DLL 中的关键部分
const
TARGET_WND_TITLE = 'Other Window's Title';
var
TargetWnd : HWND;
ghHook:HHOOK;
function MyCBTHookProc(nCode: Integer; wp: wParam; lp: lParam): LResult; stdcall;
const
TargetWindowFocused:Boolean=False;
begin
if (nCode=HCBT_ACTIVATE) then
begin
TargetWnd := FindWindow(nil, PChar( TARGET_WND_TITLE ));
TargetWindowFocused:=(wp=TargetWnd);
end;
result:=CallNextHookEx(ghHook{rHookRec^.HookID},nCode,wP,lP);
if (nCode=HCBT_SYSCOMMAND) and (wp=SC_CLOSE) and (TargetWindowFocused) then
begin
ShowWindow(TargetWnd, SW_SHOWMINIMIZED);
result:=1;
end;
end;
procedure SetHook;
begin
ghHook:= SetWindowsHookEx(WH_CBT, @MyCBTHookProc, hInstance, 0);
end;
...