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. how to change the font for a label

how to change the font for a label

Scheduled Pinned Locked Moved C / C++ / MFC
tutorial
2 Posts 2 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.
  • M Offline
    M Offline
    Mac
    wrote on last edited by
    #1

    Hi, I tried to change the font of a label using SelectObject but it don't work. The SelectObject works if I use TextOut(...). But for label or edit, I use SetDlgItemText(..). So how to change the fonts used for edit/label or is there anything that I did it wrongly. Thanks. code that I use ======================== HDC hDC = GetDC(); hFont = CreateFont(....) HFONT hFontOld = (HFONT)SelectObject( hDC, hFont); TextOut(....) DelectObject(hFont) SelectObject(hDC, hFontOld);

    L 1 Reply Last reply
    0
    • M Mac

      Hi, I tried to change the font of a label using SelectObject but it don't work. The SelectObject works if I use TextOut(...). But for label or edit, I use SetDlgItemText(..). So how to change the fonts used for edit/label or is there anything that I did it wrongly. Thanks. code that I use ======================== HDC hDC = GetDC(); hFont = CreateFont(....) HFONT hFontOld = (HFONT)SelectObject( hDC, hFont); TextOut(....) DelectObject(hFont) SelectObject(hDC, hFontOld);

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      i think this way could work: overwrite or go into InitDialog (WM_INITDIALOG) and set here the font for the label. I hope that is correct, because it's only a part of 16-bit-code-application (MFC). I believe IDC_ErrorA was a Label. //define at the top of your cpp-file CFont m_biggerFont; //must be are here, global in View for Paint() void Cxx_View::OnInitialUpdate() { LOGFONT logfont; CRect rect; // get edit control size GetDlgItem(IDC_ErrorA)->GetWindowRect(&rect); ScreenToClient(&rect); // in parent coordinate memset(&logfont, 0, sizeof(logfont)); logfont.lfHeight = int ((rect.bottom-rect.top)); logfont.lfWeight = FW_BOLD; switch(FontType) { case 0: strcpy(logfont.lfFaceName, "MS Sans Serif");break; default: strcpy(logfont.lfFaceName, "MS Sans Serif"); } VERIFY(m_biggerFont.CreateFontIndirect(&logfont)); GetDlgItem(IDC_BigA)->SetFont(&m_biggerFont,TRUE); GetDlgItem(IDC_BigA)->UpdateWindow(); ... }

      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