Re: Reflection problem when changing parent window
- From: Joseph M. Newcomer <newcomer@xxxxxxxxxxxx>
- Date: Wed, 17 Aug 2005 22:50:06 -0400
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
.
- References:
- Reflection problem when changing parent window
- From: Doru K
- Reflection problem when changing parent window
- Prev by Date: Re: GetPixel(...) from the buffer and BITMAPINFOHEADER?
- Next by Date: Re: DLL Locking Window Paints/Messages
- Previous by thread: Re: Reflection problem when changing parent window
- Next by thread: How to add e-mail function into VC++ program?
- Index(es):
Relevant Pages
|