Fons wrote:
>
>>> This works fine:
>>>
>>> procedure TFormTest.WndProc(var Message: TMessage);
>>> begin
>>> inherited;
>>>
>>> if Message.LParam = longint(Label1) then begin
>>> case Message.Msg of
>>> CM_MOUSELEAVE : Label2.Caption := 'CM_MOUSELEAVE';
>>> CM_MOUSEENTER : Label2.Caption := 'CM_MOUSEENTER';
>>> end;
>>> end;
>>> end;
>>>
>>> Until I put Label1 in a TPanel. If I catch WndProc of Label1, instead
>>> of the Form, I can make it work but there must be a better solution.
>>>
>>> I tried Internet but couldn't find a solution (WndProc and controls in
>>> TPanels).
>>
>>
>> You seem to imply there is some sort of problem. But you don't say what
>> it is.
>>
>> Application.OnMessage?
>
>
> The problem is that both "Label2.Caption := ..." are called when Label1
> is directly in the form. But when I move Label1 into a TPanel (that is
> directly in the form), so: a label on top of a panel that is on top of a
> form; then "Label2.Caption := ..." is not called. I made some object
> that makes it work:
>
> THandleMessage = procedure (Sender : TObject; Message : TMessage)
> of object;
>
> constructor TCatchWndMethod.Create(aWinControl: TWinControl;
> aHandleMessage : THandleMessage);
> begin
> WinControl := aWinControl;
> OldWindowProc := WinControl.WindowProc;
> WinControl.WindowProc := WindowProc;
> HandleMessage := aHandleMessage;
> end;
>
> procedure TCatchWndMethod.WindowProc(var Message: TMessage);
> begin
> if Assigned(OldWindowProc) then
> OldWindowProc(Message);
> HandleMessage(WinControl, Message);
> end;
>
> Called with:
>
> TCatchWndMethod.Create(TWinControl(Label1), HandleMessage);
>
> In HandleMessage:
>
> procedure TFormTest.HandleMessage(Sender: TObject; Message: TMessage);
> begin
> if Sender = Label1 then begin
> case Message.Msg of
> CM_MOUSELEAVE : Label2.Caption := 'CM_MOUSELEAVE';
> CM_MOUSEENTER : Label2.Caption := 'CM_MOUSEENTER';
> end;
> end;
> end;
>
> you have to call:
>
> if Sender = Label1 then
>
> instead of:
>
> if Message.LParam = longint(Label1) then
>
> because the latter doesn't work.
>
> In this construction "Label2.Caption := ..." is called when Label1 is
> placed in a TPanel.
>
>> Groetjes,
>> Maarten Wiltink
>
>
> Thanks,
> Fons.
>
A Tlabel is a managed control with in the VCL and has no window of it's
own.
A Tpanel how ever is a windows control and has it's own window so that
means all Tlabel type controls (TGraphic) become a child of that panel.
Tgraphic controls do not receive messaegs from the OS message pump
instead, the parent of the control will send on messages needed to
manage the control..
This type of control can not receive input focus etc.
A TFORM and TPANEL both contain a real windows handle to message
messages from the OS etc..
etc..
That was put in layman's terms ..
--
http://webpages.charter.net/jamie_5"


|