Subcolate window Auxiliary class NativeWindow

zhaozj2021-02-08  241

An important tool in advanced development in advanced development. Inspired by NativeWindow in C #, the following simple classes are implemented to help achieve subcatenation more easily.

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); m_OldWinProc: = pointer (GetWindowLong (m_Handle, GWL_WNDPROC)); Setwindowlong (M_Handle, GWL_WndProc, longint (m_newwinproc);

Constructor tzwnativeWindow.create; begin m_handle: = invalid_handle_value; m_oldwinproc: = nil; m_newwinc: = nil; end;

Destructor TzwnativeWindow.Destroy; begin releasehandle; inherited;

procedure TzwNativeWindow.ReleaseHandle; begin if (m_Handle <> INVALID_HANDLE_VALUE) then try SetWindowLong (m_Handle, GWL_WNDPROC, LongInt (m_OldWinProc)); finally m_Handle: = INVALID_HANDLE_VALUE; m_OldWinProc: = nil; m_NewWinProc: = nil; end; end;

Procedure TzwnativeWindow.WndProc (Var Message: TMessage); Begin With Message Do Begin Result: = CallWindowProc (M_OldwinProc, M_Handle, MSG, WPARAM, LPARAM); End;

End.

转载请注明原文地址:https://www.9cbs.com/read-2594.html

New Post(0)