Changing the dialog font
-
Hi all, How can I change the font of the dialog dynamically. I have tried SetFont from OnInitDialog() function.But it dosen't work. Please help me Thanks in advance Naveen.R nave
1. place the following string somewhere in your "stdafx.h" file: #include 2. override DoModal() function in your dialog class: int CSampleDialog::DoModal() { CDialogTemplate dlt; int nResult; // load dialog template if (!dlt.Load(MAKEINTRESOURCE(CSampleDialog::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; } It may be reasonable to choose a font for your dialog box according to user-specified schemes (those in Control Panel / Display / Appearance). Unfortunately I was unable to find any simple ways to get font settings for the dialog boxes. A possible alternative is to use font settings for icon titles and some related controls (like tree and list controls), that can be retrieved by SystemParametersInfo() function. Here is a simple procedure that returns the face name and the size in points for this font: void GetSystemIconFont(CString& strFontName,int& nPointSize) { LOGFONT lf; // get LOGFONT structure for the icon font SystemParametersInfo(SPI_GETICONTITLELOGFONT,sizeof(LOGFONT),&lf,0); // getting number of pixels per logical inch // along the display height COLOR="#990000"> HDC hDC = ::GetDC(NULL); int nLPixY = GetDeviceCaps(hDC, LOGPIXELSY); ::ReleaseDC(NULL,hDC); // copy font parameters nPointSize = -MulDiv(lf.lfHeight,72,nLPixY); strFontName = lf.lfFaceName; } Ashok Reddy
-
Hi all, How can I change the font of the dialog dynamically. I have tried SetFont from OnInitDialog() function.But it dosen't work. Please help me Thanks in advance Naveen.R nave
1. place the following string somewhere in your "stdafx.h" file: #include 2. override DoModal() function in your dialog class: int CSampleDialog::DoModal() { CDialogTemplate dlt; int nResult; // load dialog template if (!dlt.Load(MAKEINTRESOURCE(CSampleDialog::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; } It may be reasonable to choose a font for your dialog box according to user-specified schemes (those in Control Panel / Display / Appearance). Unfortunately I was unable to find any simple ways to get font settings for the dialog boxes. A possible alternative is to use font settings for icon titles and some related controls (like tree and list controls), that can be retrieved by SystemParametersInfo() function. Here is a simple procedure that returns the face name and the size in points for this font: void GetSystemIconFont(CString& strFontName,int& nPointSize) { LOGFONT lf; // get LOGFONT structure for the icon font SystemParametersInfo(SPI_GETICONTITLELOGFONT,sizeof(LOGFONT),&lf,0); // getting number of pixels per logical inch // along the display height COLOR="#990000"> HDC hDC = ::GetDC(NULL); int nLPixY = GetDeviceCaps(hDC, LOGPIXELSY); ::ReleaseDC(NULL,hDC); // copy font parameters nPointSize = -MulDiv(lf.lfHeight,72,nLPixY); strFontName = lf.lfFaceName; } Ashok Reddy
-
Hi all, How can I change the font of the dialog dynamically. I have tried SetFont from OnInitDialog() function.But it dosen't work. Please help me Thanks in advance Naveen.R nave
Halo Naveen, I think you have not updated your dialog data after setting the font. After you finish setting the font in dialog, do
UpdateData(0);
If the problem is something else, I could give you a small sample code snippet on how to set a font. Please let me know of anything. Regards, Rajesh R. Subramanian You have an apple and me too. We exchange those and We have an apple each. You have an idea and me too. We exchange those and We have two ideas each. -
1. place the following string somewhere in your "stdafx.h" file: #include 2. override DoModal() function in your dialog class: int CSampleDialog::DoModal() { CDialogTemplate dlt; int nResult; // load dialog template if (!dlt.Load(MAKEINTRESOURCE(CSampleDialog::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; } It may be reasonable to choose a font for your dialog box according to user-specified schemes (those in Control Panel / Display / Appearance). Unfortunately I was unable to find any simple ways to get font settings for the dialog boxes. A possible alternative is to use font settings for icon titles and some related controls (like tree and list controls), that can be retrieved by SystemParametersInfo() function. Here is a simple procedure that returns the face name and the size in points for this font: void GetSystemIconFont(CString& strFontName,int& nPointSize) { LOGFONT lf; // get LOGFONT structure for the icon font SystemParametersInfo(SPI_GETICONTITLELOGFONT,sizeof(LOGFONT),&lf,0); // getting number of pixels per logical inch // along the display height COLOR="#990000"> HDC hDC = ::GetDC(NULL); int nLPixY = GetDeviceCaps(hDC, LOGPIXELSY); ::ReleaseDC(NULL,hDC); // copy font parameters nPointSize = -MulDiv(lf.lfHeight,72,nLPixY); strFontName = lf.lfFaceName; } Ashok Reddy
-
Halo Naveen, I think you have not updated your dialog data after setting the font. After you finish setting the font in dialog, do
UpdateData(0);
If the problem is something else, I could give you a small sample code snippet on how to set a font. Please let me know of anything. Regards, Rajesh R. Subramanian You have an apple and me too. We exchange those and We have an apple each. You have an idea and me too. We exchange those and We have two ideas each. -
Thanks ashok..it works. Should i have to overide the Create() function so that the font will change when dialog is created as Modless? nave