winapi - Creating multiple dialogs in an MFC app with no main Window, they become children of each other -
(title updated) following on this question, have clearer picture what's going on...
i have mfc application no main window, exposes api create dialogs. when call of these methods repeatedly, dialogs created parented each other instead of being parented desktop... have no idea why.
but anyway after creation, unable change parent null or cwnd::getdesktopwindow()... if call setparent followed getparent, nothing has changed.
so apart weird question of why windows magically parenting each dialog last 1 created, there i'm missing able set these windows children of desktop?
updated: have found reason this, not solution. dialog constructor, end in:
bool cdialog::createindirect(lpcdlgtemplate lpdialogtemplate, cwnd* pparentwnd, void* lpdialoginit, hinstance hinst) { assert(lpdialogtemplate != null); if (pparentwnd == null) pparentwnd = afxgetmainwnd(); m_lpdialoginit = lpdialoginit; return createdlgindirect(lpdialogtemplate, pparentwnd, hinst); }
note: if (pparentwnd == null)pparentwnd = afxgetmainwnd();
the call-stack dialog constructor looks this:
- mfc80d.dll!cdialog::createindirect(const dlgtemplate * lpdialogtemplate=0x005931a8, cwnd * pparentwnd=0x00000000, void * lpdialoginit=0x00000000, hinstance__ * hinst=0x00400000)
- mfc80d.dll!cdialog::createindirect(void * hdialogtemplate=0x005931a8, cwnd * pparentwnd=0x00000000, hinstance__ * hinst=0x00400000)
- mfc80d.dll!cdialog::create(const char * lpsztemplatename=0x0000009d, cwnd * pparentwnd=0x00000000)
- mfc80d.dll!cdialog::create(unsigned int nidtemplate=157, cwnd * pparentwnd=0x00000000)
- myapp.exe!cmydlg::cmydlg(cwnd * pparent=0x00000000)
running in debugger, if manually change pparentwnd 0 in cdialog::createindirect, works fine... how stop happening in first place?
some thoughts:
first, passing null parent window whole way through chain. becomming non null when mfc tries find applications main window.
as see have 2 mitigations:
- create cwnd desktop window. cwnd::getdesktopwindow give non null window use parent window inhibit afxgetmainwnd call.
- or trace afxgetmainwnd, find out reading main window from, , see if there setting prevent finding dialog window.
on final note. mfc terminology unfortunate :- on windows, child windows have parent windows. popup or dekstop windows have owner windows. createwindow takes single parameter accepts owner, or parent of window being created. distinction important because while parent window can changed, owner cannot. setparent not change owner window popup or overlapped window.
Comments
Post a Comment