Cannot Set Focus to Modeless Dialog w/ DesktopParent

Cannot Set Focus to Modeless Dialog w/ DesktopParent

Post by ratchari » Sun, 26 Feb 2006 14:50:54


In the mainframe I created a hidden modeless dialog which I will show
later:
===================================================================
void CMainFrame::ShowModeless()
{
pDlg = new CModeless;

//make desktop the parent since I don't want it to always be on top
pDlg->Create(IDD_MODELESS, CWnd::GetDesktopWindow());

pDlg->ShowWindow(SW_HIDE);
pDlg->MoveWindow(0, 0, 0, 0);
}
===================================================================

Then I'm going to pop up modal dialogs, each will reference the
modeless dialog and show it. I want the modeless dialog to not always
be on top of the screen so I made the desktop its parent, but I want
modeless dialog to be on top of the modal dialogs when I pop it up. If
I don't make the desktop the parent of the modeless dialog, it always
stays on top of the screen even when I switch program. I'm can't seem
to set the focus of the modeless dialog when the modal dialog pops up.
I tried doing the following:

===================================================================
BOOL CMyModalDialog::OnInitDialog()
{
CDialog::OnInitDialog();
//blah blah blah


((CMainFrame*) AfxGetMainWnd())->pDlg->SetWindowPos(&wndNoTopMost, myx,
myy, mywidth, myheight, SWP_SHOWWINDOW);

((CMainFrame*) AfxGetMainWnd())->pDlg->SetFocus();//This doesn't work

((CMainFrame*) AfxGetMainWnd())->pDlg->BringToTop();//This doesn't work

(CMainFrame*) AfxGetMainWnd())->pDlg->PostMessage(WM_SETFOCUS);//This
doesn't work, maybe I'm not using this one correct
}
===================================================================

Thanks in advance, especially you, AliR, your inputs have been very
useful!
 
 
 

Cannot Set Focus to Modeless Dialog w/ DesktopParent

Post by Galit » Mon, 27 Feb 2006 13:09:45

SetForegroundWindow, have you try it? and try to use
m_pdlgAnyDialog->Create(CAnyDialog::IDD) instead... you know a simple
ShowWindow(SW_SHOW) should do the trick