Thema: Delphi WindowProc einer Klasse?

Einzelnen Beitrag anzeigen

Benutzerbild von retnyg
retnyg

Registriert seit: 11. Feb 2005
193 Beiträge
 
#6

Re: WindowProc einer Klasse?

  Alt 1. Feb 2006, 21:52
Delphi-Quellcode:
// code ist aus flocke's sizegrip unit ausgeliehen, thx nochma :P
type
  TWndProc = function (hWnd: HWND; Msg: UINT; wParam: WPARAM; lParam: LPARAM): LRESULT; stdcall;

var
  OldWndProc: TWndProc;

function NewWndProc(hWnd: HWND; Msg: UINT; wParam: WPARAM; lParam: LPARAM): LRESULT; stdcall;

  function CallOld: LRESULT;
  begin
    Result := CallWindowProc(@OldWndProc, hWnd, Msg, wParam, lParam);
  end;

begin
  // Result := DefWindowProc(hWnd, Msg, wParam, lParam); // standardWndProc aufrufen

  case Msg of
    WM_DESTROY: begin
      SetWindowLong(hWnd, GWL_WNDPROC, LongInt(@OldWndProc));
      result := callold;
    end;

    WM_PAINT: Begin
      // dein code ^.^
    end;

    else
      Result := CallOld;
  end;
end;

procedure RemoveMsgHook(hWnd: HWND);
begin
  if @OldWndProc <> nil then
    SetWindowLong(hWnd, GWL_WNDPROC, LongInt(@OldWndProc));
end;

procedure SetMsgHook(hWnd: HWND);
begin
  RemoveMsgHook(hWnd);
  OldWndProc := TWndProc(Pointer(GetWindowLong(hWnd, GWL_WNDPROC)));
  SetWindowLong(hWnd, GWL_WNDPROC, LongInt(@NewWndProc));
end;
  Mit Zitat antworten Zitat