A Journey 2 Eternity

Change Default Dialog Font of CDialog

Posted on: December 31, 2007

Sometimes it is desirable to change the default font specified in dialog templates (usually “MS Sans Serif”, 8 pts.) at runtime (dynamically). For example, you may want to increase the font size to make it more readable under higher screen resolutions. MFC library contains a class CDialogTemplate, that serves exactly this purpose, but Microsoft has not bothered to include its description in standard MFC reference. This is how you can use this class in your code:

Override DoModal() function in your dialog class:

int CSimpleDialog::DoModal()
{
	CDialogTemplate dlt;
	int nResult;

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

	// set your own font, for example “Arial”, 10 pts.
	dlt.SetFont(“Arial”, 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;
	InitModalIndirect(pdata);

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

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

	return nResult;
}
Advertisements

2 Responses to "Change Default Dialog Font of CDialog"

Thank you

But Using this We can Set only Font Name and Size what about color… I want to change Color to white.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Pages

Categories

December 2007
M T W T F S S
« Nov   Mar »
 12
3456789
10111213141516
17181920212223
24252627282930
31  

Blog Stats

  • 27,176 hits
%d bloggers like this: