Watch, Follow, &
Connect with Us

For forums, blogs and more please visit our
Developer Tools Community.


Welcome, Guest
Guest Settings
Help

Thread: Mouse messages from windows



Permlink Replies: 6 - Last Post: Dec 17, 2017 3:24 AM Last Post By: Lex Dean
Lex Dean

Posts: 132
Registered: 3/26/07
Mouse messages from windows
Click to report abuse...   Click to reply to this thread Reply
  Posted: Dec 13, 2017 9:34 PM
I'm not getting mouse messages passed to child VCL objects

I have a TCustomControl descendant parent that contains child VCL objects that are TGraphicControl descendants
Mouse up and down events are working well in TCustomControl but do not pass the events through any of it's Children objects.
TCustomControl receives from windows WMLButtonDown, but only when the below code is in create method -

const
GridStyle = [csCaptureMouse, csOpaque, csDoubleClicks];
begin
inherited Create(AOwner);
if NewStyleControls then
ControlStyle := GridStyle else
ControlStyle := GridStyle + [csFramed];

ControlStyle is not available in TGraphicControl, So how do I tell windows to send csCaptureMouse messages to a TGraphicControl object.
or have I got to look at another path to get a result?
Peter Below

Posts: 1,227
Registered: 12/16/99
Re: Mouse messages from windows
Click to report abuse...   Click to reply to this thread Reply
  Posted: Dec 13, 2017 10:56 PM   in response to: Lex Dean in response to: Lex Dean
Lex Dean wrote:

I'm not getting mouse messages passed to child VCL objects

I have a TCustomControl descendant parent that contains child VCL
objects that are TGraphicControl descendants Mouse up and down events
are working well in TCustomControl but do not pass the events through
any of it's Children objects. TCustomControl receives from windows
WMLButtonDown, but only when the below code is in create method -

const
GridStyle = [csCaptureMouse, csOpaque, csDoubleClicks];
begin
inherited Create(AOwner);
if NewStyleControls then
ControlStyle := GridStyle else
ControlStyle := GridStyle + [csFramed];

ControlStyle is not available in TGraphicControl, So how do I tell
windows to send csCaptureMouse messages to a TGraphicControl object.
or have I got to look at another path to get a result?

TGraphicControl descendent do not exist as far as Windows is concerned
since they do not have window handles. It is the task of the parent
TwinControl to pass mouse messages on to its TGraphicControl children.
The VCL TWinControl class contains the appropriate code; if you
intercept the mouse messages in your custom control and cannot pass
them on to the inherited message handler for some reason you will have
to do this yourself. Look at the TWinControl source code in
vcl.controls.pas.

--
Peter Below
TeamB
Lex Dean

Posts: 132
Registered: 3/26/07
Re: Mouse messages from windows
Click to report abuse...   Click to reply to this thread Reply
  Posted: Dec 14, 2017 2:59 AM   in response to: Peter Below in response to: Peter Below
Mouse messages are part of TControl that has WMLButtonDown message and TGraphicControl is a descendant of TControl
and that should be passed through to WMLButtonDown but windows is not delivering it to WMLButtonDown.
is this because windows messaging has no HWND handle?

so how do I write this message

procedure MyObjectr.MouseDown(Button: TMouseButton; Shift: TShiftState; X,
Y: Integer);
Var I: Integer;
Control: TControl;
R: TRect;
begin
inherited;
Control := ControlAtPos(Point(X, Y), False, True);
R := Control.BoundsRect;
X := X - R.Left;
Y := Y - R.Top;
// sendmessage needs a HWND handle that TGraphicControl does not have
I := Lo(X) or hi(Y);
Perform(WM_LBUTTONDOWN, 0, I);
// is this going to do the job?
end;
Remy Lebeau (Te...


Posts: 9,447
Registered: 12/23/01
Re: Mouse messages from windows [Edit]
Click to report abuse...   Click to reply to this thread Reply
  Posted: Dec 14, 2017 2:25 PM   in response to: Lex Dean in response to: Lex Dean
Lex Dean wrote:

Mouse messages are part of TControl that has WMLButtonDown message
and TGraphicControl is a descendant of TControl and that should be
passed through to WMLButtonDown

The VCL handles that automatically for you.

but windows is not delivering it to WMLButtonDown.

is this because windows messaging has no HWND handle?

Yes, Windows doesn't know anything about graphical controls, so it
can't send message to them directly. The Parent control has to forward
messages to graphical children as needed.

so how do I write this message

You don't have to write anything. The functionality is already built in
to the VCL.

For instance, if you study the source code for TPanel (a
TCustomControl), it doesn't handle mouse messages directly, and yet its
children, windowed and graphical alike, receive mouse messages just
fine.

The forwarding of mouse messages to graphical children is handled by
TWinControl.IsControlMouseMsg(), which is called by
TWinControl.WndProc() when processing mouse messages to the parent
window.

You have to mess around with default message handling to screw this up.
What does your component actually do?

--
Remy Lebeau (TeamB)
Lex Dean

Posts: 132
Registered: 3/26/07
Re: Mouse messages from windows [Edit]
Click to report abuse...   Click to reply to this thread Reply
  Posted: Dec 14, 2017 3:26 PM   in response to: Remy Lebeau (Te... in response to: Remy Lebeau (Te...
Remy Lebeau (TeamB) you are so correct

graphical control children are buttons
The WMLButtonDown is not getting to it children because of what you just said
But WMLButtonUp is working just fine
So I could have just fixed the screw up in the code in the parent TCustomControl descendant I had made

This should have been a update in Delphi 7 for all to use than getting mucked around by bad code.
Remy Lebeau (Te...


Posts: 9,447
Registered: 12/23/01
Re: Mouse messages from windows [Edit]
Click to report abuse...   Click to reply to this thread Reply
  Posted: Dec 14, 2017 3:53 PM   in response to: Lex Dean in response to: Lex Dean
Lex Dean wrote:

graphical control children are buttons
The WMLButtonDown is not getting to it children because of what you
just said

What I said is that messages would not reach the children if the parent
is interferring with default message handling. Are you actually doing
that?

But WMLButtonUp is working just fine

In the parent, or in the children?

So I could have just fixed the screw up in the code in the parent
TCustomControl descendant I had made

And what screwup did you make exactly?

--
Remy Lebeau (TeamB)
Lex Dean

Posts: 132
Registered: 3/26/07
Re: Mouse messages from windows [Edit]
Click to report abuse...   Click to reply to this thread Reply
  Posted: Dec 14, 2017 5:11 PM   in response to: Remy Lebeau (Te... in response to: Remy Lebeau (Te...
I wrote this code to fix the problem and override TCustomControl now, so all mouse events are working correctly.
This is a major update to WMLButtonDown and is comparable to WMLButtonUp that works
Now both work fine as they should have been from the beginning.

In fact the problem became to great I simply made a Boolean option to send a WMLButtonDown message to all its children
with correct mouse positioning.
Legend
Helpful Answer (5 pts)
Correct Answer (10 pts)

Server Response from: ETNAJIVE02