How to catch the moment when the parent control has been resized?

前端 未结 5 439
-上瘾入骨i
-上瘾入骨i 2021-01-20 18:58

I have a visual component derived from TWinControl. I need to do some work in my component when its parent control has been resized. In general case, the \"Align\" property

5条回答
  •  迷失自我
    2021-01-20 20:02

    Yes, Andrew, I think attaching your component to parent's message loop (subclassing it) is the way to go. For that you can use TControl.WindowProc property. The doc explains that you have to save the original and restore it later (in the destructor of your component) and also to pass the messages to the original handler, ie your replacement should look like

    procedure TMyComponent.SubclassedParentWndProc(Var Msg: TMessage);
    begin
       FOldParentWndProc(Msg);
       if(Msg.Message = WM_SIZE)then begin
          ...
       end; 
    end;
    

    If you want to do it "old shool" way, use the SetWindowLongPtr API with GWLP_WNDPROC but AFAIK the WindowProc was introduced exactly for the reason to make it easier to subclass components, ie there is nothing wrong using it.

提交回复
热议问题