Discussion:
Transferring mouse messages & coordinates between controls within a custom control
(too old to reply)
Keke
2006-08-22 11:52:32 UTC
Permalink
Dear All,

I have a custom control, let's call it "MyNewControl" that is a
TCustomControl descendant. I have a Custom Label on it (created in
MyNewControl.Create and freed in MyNewControl.Detstroy), let's call it
"MyLabel", which is a TCustomLabel descendant. I set MyLabel.Parent =
AOwner, which is MyNewControl, in MyLabel.Create (code: self.Parent :=
AOwner as TWinControl).

My point is that I want this MyLabel to ignore all mouse messages and
transfer them to MyNewControl.

For this, I've overridden the WndProc in MyLabel, which looks like
this:

Procedure TMyLabel.WndProc(var Message: TMessage);
var
myMousePoint: TPoint;
begin
if (
(Message.Msg=WM_MOUSEMOVE) or
(Message.Msg=WM_LBUTTONDOWN) or
(Message.Msg=WM_LBUTTONUP) or
(Message.Msg=WM_LBUTTONDBLCLK) or
(Message.Msg=WM_RBUTTONDOWN) or
(Message.Msg=WM_RBUTTONUP) or
(Message.Msg=WM_RBUTTONDBLCLK) or
(Message.Msg=WM_MBUTTONDOWN) or
(Message.Msg=WM_MBUTTONUP) or
(Message.Msg=WM_MBUTTONDBLCLK) or
(Message.Msg=WM_MOUSEWHEEL) or
(Message.Msg=WM_NCMOUSEMOVE) ) then
begin
//the next line WORKS, but provides wrong coordinates to the parent
(different coordinate systems)
//self.Parent.Perform(Message.Msg, Message.WParam, Message.LParam)

//for testing, the next 2 lines WORK, but exactly same problem as
above, provides wrong coordinates to MyNewComponent
//myMousePoint := Point(LOWORD(Message.LParam), Word(Message.LParam
shr 16));
//self.Parent.Perform(Message.Msg, Message.WParam, myMousePoint.X
or (myMousePoint.Y shl 16));

//based on the previous lines, the next 2 lines should convert
MyLabel's coordinates to MyNewControl's coordinates, but Delphi quits,
or shows a "Stack overflow" error message
myMousePoint :=
self.Parent.ScreenToClient(self.ClientToScreen(Point(LOWORD(Message.LParam),
Word(Message.LParam shr 16))));
self.Parent.Perform(Message.Msg, Message.WParam, myMousePoint.X or
(myMousePoint.Y shl 16));
end
else
inherited WndProc(Message);
end;

Please see the commented lines. I tried to convert MyLabel's
coordinates to MyNewControl's coordinates, but this generates a very
nasty "stack overflow" error in the Delphi IDE, if I move the mouse
pointer over MyLabel. If I run the test app, it hangs, with processor
on 100%.

What is happening? It seems that ScreenToClient and ClientToScreen does
something extra I don't know about.

Thank you for your time and ideas in advance!
Keke
Riki Wiki
2006-08-26 06:32:48 UTC
Permalink
Hoi Keke

You need to repost your question on the Borland news server to make
everybody see it and possibly answer your question. Further, this news
group do not officially exist, the group to use is
b.p.d.vcl.components.writing.win32.

How to post to Delphi newsgroups:
<http://delphi.wikia.com/wiki/Delphi_Newsgroups>

Loading...