Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Changing the dialog font

Changing the dialog font

Scheduled Pinned Locked Moved C / C++ / MFC
helpquestion
7 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • N Offline
    N Offline
    Naveen
    wrote on last edited by
    #1

    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

    A R 3 Replies Last reply
    0
    • N Naveen

      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

      A Offline
      A Offline
      ashokbngr
      wrote on last edited by
      #2

      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

      1 Reply Last reply
      0
      • N Naveen

        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

        A Offline
        A Offline
        ashokbngr
        wrote on last edited by
        #3

        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

        N 1 Reply Last reply
        0
        • N Naveen

          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

          R Offline
          R Offline
          Rajesh R Subramanian
          wrote on last edited by
          #4

          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.

          N 1 Reply Last reply
          0
          • A ashokbngr

            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

            N Offline
            N Offline
            Naveen
            wrote on last edited by
            #5

            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

            A 1 Reply Last reply
            0
            • R Rajesh R Subramanian

              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.

              N Offline
              N Offline
              Naveen
              wrote on last edited by
              #6

              Can u show me the sample? I have tried updateData(0). it dosen't work nave

              1 Reply Last reply
              0
              • N Naveen

                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

                A Offline
                A Offline
                ashokbngr
                wrote on last edited by
                #7

                Yes.. Override create for modeles dialog. Try that and revert me back whether it works fine or not. Thanks & Regards, Ashok

                1 Reply Last reply
                0
                Reply
                • Reply as topic
                Log in to reply
                • Oldest to Newest
                • Newest to Oldest
                • Most Votes


                • Login

                • Don't have an account? Register

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • World
                • Users
                • Groups