Keke
2006-08-22 11:52:32 UTC
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
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