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. CFont clean-up

CFont clean-up

Scheduled Pinned Locked Moved C / C++ / MFC
question
12 Posts 4 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.
  • T Offline
    T Offline
    Tara14
    wrote on last edited by
    #1

    Hi, Please can you tell me the correct way to perform clean-up operation for a Cfont object? I use this in OnInitDialog() :

    CFont *m_pTitleFont = new CFont;
    m_pTitleFont->CreateFont(25,0,0,0,800,0,0,0,0,0,0,ANTIALIASED_QUALITY,0,"Verdana");

    s_Title.SetFont(m_pTitleFont);

    s_Title is a CStatic object. I use different font types for different Static controls. So I am usually creating three-four fonts. Thanks.

    _


    Fortitudine Vincimus!_

    M 1 Reply Last reply
    0
    • T Tara14

      Hi, Please can you tell me the correct way to perform clean-up operation for a Cfont object? I use this in OnInitDialog() :

      CFont *m_pTitleFont = new CFont;
      m_pTitleFont->CreateFont(25,0,0,0,800,0,0,0,0,0,0,ANTIALIASED_QUALITY,0,"Verdana");

      s_Title.SetFont(m_pTitleFont);

      s_Title is a CStatic object. I use different font types for different Static controls. So I am usually creating three-four fonts. Thanks.

      _


      Fortitudine Vincimus!_

      M Offline
      M Offline
      Mark Salsbery
      wrote on last edited by
      #2

      Tara14 wrote:

      can you tell me the correct way to perform clean-up operation for a Cfont object?

      How about delete m_pTitleFont; ? Mark

      "Posting a VB.NET question in the C++ forum will end in tears." Chris Maunder

      CPalliniC 1 Reply Last reply
      0
      • M Mark Salsbery

        Tara14 wrote:

        can you tell me the correct way to perform clean-up operation for a Cfont object?

        How about delete m_pTitleFont; ? Mark

        "Posting a VB.NET question in the C++ forum will end in tears." Chris Maunder

        CPalliniC Offline
        CPalliniC Offline
        CPallini
        wrote on last edited by
        #3

        I wonder if the CFont destructor calls the DeleteObject method, does it?

        If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.

        In testa che avete, signor di Ceprano?

        M S 2 Replies Last reply
        0
        • CPalliniC CPallini

          I wonder if the CFont destructor calls the DeleteObject method, does it?

          If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.

          M Offline
          M Offline
          Mark Salsbery
          wrote on last edited by
          #4

          CPallini wrote:

          the CFont destructor calls the DeleteObject method, does it?

          Not directly. ~CGdiObject() does though. Mark

          "Posting a VB.NET question in the C++ forum will end in tears." Chris Maunder

          CPalliniC 1 Reply Last reply
          0
          • CPalliniC CPallini

            I wonder if the CFont destructor calls the DeleteObject method, does it?

            If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.

            S Offline
            S Offline
            Stephen Hewitt
            wrote on last edited by
            #5

            You can look in the source and find out.....

            Steve

            CPalliniC 1 Reply Last reply
            0
            • M Mark Salsbery

              CPallini wrote:

              the CFont destructor calls the DeleteObject method, does it?

              Not directly. ~CGdiObject() does though. Mark

              "Posting a VB.NET question in the C++ forum will end in tears." Chris Maunder

              CPalliniC Offline
              CPalliniC Offline
              CPallini
              wrote on last edited by
              #6

              OK, thanks! :-D BTW this MS sample made me wondering about [^], since they explicitely call CFont::DeleteObject.

              If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.

              In testa che avete, signor di Ceprano?

              M 1 Reply Last reply
              0
              • S Stephen Hewitt

                You can look in the source and find out.....

                Steve

                CPalliniC Offline
                CPalliniC Offline
                CPallini
                wrote on last edited by
                #7

                What an empirical boy!:-D Do you suggest to take sources as references? They're of course, for the current release... and..what if MS changes mind over time? :)

                If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.

                In testa che avete, signor di Ceprano?

                S 1 Reply Last reply
                0
                • CPalliniC CPallini

                  What an empirical boy!:-D Do you suggest to take sources as references? They're of course, for the current release... and..what if MS changes mind over time? :)

                  If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.

                  S Offline
                  S Offline
                  Stephen Hewitt
                  wrote on last edited by
                  #8

                  CPallini wrote:

                  Do you suggest to take sources as references? They're of course, for the current release... and..what if MS changes mind over time?

                  They are not going to change something like. They can hardly make the class not clean up the resources when it previously did of vice versa.

                  Steve

                  CPalliniC 1 Reply Last reply
                  0
                  • S Stephen Hewitt

                    CPallini wrote:

                    Do you suggest to take sources as references? They're of course, for the current release... and..what if MS changes mind over time?

                    They are not going to change something like. They can hardly make the class not clean up the resources when it previously did of vice versa.

                    Steve

                    CPalliniC Offline
                    CPalliniC Offline
                    CPallini
                    wrote on last edited by
                    #9

                    Stephen Hewitt wrote:

                    They can hardly make the class not clean up the resources when it previously did of vice versa.

                    I agree on the above observation, of course.:) I don't agree on the method, of course.:-D

                    If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.

                    In testa che avete, signor di Ceprano?

                    S 1 Reply Last reply
                    0
                    • CPalliniC CPallini

                      Stephen Hewitt wrote:

                      They can hardly make the class not clean up the resources when it previously did of vice versa.

                      I agree on the above observation, of course.:) I don't agree on the method, of course.:-D

                      If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.

                      S Offline
                      S Offline
                      Stephen Hewitt
                      wrote on last edited by
                      #10

                      CPallini wrote:

                      I don't agree on the method, of course.

                      In a perfect world the documentation would be complete and answer all your questions. In the real world this is not always the case and you often need to find your answers elsewhere. In such situations a mixture of common sense and a peek at source code often save the day. This is just life in the trenches.

                      Steve

                      CPalliniC 1 Reply Last reply
                      0
                      • S Stephen Hewitt

                        CPallini wrote:

                        I don't agree on the method, of course.

                        In a perfect world the documentation would be complete and answer all your questions. In the real world this is not always the case and you often need to find your answers elsewhere. In such situations a mixture of common sense and a peek at source code often save the day. This is just life in the trenches.

                        Steve

                        CPalliniC Offline
                        CPalliniC Offline
                        CPallini
                        wrote on last edited by
                        #11

                        Stephen Hewitt wrote:

                        This is just life in the trenches

                        :-D

                        If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.

                        In testa che avete, signor di Ceprano?

                        1 Reply Last reply
                        0
                        • CPalliniC CPallini

                          OK, thanks! :-D BTW this MS sample made me wondering about [^], since they explicitely call CFont::DeleteObject.

                          If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.

                          M Offline
                          M Offline
                          Mark Salsbery
                          wrote on last edited by
                          #12

                          CPallini wrote:

                          BTW this MS sample made me wondering about

                          That's cool. The OP created his/hers with new so I chose delete as an idea :) For a local object, DeleteObject is great to free the HGDIOBJ when you no longer need it. When the CFont goes out of scope, it will be freed as well. Cheers! Mark

                          "Posting a VB.NET question in the C++ forum will end in tears." Chris Maunder

                          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