Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Set window's owner

Status
Not open for further replies.

apatterno

Programmer
Nov 26, 2002
368
US
Hi, is there any way to set a window's owner (OWNER, not PARENT) after it has been created?

When I say "Owner" I am referring to [tt]::GetWindow[/tt]'s concept of "ownership".

Any help would be helpful. Thanks
 
Your question is not clear. I do not understand the distinction.

-pete
 
Sorry... what I should have been more specific about is:

As the MSDN states:

"Being owned places several constraints on a window.
(1) An owned window is always above its owner in the z-order.
(2) The system automatically destroys an owned window when its owner is destroyed.
(3) An owned window is hidden when its owner is minimized."


I am trying to create a modeless dialog in MFC, but when i do, it has those behaviors, which are undesired.

My code to create the dialog is as follows:

[tt]CDialog::Create(IDD, NULL);[/tt]

The unfortunate problem with this is that somewhere in [tt]DLGCORE.CPP[/tt] lies the code

[tt]if (pParentWnd == NULL)
pParentWnd = AfxGetMainWnd();[/tt]

Is there a way to change this after the dialog has been created, so that the dialog doesn't behave as mentioned above.

Help is helpful, thanks in advance.
 
Ok so we are talking about the "parent" window and you want to change in dynamically.

The bottom line is that i have never had the need to do that. It makes me curious as to what your criteria is for needing to change the parent window.

It would certainly be possible to write a function in your dialog class that results in changing the assignment to the pParentWnd member of your class, however i would be dubious that the window subsystem would recognize the change in any meaninful way. At worst it might produce undesirable effects such as program termination.

-pete
 
Answer:
(in case anyone else was following the thread)

Well, after a bit more research into the innards of MFC, I found the undocumented function [tt]CWnd::CreateDlg(LPCTSTR lpszTemplateName, CWnd* pParentWnd)[/tt]. I think that basically this does the same thing as [tt]CDialog::Create[/tt], except that it lets you pass [tt]NULL[/tt] for [tt]pParentWnd[/tt]. At least that's what I assume, based on the results I've seen in my program.

>> It makes me curious as to what your criteria is for needing to change the parent window.

I thought I needed to change the parent window in order to set it to [tt]NULL[/tt], since [tt]CDialog::Create[/tt] is hardcoded to set the parent window to [tt]AfxGetMainWnd()[/tt] if you pass [tt]NULL[/tt] as an argument. But this [tt]CWnd::CreateDlg[/tt] function seems to work.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top