Einzelnen Beitrag anzeigen

nitschchedu

Registriert seit: 24. Mär 2006
300 Beiträge
 
Delphi 7 Professional
 
#5

Re: Windows Message in Klasse

  Alt 26. Okt 2006, 10:58
Habe es jetzt so versucht

Delphi-Quellcode:

unit nduComponent;

interface

uses
  Windows, Messages, SysUtils, Classes, Forms, Dialogs;

type
  TnduWindowHook = function(var Message: TMessage): Boolean of Object;
  TnduOnReceiveUserMessage = procedure(Msg: Cardinal; wParam, lParam: Integer;
    var Handled: Boolean) of object;
  TnduOnReceiveOtherMessage = procedure(var Handled: Boolean) of object;

  TnduComponent = class(TComponent)
    function MessageHook(var Msg: TMessage): Boolean; virtual;
  private
    FHooked: Boolean;
    FOnReceiveUserMessage: TnduOnReceiveUserMessage;

    procedure SetOnReceiveUserMessage(const Value: TnduOnReceiveUserMessage);
  protected
    function DoUserMessage(Msg: TMessage): Boolean; dynamic;
  public
    constructor Create(AOwner: TComponent); override;
    destructor Destroy; override;
  published
    property OnReceiveUserMessage: TnduOnReceiveUserMessage read FOnReceiveUserMessage write SetOnReceiveUserMessage;
  end;


implementation

{ TnduCompoent }

constructor TnduComponent.Create(AOwner: TComponent);
begin
  inherited Create(AOwner);

  FHooked := False;

  if not (csDesigning in ComponentState) then
  begin
    Application.HookMainWindow(MessageHook);
    FHooked := True;
  end;

end;

destructor TnduComponent.Destroy;
begin
  if FHooked then
  begin
    Application.UnhookMainWindow(MessageHook);
  end;

  inherited Destroy;
end;

function TnduComponent.DoUserMessage(Msg: TMessage): Boolean;
begin
  Result := False;

  if Assigned(FOnReceiveUserMessage) then
  begin
    FOnReceiveUserMessage(Msg.Msg, Msg.wParam, Msg.LParam, Result);
  end;
end;

function TnduComponent.MessageHook(var Msg: TMessage): Boolean;
begin
  Result := False;
end;

procedure TnduComponent.SetOnReceiveUserMessage(
  const Value: TnduOnReceiveUserMessage);
begin
  FOnReceiveUserMessage := Value;
end;

end.
doch die NDU_WM_MMFNOTIFY = WM_USER + 1;

kommt nich an
  Mit Zitat antworten Zitat