Einzelnen Beitrag anzeigen

Fritzew

Registriert seit: 18. Nov 2015
Ort: Kehl
678 Beiträge
 
Delphi 11 Alexandria
 
#33

AW: proceduren (Events) aus Interface

  Alt 9. Sep 2016, 10:36
Also es geht ja wohl darum die implementation (DLL) und den Client sauber zu trennen.
Wir machen das im Prinzip so: (angepasst an Deine Interfaces)

// Client Unit

Delphi-Quellcode:
unit uMagneticClient;

interface

uses
  Windows;

 type
    ISkinMagnetic = interface
    ['{A00CB8B3-8433-4C58-9115-1845B29B3FF0}']
    function GetSnapWidth: Integer;
    procedure SetSnapWidth(const Value: Integer);
    property SnapWidth: Integer read GetSnapWidth write SetSnapWidth;
    function AddMagneticWindow(Handle: HWND; hWndParent: HWND): Boolean;
    function RemoveMagneticWindow(Handle: HWND): Boolean;
    function SetFullWindowDrag(HWND: DWORD; ShowFullWindow: Boolean): Boolean;
  end;

{$IFNDEF MAGNETICDLL} // Ist in den Projectoptionen der Dll definiert
  function SkinMagnetic : ISkinMagnetic; stdcall; external 'Magnetic.dll';
{$ENDIF}

implementation

end.
Delphi-Quellcode:
unit uMagneticDll;

interface

uses
  windows,
  uMagneticClient;


 type
   ISkinMagneticEx = interface(ISkinMagnetic)
    ['{14454F11-1C26-4133-A46E-3271F5A9618B}']
    function zSubclass_Proc(var Wnd: HWND; var Msg: UINT; var wParam: wParam;
      var lParam: lParam): LRESULT;
  end;


implementation

end.


Delphi-Quellcode:
unit uMagnetic;

interface

uses
  Windows,
// SysUtils,
  Messages,
  Classes,
  uMagneticClient,
  uMagneticDll;

type

  TWND_INFO = record
    h_wnd: HWND;
    hWndParent: HWND;
    pOldWinProc: TFNWndProc;
    Glue: Boolean;
  end;

  TMagnetic = class(TInterfacedObject, ISkinMagnetic, ISkinMagneticEx)
    constructor Create;
    destructor Destroy; override;

  private
    FSnapWidth: Integer;
    m_uWndInfo: array of TWND_INFO;
    m_rcWnd: array of TRect;
    m_lWndCount: Integer;
    m_ptAnchor: TPOINT;
    m_ptOffset: TPOINT;
    m_ptCurr: TPOINT;
    m_ptLast: TPOINT;
    lOldSetting: Integer;
    function GetSnapWidth: Integer;
    procedure SetSnapWidth(const Value: Integer);
    procedure pvSizeRect(Handle: HWND; var rcWnd: TRect; lfEdge: Integer);
    procedure pvMoveRect(Handle: HWND; var rcWnd: TRect);
    procedure pvCheckGlueing;
    function pvWndsConnected(const rcWnd1, rcWnd2: TRect): Boolean;
    function pvWndGetInfoIndex(Handle: HWND): Integer;
    function pvWndParentGetInfoIndex(hWndParent: HWND): Integer;
    function zSubclass_Proc(var Wnd: HWND; var Msg: UINT; var wParam: wParam; var lParam: lParam): LRESULT;
    function getWND_INFO(aHandle: HWND; var Wnd_info: TWND_INFO): Boolean;

  public
    function AddMagneticWindow(Handle: HWND; hWndParent: HWND): Boolean;
    function RemoveMagneticWindow(Handle: HWND): Boolean;
    procedure CheckGlueing;
    property SnapWidth: Integer read GetSnapWidth write SetSnapWidth;
    function SetFullWindowDrag(HWND: DWORD; ShowFullWindow: Boolean): Boolean;
  end;

   function SkinMagnetic : ISkinMagnetic; stdcall;

implementation

var
  MagneticWnd: ISkinMagneticEx = nil;

function SubFormWindowProc(Wnd: HWND; Msg: UINT; wParam: wParam; lParam: lParam): LRESULT; stdcall;
begin
  result := MagneticWnd.zSubclass_Proc(Wnd, Msg, wParam, lParam);
end;

 function SkinMagnetic : ISkinMagnetic; stdcall;
 begin
   if MagneticWnd = nil then
    MagneticWnd := TMagnetic.Create;
    result := MagneticWnd as ISkinMagnetic;
 end;
 
 
 initialization

finalization

MagneticWnd := nil;

end.

Die Dll:

Delphi-Quellcode:
library Magnetic;

uses
  uMagneticDll in 'uMagneticDll.pas',
  uMagnetic in 'uMagnetic.pas',
  uMagneticClient in 'uMagneticClient.pas';

{$R *.res}


exports
  skinMagnetic;


begin

end.


Benutzung dann Einfach mit z.b :


Delphi-Quellcode:
 uses uMagneticClient;

  SkinMagnetic.AddMagneticWindow(hWnd1, 0);

Sollte so ohne Problem funktionieren

Fritz
Fritz Westermann
  Mit Zitat antworten Zitat