Click here to Skip to main content
15,174,448 members
Please Sign up or sign in to vote.
3.40/5 (2 votes)
Hi friends,

I am stuck at a small problem. I am creating a font dialog using domodal method. But after creation this dialog is popup at the backside of other side. Can anybody tell me how to popup that dialog in front of other one. My code is as below:
CFontDialog			 m_OTheFontDialog;	
FontFamily*		pOFontFamily = NULL;
	m_OTheFontDialog.m_cf.Flags |= CF_TTONLY;

	if(m_OTheFontDialog.DoModal() == IDOK)
		m_SFontInformation.lfQuality = ANTIALIASED_QUALITY;
		m_crTextColor = m_OTheFontDialog.GetColor();

			iFontStyle = iFontStyle | FontStyleBold;

			iFontStyle = iFontStyle | FontStyleItalic;

			iFontStyle = iFontStyle | FontStyleStrikeout;

			iFontStyle = iFontStyle | FontStyleUnderline;

		if(!wcscmp(m_SFontInformation.lfFaceName, _T("")))
			return false;

		pOFontFamily = new FontFamily(m_SFontInformation.lfFaceName);
                m_pOBrush = new SolidBrush(Color(255, GetRValue(m_crTextColor), GetGValue(m_crTextColor), GetBValue(m_crTextColor)));
		m_pOTheFont = new Font(pOFontFamily, (float)ulFontHeight, iFontStyle, UnitPixel);

Please help me resolve this issue.

You can use CWnd::SetWindowPos I would say, take a look: CWnd::SetWindowPos[^] :

m_pMainWnd->SetWindowPos(&CWnd:: wndTopMost, 0,0,0,0,SWP_NOMOVE|SWP_NOSIZE|SWP_SHOWWINDOW);
Vaibhav_J_Jaiswal 8-Aug-13 9:19am
It is not work in the case of domodal(). The object of dialog is created after calling domodal. So before domodal the exe is crashed because of null dialog object and after the domodal the dialog is already popup. So no any chance to call the above method. Any other way for this?
Try setting the parent of the dialog to the other window, the way you have created m_OTheFontDialog the parent is NULL which is the desktop window.

I suspect that is why it appears behind at the moment because you have m_OtheFontDialog.pParentWnd = NULL effectively

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900