Re: Reflection problem when changing parent window

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



Generally, if you ever use SetParent, be prepared for immense amounts of grief. It kind of
sort of does something resemblinjg what you think it might do, but overall its use is just
an invitation to disaster and it should be avoided. Historically, this API is known to be
a troublemaker, and everyone who tries to use it ends up with questions that sound like
yours.

A more serious question is why you need to destroy the parent and then have the window
free-floating. Architectures like this should make you nervous. There's something wrong
with the design of a program that requires this sort of weird behavior, and you need to
rethink what you are doing.
joe
On 17 Aug 2005 04:12:46 -0700, "Doru K" <dorutzu.teste@xxxxxxx> wrote:

> Hi,
>
> I would really appreciate if someone could give me a hand on this. I
>have a class derived from CTreeCtrl. In this class, I have a method to
>deal with the selection change event:
> ON_NOTIFY_REFLECT(TVN_SELCHANGED, OnTvnSelchanged)
>
> At a certain moment, I instantiate an object like this:
> m_pTree = new CMyTreeCtrl();
> m_pTree->Create(TVS_HASBUTTONS | TVS_HASLINES | TVS_LINESATROOT |
>TVS_EDITLABELS | TVS_SHOWSELALWAYS | WS_BORDER | WS_CHILD | WS_TABSTOP
>| WS_VISIBLE, CRect(0, 0, 100, 100), this, IDC_TM_FOLDER_TREE);
>
> where "this" is a WS_CHILD window as well.
>
> After a while, I have to destroy the parent window, but I want to keep
>everything in the tree intact, so what I do, before destroying the
>parent is:
> m_pTree->ShowWindow(SW_HIDE);
> m_pTree->SetParent(CWnd::FromHandle(GetForegroundWindow()));
>
> Then, I will get a new WS_CHILD window and set this new window as my
>object's parent.
>
> All looks ok in the new window (the tree is all ok), but I don't get
>any "selection changed" events. I don't know where these events go, or
>what happens to them. I suspect it's something related to changing the
>parent, but... :(
>
> Thanks for any help or ideas,
> Doru K.
Joseph M. Newcomer [MVP]
email: newcomer@xxxxxxxxxxxx
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm
.



Relevant Pages

  • Re: Help in creating dialog based application
    ... you wouldn't want to destroy them; it is more likely you'd want to just hide ... But the way you would notify the parent dialog to do anything is PostMessage ... again some button to navigate back to main dialog/student list/course ... dialog as parent but how i will inform the parent window to distroy ...
    (microsoft.public.vc.mfc)
  • Re: Reflection problem when changing parent window
    ... > After a while, I have to destroy the parent window, but I want to keep ... > everything in the tree intact, so what I do, before destroying the ...
    (microsoft.public.vc.mfc)
  • Re: Help in creating dialog based application
    ... you wouldn't want to destroy them; it is more likely you'd want to just hide ... But the way you would notify the parent dialog to do anything is PostMessage ... dialog as parent but how i will inform the parent window to distroy ... dialog which will create modeless dialogs so when i switch to some ...
    (microsoft.public.vc.mfc)
  • Re: Capture Window Closure and prevent it.
    ... Is there anyway to access a parents messages from the child? ... window to be closed. ... to destroy yourself or not. ... to control the parent window's lifetime, ...
    (microsoft.public.vc.atl)
  • Re: Does CreateParented destroys children automatically ????
    ... > When we create a child window using Create method, ... > are automatically destroyed when the parent is destrioyed. ... The 'Parent' is the control wrapping the containing window. ... When you destroy the parent, children are expected to be left parentless ...
    (comp.lang.pascal.delphi.misc)