unit Unit1; <br> <br> interface <br> <br> uses <br> Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, <br> Dialogs, Menus; <br> <br> type <br> TForm1 = class(TForm) <br> MainMenu1: TMainMenu; <br> New1: TMenuItem; <br> procedure New1Click(Sender: TObject); <br> procedure FormDestroy(Sender: TObject); <br> procedure FormCreate(Sender: TObject); <br> private <br> { Private declarations } <br> public <br> { Public declarations } <br> end; <br> <br> var <br> Form1: TForm1; <br> <br> implementation <br> <br> {$R *.dfm} <br> <br> uses Unit2; <br> <br> var <br> lpfnClient: Pointer; <br> <br> function HookClientProc(hWnd: HWND; uMsg: UINT; wParam: WPARAM; lParam: LPARAM): LRESULT; stdcall; <br> begin <br> if uMsg = WM_MDIDESTROY then <br> ShowMessage('WM_MDIDESTROY'); <br> Result := CallWindowProc(Pointer(lpfnClient), hWnd, uMsg, wParam, lParam) <br> end; <br> <br> procedure TForm1.New1Click(Sender: TObject); <br> begin <br> with TForm2.Create(Self) do <br> begin <br> Visible := True; <br> end; <br> end; <br> <br> procedure TForm1.FormDestroy(Sender: TObject); <br> begin <br> SetWindowLong(Self.ClientHandle, GWL_WNDPROC, Integer(lpfnClient)); <br> end; <br> <br> procedure TForm1.FormCreate(Sender: TObject); <br> begin <br> lpfnClient := Pointer(GetWindowLong(Self.ClientHandle, GWL_WNDPROC)); <br> SetWindowLong(Self.ClientHandle, GWL_WNDPROC, LPARAM(@HookClientProc)); <br> end; <br> <br> end.<br>关闭我测试过,绝对可以。打开只要检索uMsg值对应打开值应该也是可以的。