这是DLL中的核心
HOOK,已经设置好了调用和取消HOOK的出口函数。
本意是想当用户关闭记事本时,不要关闭它,而是最小化它。可实际上执行并不成功。不知是为什么?function MessHookProc(nCode: Integer;WParam: WPARAM;LParam: LPARAM): LRESULT;stdcall;
var ms:^MSG;
hw:HWND;
begin
if nCode = 0 then begin
hw:=findwindow(nil,'未定标题 - 记事本');
ms:=pointer(LParam);
if ms.message = WM_SYSCOMMAND then begin
if (ms.wParam=SC_CLOSE) and (ms.hwnd=hw) then
sendMessage(ms.hwnd,WM_SYSCOMMAND,SC_CLOSE,0);
Result := 0;
Exit;
end;
end;
if nCode<0 then Result := CallNextHookEx(hk, nCode, wParam, lParam) else Result:=0;
end;
HOOK,已经设置好了调用和取消HOOK的出口函数。
本意是想当用户关闭记事本时,不要关闭它,而是最小化它。可实际上执行并不成功。不知是为什么?function MessHookProc(nCode: Integer;WParam: WPARAM;LParam: LPARAM): LRESULT;stdcall;
var ms:^MSG;
hw:HWND;
begin
if nCode = 0 then begin
hw:=findwindow(nil,'未定标题 - 记事本');
ms:=pointer(LParam);
if ms.message = WM_SYSCOMMAND then begin
if (ms.wParam=SC_CLOSE) and (ms.hwnd=hw) then
sendMessage(ms.hwnd,WM_SYSCOMMAND,SC_CLOSE,0);
Result := 0;
Exit;
end;
end;
if nCode<0 then Result := CallNextHookEx(hk, nCode, wParam, lParam) else Result:=0;
end;
hk:= SetWindowsHookEx(WH_GETMESSAGE,@MessHookProc,Hinstance,0);
使用的是该类型。
TO楼上:
我手头上分不多,如果你只是为了分而不是真诚救人与水火的话,就不应该来。
你应该用WH_CALLWNDPROC钩子
现在想要使它失效,该如何做???
真的急,麻烦老大及时回复。
使用CBT可以,但无法更改它的消息
我截获WM_SYSCOMMAND和WM_CLOSE只能处理掉alt+f4,点那个叉照样会退出。。
TForm1 = class(TForm)
private
{ Private declarations }
procedure WMSysCommand(var Msg: TWMSysCommand);
message WM_SYSCOMMAND;
public
{ Public declarations }
end;var
Form1: TForm1;implementation{$R *.DFM}procedure TForm1.WMSysCommand;
begin
if (Msg.CmdType = SC_MINIMIZE) or
(Msg.CmdType = SC_MAXIMIZE) or (Msg.CmdType =SC_CLOSE)then
MessageBeep(0) else
inherited;
end;end.这样就没反应了
begin
canclose:=false;
application.Minimize;
end;你看这样行不行,好象如果没有特别的处理的话就关不了了。
uCmdType = wParam; // type of system command requested
xPos = LOWORD(lParam); // horizontal position, in screen coordinates
yPos = HIWORD(lParam); // vertical position, in screen coordinates ->uCmdType
Specifies the type of system command requested. This parameter can be one of the following values. Value Meaning
SC_CLOSE Closes the window.
==========================================
function MessHookProc(nCode: Integer;WParam: WPARAM;LParam: LPARAM): LRESULT;stdcall;
var ms:^MSG;
hw:HWND;
begin
Result := 0;
If iCode < 0 Then
begin
Result := CallNextHookEx(hNextHookProc, iCode, wParam, lParam);
Exit;
end;
if (nCode = HSHELL_WINDOWDESTROYED) then
begin
if MessageDlg('关闭本程序吗?', mtConfirmation, mbYesNoCancel, 0) = mrYes
then Result := CallNextHookEx(hk, nCode, wParam, lParam)
// 允许Windows关闭
else result:=1; // 阻止Windows关闭
end
else begin
Result := CallNextHookEx(hk, nCode, wParam, lParam);
end;
end;
http://community.csdn.net/Expert/topic/3504/3504457.xml?temp=.3672144