How to handle parental messages

Now when one expert answered my question about hooking parental messages, I need help again. I need to handle and MODIFY a result of WM_NCHITTEST message. And I need to do this from hook. The idea was: user places component onto the form and the component takes the form's WM_NCHITTEST do decide what's caption, what's resizable border etc...
AleqAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

rwilson032697Commented:
Here's an example os using NCHITTEST to drag a form by clicking any where in it. It fools windows into thinking the caption has been clicked on.

This should show you all you need...

Cheers,

Raymond.

unit Unit1;

interface

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

type
  TForm1 = class(TForm)
  private
    { Private declarations }
  public
    { Public declarations }
    procedure WMNCHitTest(var M: TWMNCHitTest); message WM_NCHITTEST;
  end;

var
  Form1: TForm1;

implementation

{$R *.DFM}

procedure TForm1.WMNCHitTest(var M: TWMNCHitTest);
begin
  inherited;
 {If the client has been clicked, make Windows believe}
 {it was the caption bar that was clicked on}
  if  M.Result = htClient then
    M.Result := htCaption;
end;


end.
0
intheCommented:
listening..
0
rpoCommented:
I think it's easier to do what you want using subclassing instead of hooks.

I would do this with SetWindowLong with GWL_WNDPROC parameter.

You steel need that MakeHookInstance function to get an address for new window procedure :)

Roman.
0
Cloud Class® Course: Microsoft Office 2010

This course will introduce you to the interfaces and features of Microsoft Office 2010 Word, Excel, PowerPoint, Outlook, and Access. You will learn about the features that are shared between all products in the Office suite, as well as the new features that are product specific.

AleqAuthor Commented:
rwilson: I know this solution, but I need to handle WM_NCHITTEST from component placed on that form.
0
JaymolCommented:
Can I just ask, so I get it straight in my head.....are you saying you wish to write a component that handles the form's windows messages?  If so, I've got code for that.  Let me know.

John.
0
rwilson032697Commented:
Aleq: The point is that you do just the same thing in your component (the handling of the message, that is).

Cheers,
Raymond.
0
AleqAuthor Commented:
rwilson - I tried it. Handling WM_NCHITTEST in component was very interesting - it allowed me to resize the component itself, not parental form .....
0
rpoCommented:
Aleq, try this code (it actually works in a component which limits form's size):

--------------
constructor TEnhancedForm.Create(
  AOwner: TComponent);
var
  i: word;
  FormSizeLimitCount: byte;
  LanguageManager : TMLManager;
begin
  inherited Create(AOwner);
  if (AOwner is TForm) then
    with (AOwner as TForm) do
    begin
      FFormHandle := Handle;
      FOldWndHandler :=
        Pointer(GetWindowLong(
          FFormHandle,GWL_WNDPROC));
       FWndHandlerPtr:=
        MakeObjectInstance(
          NWndProc);

      if FWndHandlerPtr = nil then
        raise EOutOfResources.
          Create('Windows
            resources exhausted');

      SetWindowLong(
        FFormHandle,GWL_WNDPROC,         Longint(FWndHandlerPtr));
    end;
end;

procedure TEnhancedForm.NWndProc ( var Message : TMessage );
begin
  with Message do
  begin
    case Msg of
      WM_NCHITTEST : ....

    end;
  end;
end;
--------------

The MakeObjectInstance function defined in Forms.pas (and it possibly replaces the MakeHookInstance i sent you before).

Roman.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
AleqAuthor Commented:
Can you give me the whole TEnhancedForm ? I've tried this code, but It made some problems....
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Delphi

From novice to tech pro — start learning today.