Example #1
0
int EditBoardText::DoModal() 
{
   CDialogTemplate dlt;
   int             nResult;

   // load dialog template
   if (!dlt.Load(MAKEINTRESOURCE(EditBoardText::IDD))) return -1;

   // set your own font, for example "Arial", 10 pts. 
   dlt.SetFont(m_strFaceName, 10);
	
   // get pointer to the modified dialog template
   LPSTR pdata = (LPSTR)GlobalLock(dlt.m_hTemplate);
	
   // let MFC know that you are using your own template
   m_lpszTemplateName = NULL;
   m_hDialogTemplate  = NULL;

   InitModalIndirect(pdata);

   // display dialog box
   nResult = CDialog::DoModal();

   // unlock memory object
   GlobalUnlock(dlt.m_hTemplate);

   return nResult;	
}
Example #2
0
void BaseDialog::SetFont(CDialogTemplate& dlgTemplate)
{
  NONCLIENTMETRICS ncm;
  ::ZeroMemory(&ncm,sizeof ncm);
  ncm.cbSize = sizeof ncm;
  ::SystemParametersInfo(SPI_GETNONCLIENTMETRICS,sizeof ncm,&ncm,0);

  OSVERSIONINFO osvi;
  osvi.dwOSVersionInfoSize = sizeof osvi;
  ::GetVersionEx(&osvi);
  WORD fontSize = (osvi.dwMajorVersion < 6) ? 8 : 9;

  dlgTemplate.SetFont(ncm.lfMessageFont.lfFaceName,fontSize);
}
INT_PTR CWaterAttachment::DoModal()
{
	// TODO: Add your specialized code here and/or call the base class
	CDialogTemplate dlt;
	int nResult;
	// load dialog template
	if (!dlt.Load(MAKEINTRESOURCE(CWaterAttachment::IDD))) return -1;
	// set the font, for example "Arial", 10 pts.
	dlt.SetFont("Arial", 8);
	// get pointer to the modified dialog template
	LPSTR pdata = (LPSTR)GlobalLock(dlt.m_hTemplate);
	// let MFC know that you are using your own template
	m_lpszTemplateName = NULL;
	InitModalIndirect(pdata);
	// display dialog box
	nResult = CDialog::DoModal();
	// unlock memory object
	GlobalUnlock(dlt.m_hTemplate);
	return nResult;
}
Example #4
0
INT_PTR CCustomDialog::DoModal(void)
{
	// get the custom font information
	CUpdateItApp* pApp = DYNAMIC_DOWNCAST(CUpdateItApp, AfxGetApp());
	CString strFaceName = pApp->GetConfigString(SZ_ARG_FONT_FACENAME, SZ_REGK_FONT, SZ_REGV_FONT_FACENAME);
	WORD wFontSize = LOWORD(pApp->GetConfigUInt(SZ_ARG_FONT_POINTSIZE, SZ_REGK_FONT, SZ_REGV_FONT_SIZE, 0));

	if (!strFaceName.IsEmpty() && wFontSize > 0)
	{
		// try to load dialog template
		CDialogTemplate dlgtRes;
		if (!dlgtRes.Load(m_lpszTemplateName))
		{
			return (-1);
		}

		// set specified custom font
		dlgtRes.SetFont(strFaceName, wFontSize);

		// get pointer to the modified dialog template
		DLGTEMPLATE* pTemplate = reinterpret_cast<DLGTEMPLATE*>(::GlobalLock(dlgtRes.m_hTemplate));

		// try to load coresponding DLGINIT resource (if any)
		HGLOBAL hResData = NULL;
		void* pvDlgInit = NULL;
		HINSTANCE hResInst = AfxGetResourceHandle();
		HRSRC hResInfo = ::FindResource(hResInst, m_lpszTemplateName, RT_DLGINIT);
		if (hResInfo != NULL)
		{
			hResData = ::LoadResource(hResInst, hResInfo);
			ASSERT(hResData != NULL);
			pvDlgInit = ::LockResource(hResData);
			ASSERT(pvDlgInit != NULL);
		}

		// let MFC know that we are using our own template
		LPCTSTR pszTemplateName = m_lpszTemplateName;
		m_lpszTemplateName = NULL;
		InitModalIndirect(pTemplate, NULL, pvDlgInit);

		// display dialog box
		INT_PTR nResult = __super::DoModal();

		if (hResData != NULL)
		{
			::UnlockResource(hResData);
			::FreeResource(hResData);
		}

		// unlock memory object
		::GlobalUnlock(dlgtRes.m_hTemplate);

		m_lpszTemplateName = pszTemplateName;
		m_lpDialogTemplate = NULL;

		return (nResult);
	}
	else
	{
		// no custom font is specified
		return (__super::DoModal());
	}
}