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 Dialog Font Programmatically

Changing Dialog Font Programmatically

Scheduled Pinned Locked Moved C / C++ / MFC
helpquestionlearning
3 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.
  • Y Offline
    Y Offline
    yoshibebe
    wrote on last edited by
    #1

    Hi, I am trying to change the dialog font programmatically. The dialog right now is created using a Resource file, and the font size and face is hard-coded. I would like to be able to change the font face and size in the OnInitDialog() function. So far this is what I have: HFONT hFont; LOGFONT lf; CFont pFont; short int fRedraw= FALSE; memset(&lf, 0, sizeof(LOGFONT)); hFont = (HFONT) GetStockObject( SYSTEM_FONT ); GetObject(hFont, sizeof(lf), &lf); pFont.CreateFontIndirect(&lf); this->SetFont(&pFont, true); SendMessageToDescendants(WM_SETFONT, (WPARAM)pFont.m_hObject, MAKELONG ((WORD) fRedraw, 0), TRUE); This is changing the font size and face for the CONTROLS of the dialog. However, it does not change anything elose besides that. I tried to do a this->SetFont, however, this does not help. I need the dialog itself to be resized accordingly, and also regular CText. When the font is changed in the resource file, I notice that the dialog size itself changes, however, this is not happening when I call SetFont or send a WM_SETFONT message. Can anyone help me? Thanks!!!

    S 1 Reply Last reply
    0
    • Y yoshibebe

      Hi, I am trying to change the dialog font programmatically. The dialog right now is created using a Resource file, and the font size and face is hard-coded. I would like to be able to change the font face and size in the OnInitDialog() function. So far this is what I have: HFONT hFont; LOGFONT lf; CFont pFont; short int fRedraw= FALSE; memset(&lf, 0, sizeof(LOGFONT)); hFont = (HFONT) GetStockObject( SYSTEM_FONT ); GetObject(hFont, sizeof(lf), &lf); pFont.CreateFontIndirect(&lf); this->SetFont(&pFont, true); SendMessageToDescendants(WM_SETFONT, (WPARAM)pFont.m_hObject, MAKELONG ((WORD) fRedraw, 0), TRUE); This is changing the font size and face for the CONTROLS of the dialog. However, it does not change anything elose besides that. I tried to do a this->SetFont, however, this does not help. I need the dialog itself to be resized accordingly, and also regular CText. When the font is changed in the resource file, I notice that the dialog size itself changes, however, this is not happening when I call SetFont or send a WM_SETFONT message. Can anyone help me? Thanks!!!

      S Offline
      S Offline
      Stye
      wrote on last edited by
      #2

      Do you want to change the main dialog of a dialog based app or a dialog that is part of a doc view app? Do you want to change the dialog after it is already created or have a different font at creation depending a factor such as screen resolution, etc.?

      A 1 Reply Last reply
      0
      • S Stye

        Do you want to change the main dialog of a dialog based app or a dialog that is part of a doc view app? Do you want to change the dialog after it is already created or have a different font at creation depending a factor such as screen resolution, etc.?

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

        I've found the answer: 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; }

        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