From: lancel@pdainc.com (Lance Leverich) Subject: Re: [delphi] Windows API headache Date: Fri, 7 Jul 1995 09:16:54 -0400 >Question: Does anyone know how to use SetWindowLong to install a new window >function for an existing window (subclassing), and more specifically, the >correct form for the new window function? I want to do this in order to >intercept messages going to another application. All right, here it goes... var OldWinProc: Integer; function NewWinProc(hWnd: HWND; Msg: WORD; wParam: WORD; lParam: LONGINT): LONGINT; var MessageProcessed: Boolean; begin MessageProcessed := False; case Msg of . . { if you process a message then set MessageProcessed to True } . . end; {end of case Msg } if not MessageProcessed then Result := CallWindowProc(OldWinProc,hWnd,Msg,wParam,lParam) else Result := 0; end; procedure SubClassWin(hWnd: HWND); begin OldWinProc := SetWindowLong(hWnd,GWL_WNDPROC,@NewWinProc); end; procedure UnSubClassWin(hWnd: HWND); begin SetWindowLong(hWnd,GWL_WNDPROC,OldWinProc); end; The syntax (function names/parameter types) here may not be spot on, I'm translating on the fly from C/C++ code that I know works. The concepts should be right on line, though. Good Luck! Lance Leverich PDA, Inc. lancel@pdainc.com (913) 469-8700 ext.4110