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. Font in CWnd

Font in CWnd

Scheduled Pinned Locked Moved C / C++ / MFC
wpfquestion
5 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.
  • I Offline
    I Offline
    includeh10
    wrote on last edited by
    #1

    I created a CWnd control with widow styles WS_CHILD|WS_VISIBLE (parent is a CWnd also), then set a new CFont to the control by SetFont(...) function. But, when called CFont*pFt=GetFont(); inside the CWnd control, return value of pFt is null. Should I add more window styles? How do you set a font to CWnd to ensure that GetFont() is valid? BTW: I tested to create a CStatic, GetFont() is still null;

    modified on Monday, January 10, 2011 11:39 PM

    L J 3 Replies Last reply
    0
    • I includeh10

      I created a CWnd control with widow styles WS_CHILD|WS_VISIBLE (parent is a CWnd also), then set a new CFont to the control by SetFont(...) function. But, when called CFont*pFt=GetFont(); inside the CWnd control, return value of pFt is null. Should I add more window styles? How do you set a font to CWnd to ensure that GetFont() is valid? BTW: I tested to create a CStatic, GetFont() is still null;

      modified on Monday, January 10, 2011 11:39 PM

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

      See comments here[^] about the return value from the WM_GETFONT message.

      I must get a clever new signature for 2011.

      L 1 Reply Last reply
      0
      • I includeh10

        I created a CWnd control with widow styles WS_CHILD|WS_VISIBLE (parent is a CWnd also), then set a new CFont to the control by SetFont(...) function. But, when called CFont*pFt=GetFont(); inside the CWnd control, return value of pFt is null. Should I add more window styles? How do you set a font to CWnd to ensure that GetFont() is valid? BTW: I tested to create a CStatic, GetFont() is still null;

        modified on Monday, January 10, 2011 11:39 PM

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

        At which point do you call GetFont? Does the window already/still exist at that point? Calling it from within OnCreate() should be safe to ensure the font has been set.

        1 Reply Last reply
        0
        • L Lost User

          See comments here[^] about the return value from the WM_GETFONT message.

          I must get a clever new signature for 2011.

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

          Additionally, it will return 0 too when called on a control/window that doesn't exist (yet/anymore/at all).

          1 Reply Last reply
          0
          • I includeh10

            I created a CWnd control with widow styles WS_CHILD|WS_VISIBLE (parent is a CWnd also), then set a new CFont to the control by SetFont(...) function. But, when called CFont*pFt=GetFont(); inside the CWnd control, return value of pFt is null. Should I add more window styles? How do you set a font to CWnd to ensure that GetFont() is valid? BTW: I tested to create a CStatic, GetFont() is still null;

            modified on Monday, January 10, 2011 11:39 PM

            J Offline
            J Offline
            jk chan
            wrote on last edited by
            #5

            Just call GetFont immediately after SetFont, so that we can test whether the problem is with invalid window handle. For a valid window handle it must work.

            If u can Dream... U can do it

            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