Owners and Parents Was: Re: [lazarus] Creating Components...
Marc Weustink
weus at quicknet.nl
Fri Aug 13 17:05:58 EDT 1999
At 15:47 13-08-99 -0400, "Jeff Wormsley" <daworm at cdc.net> wrote:
>On 8/13/99, at 9:41 PM, Marc Weustink wrote:
>
>>First I think the window shouldn't be created by then. Create it when it
>>has a parent (it has no graphical function anyhow)
>>But if you have to ....
>>You can change the parent of any window whose hwnd you know to any other
>>parent by the winapi function SetParent:
>>
>>HWND SetParent(
>> HWND hWndChild, // handle of window whose parent is changing
>> HWND hWndNewParent // handle of new parent window
>> );
>
>Ok, that's not a problem then. But, if I shouldn't create the window until
>it has a parent (except perhaps the MainForm???)
Yes it depends on the window style. If is is ws_child (a control is mostly
a child) then this applies. A form is created after is is visible (!)
>then how do I know when the
>parent is set in the Interfaces code?
You don't.
>Does that mean I'll need to implement
>a new LM_xxx message, such as LM_SET_PARENT, and instead of creating the
>window on LM_CREATE,
If I recall it correctly LM_CREATE is sent to the interface to create the
Windows/GTK/? object. You shouldn't get this message before a parent is set.
Looking at delphi, TWinControl
Assigning a parent to control results in the following actions
C.Parent := AParent --> C.SetParent(AParent) --> AParent.InsertControl(C) -->
(1 the parent is invisible) or (2 the parent is visible)
(1) --> AlignControl(C) --> AParent.GetClientRect --> a Handle is needed
--> GetHandle --> HAndleNeeded --> CreateHandle -->
(2) --> AParent.UpdateControlState --> AParent.UpdateShowing -->
CreateHandle --> CreateWnd
I think this behaviour is not different al other platforms (since is is
just a grapical if to the user)
>instead create it on LM_SET_PARENT? Or is that what
>LM_ADDCHILD is for? If that is the case, though, then either what is stored
>in FComponent (currently the window handle) is inappropriate, and it is the
>contents of FComponent that are sent to LM_ADDCHILD if I remember
correctly.
<guessing part>
FComponent was if I remember it (from this list) the HWND of that component.
I guess the LM_CREATE and LM_ADDCHILD were needed by the GTK libs ?
You first create a "Control" with LM_CREATE and then add it to a parent with
LM_ADDCHILD ??
I think if my guessings are right, in a Delphi point of view LM_ADDCHILD
and LM_CREATE are one and the same.
</guessing part>
>
>The interaction between Owner, Parent, the contents of FComponent, and the
>LM_xxx message handling is so many balls to keep in the air at once that I
>find I drop more than I juggle!
:-))
I can imagine. This story took me more than an hour to investigate. I never
bothered about when exactly a window was created upon now.
Marc
More information about the Lazarus
mailing list