?
Solved

How to handle parental messages

Posted on 2000-02-10
9
Medium Priority
?
208 Views
Last Modified: 2010-04-04
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...
0
Comment
Question by:Aleq
  • 3
  • 2
  • 2
  • +2
9 Comments
 
LVL 12

Expert Comment

by:rwilson032697
ID: 2509571
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
 
LVL 17

Expert Comment

by:inthe
ID: 2509638
listening..
0
 
LVL 1

Expert Comment

by:rpo
ID: 2509656
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
Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

 

Author Comment

by:Aleq
ID: 2510882
rwilson: I know this solution, but I need to handle WM_NCHITTEST from component placed on that form.
0
 
LVL 6

Expert Comment

by:Jaymol
ID: 2510923
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
 
LVL 12

Expert Comment

by:rwilson032697
ID: 2512704
Aleq: The point is that you do just the same thing in your component (the handling of the message, that is).

Cheers,
Raymond.
0
 

Author Comment

by:Aleq
ID: 2512913
rwilson - I tried it. Handling WM_NCHITTEST in component was very interesting - it allowed me to resize the component itself, not parental form .....
0
 
LVL 1

Accepted Solution

by:
rpo earned 800 total points
ID: 2513198
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
 

Author Comment

by:Aleq
ID: 2539850
Can you give me the whole TEnhancedForm ? I've tried this code, but It made some problems....
0

Featured Post

[Webinar] Kill tickets & tabs using PowerShell

Are you tired of cycling through the same browser tabs everyday to close the same repetitive tickets? In this webinar JumpCloud will show how you can leverage RESTful APIs to build your own PowerShell modules to kill tickets & tabs using the PowerShell command Invoke-RestMethod.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
How to fix display issue, screen flickering issue when I plug in power cord to the machine. Before I start explaining the solution lets check out once the issue how it looks like after I connect the power cord. most of you also have faced this…
There may be issues when you are trying to access Outlook or send & receive emails or due to Outlook crash which leads to corrupt or damaged PST file. To eliminate the corruption from your PST file, you need to repair the corrupt Outlook PST file. U…
Suggested Courses

593 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question