Home > C++, VC++, MFC > Creating a dialog from it’s template!

Creating a dialog from it’s template!

Here is a sample on how to do it…

CDialogTemplate dlgTemplate;
// Load dialog template into memory
dlgTemplate.Load( MAKEINTRESOURCE( IDD_DIALOG_ID ));
// Change font of dialog
dlgTempl.SetFont( _T( "Courier" ), 10 ); 

// Creates and displays a modal dialog from a template in memory
CDialog dlg;
dlg.InitModalIndirect( dlgTemplate.m_hTemplate, 0 );
dlg.DoModal();

What’s the use of this? Well you can change the font of dialog at runtime? Just call dlgTemplate.SetFont. This changes the font of entire dialog. Cool isn’t it!

To use CDialogTemplate include “afxpriv.h”. Microsoft(R) says that this file could be changed in near future, so use with care.

  1. No comments yet.
  1. No trackbacks yet.

Leave a comment