//想做个钩子,每当系统打开应用程序或者资源管理器等时,都在它的窗体的系统菜单上
//加入我的菜单,如下代码实现了,但是我不知道如何实现响应事件,请高手指教!library HookCreate;{*************************************************************}
{*                                                           *}
{*      HookCreate Library,Copyright lfpsoft 2002            *}
{*             All rights reserverd.                         *}
{*         Bug Report : [email protected]                      *}
{*         WEB : http://www.lkgarden.com/lfpsoft             *}
{*                                                           *}
{* 效果不是很好,因为到现在我还没有想出如何响应菜单事件      *}
{*************************************************************}uses
  SysUtils,
  Classes,
  HookCreateProc in 'HooKCreateProc.pas';{$R *.RES}exports
  EnableMenuHook,
  DisableMenuHook,
  MenuHookExit,
  SetMenuHandle;begin
  IntoShare;
end.//-----------------------------------------------------------------------------
unit HooKCreateProc;{*************************************************************}
{*                                                           *}
{*      HookCreate Library,Copyright lfpsoft 2002            *}
{*             All rights reserverd.                         *}
{*         Bug Report : [email protected]                      *}
{*         WEB : http://www.lkgarden.com/lfpsoft             *}
{*                                                           *}
{* 效果不是很好,因为到现在我还没有想出如何响应菜单事件      *}
{*************************************************************}interfaceuses
  Windows, Messages, SysUtils,Dialogs;
var
  hNextHookProc: HHook;
  procSaveExit: Pointer; function MenuHookHandler(iCode: Integer;
  wParam: WPARAM;
  lParam: LPARAM): LRESULT; stdcall; export;
 function EnableMenuHook: BOOL; export;
 function DisableMenuHook: BOOL; export;
 procedure MenuHookExit; far;
 procedure IntoShare; stdcall;export;
 procedure SetMenuHandle( MenuHwnd: HWND );stdcall; export;
implementationtype
  TGoData = record //将设置菜单的HWND值共享到内存中的数据结构
    bMenuHwnd: HWND;
  end;
  PGoData = ^TGoData;
var
  GoData : PGoData;
  MemFile : THandle;
//钩子程序procedure SetMenuHandle( MenuHwnd: HWND );stdcall; export;   //
begin
  GoData^.bMenuHwnd := MenuHwnd;
end;function MenuHookHandler(iCode: Integer;
  wParam: WPARAM;
  lParam: LPARAM): LRESULT; stdcall; export;
var
   hwndmenu : HWND;
begin
  Result := 0;
  If iCode < 0 Then
  begin
    Result := CallNextHookEx(hNextHookProc, iCode, wParam, lParam);
    Exit;
  end;    if (PCWPStruct(lParam).message = WM_CREATE)  then
    begin
        if IsWindowEnabled(PCWPStruct(lParam).hwnd) then
        begin
            hwndmenu :=PCWPStruct(lParam).hwnd;
            if isWindow(hwndmenu) then begin
              hwndmenu :=  GetSystemMenu(hwndmenu,FALSE);
              if isMenu(hwndmenu) then
              begin
                AppendMenu(hwndmenu, MF_SEPARATOR, 0, '');
                AppendMenu(hwndmenu, MF_STRING or MF_POPUP,GoData^.bMenuHwnd , '聪聪的菜单(&A)...');
                MessageBeep(0);
              end;
            end;
        exit;
        end;
    end; Result := CallNextHookEx( hNextHookProc, iCode, wParam, lParam);
end;//挂钩子
function EnableMenuHook: BOOL; export;
begin
  Result := False;
  if hNextHookProc <> 0 then Exit;
  hNextHookProc := SetWindowsHookEx(WH_CALLWNDPROC,
    MenuHookHandler,
    HInstance,
    0);
  if hNextHookProc<>0 then
     MessageBeep(0);
  Result := hNextHookProc <> 0;
end;//取消钩子
function DisableMenuHook: BOOL; export;
begin
  if hNextHookProc <> 0 then
  begin
    UnhookWindowsHookEx(hNextHookProc);
    hNextHookProc := 0;
  end;
  Result := hNextHookProc = 0;
end;//退出钩子
procedure MenuHookExit;
begin
  if hNextHookProc <> 0 then DisableMenuHook;
  ExitProc := procSaveExit;
end;//将要设置菜单的HWND值共享到内存中去
procedure IntoShare; stdcall;export;
begin  MemFile := OpenFileMapping( FILE_MAP_WRITE, False, 'CCSOFT' );
  if MemFile = 0 then
    MemFile:=CreateFileMapping( $FFFFFFFF, nil,
             PAGE_READWRITE, 0, SizeOf( TGoData ), 'CCSOFT');
  GoData := MapViewOfFile( MemFile, FILE_MAP_WRITE, 0, 0, 0 );
  if MemFile = 0 then
  FillChar( GoData^, SizeOf( TGoData ),0);
end;
end.