子类化窗口在高级开发中的重要利器。受c#中NativeWindow的启发,实现了下面这样一个简单的类,来帮助更容易地对窗口实现子类化。
unit NativeWindow;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs;
Type
TzwNativeWindow = class
private
m_OldWinProc:FARPROC ;
m_NewWinProc:FARPROC ;
m_Handle:THandle;
protected
procedure WndProc(var Message: TMessage); virtual;
public
constructor Create;
destructor Destroy;override;
procedure AssignHandle(WndHandle:THandle);
procedure ReleaseHandle;
property Handle:THandle read m_Handle;
end;
implementation
{ TzwNativeWindow }
procedure TzwNativeWindow.AssignHandle(WndHandle: THandle);
begin
if (m_Handle<>WndHandle) then
begin
ReleaseHandle;
end;
m_Handle := WndHandle;
m_NewWinProc := MakeObjectInstance (WndProc );