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. Multiple CDC::SelectObject()

Multiple CDC::SelectObject()

Scheduled Pinned Locked Moved C / C++ / MFC
question
14 Posts 5 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.
  • C CPallini

    PatrykDabrowski wrote:

    Is it safe to use:[...]

    Yes.

    PatrykDabrowski wrote:

    or I should use SelectObject(m_pOld)/DeleteDC() after each SelectObject(&some_bitmapX)??

    No. :)

    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.

    P Offline
    P Offline
    PatrykDabrowski
    wrote on last edited by
    #3

    Thanks:)

    1 Reply Last reply
    0
    • P PatrykDabrowski

      Hello, Is it safe to use: CDC memDC; memDC.CreateCompatibleDC(pDC); CBitmap *m_pOld = memDC.SelectObject(&some_bitmap1); memDC.SelectObject(&some_bitmap2); memDC.SelectObject(&some_bitmap3); memDC.SelectObject(&some_bitmap4); .... memDC.SelectObject(m_pOld); memDC.DeleteDC; or I should use SelectObject(m_pOld)/DeleteDC() after each SelectObject(&some_bitmapX)??

      P Offline
      P Offline
      pri_skit
      wrote on last edited by
      #4

      No it is not safe to use.It will cause memory leak in your application. I think,II Option is better one.Use SelectObject(m_pOld)/DeleteDC() after each SelectObject(&some_bitmapX)??

      priyank

      P P 2 Replies Last reply
      0
      • P pri_skit

        No it is not safe to use.It will cause memory leak in your application. I think,II Option is better one.Use SelectObject(m_pOld)/DeleteDC() after each SelectObject(&some_bitmapX)??

        priyank

        P Offline
        P Offline
        PatrykDabrowski
        wrote on last edited by
        #5

        I have already tried both versions. None of them reports memory leaks in VS2003 in Debug mode. But maybe those resources are not monitored by VS... That's why I'm askng:) Thanks!

        1 Reply Last reply
        0
        • P pri_skit

          No it is not safe to use.It will cause memory leak in your application. I think,II Option is better one.Use SelectObject(m_pOld)/DeleteDC() after each SelectObject(&some_bitmapX)??

          priyank

          P Offline
          P Offline
          Parthi_Appu
          wrote on last edited by
          #6

          pri_skit wrote:

          No it is not safe to use

          Its safe.. its nothing to do with leaks (if we delete the selected objects) or simply we can do like this,

          CDC dc;//assign value
          dc.SaveDC();
          /*
          * Do select object,
          * or what ever you want.
          */
          dc.RestoreDC( -1 );

          No need to worry about the old objects..


          Do your Duty and Don't expect the Result

          P 1 Reply Last reply
          0
          • P Parthi_Appu

            pri_skit wrote:

            No it is not safe to use

            Its safe.. its nothing to do with leaks (if we delete the selected objects) or simply we can do like this,

            CDC dc;//assign value
            dc.SaveDC();
            /*
            * Do select object,
            * or what ever you want.
            */
            dc.RestoreDC( -1 );

            No need to worry about the old objects..


            Do your Duty and Don't expect the Result

            P Offline
            P Offline
            PatrykDabrowski
            wrote on last edited by
            #7

            Yes, I delete some_bitmapX objects (when exiting the app as they are 'global'). What I care about is: 1) Performance 2) Avoid memory/resource leaks. Is CDC::CreateCompatibleDC()/DeleteDC() slower comparing to CDC::SaveDC()/RestoreDC()?? Thanks for help.

            C P 2 Replies Last reply
            0
            • P PatrykDabrowski

              Yes, I delete some_bitmapX objects (when exiting the app as they are 'global'). What I care about is: 1) Performance 2) Avoid memory/resource leaks. Is CDC::CreateCompatibleDC()/DeleteDC() slower comparing to CDC::SaveDC()/RestoreDC()?? Thanks for help.

              C Offline
              C Offline
              CPallini
              wrote on last edited by
              #8

              Please revise the order of your list :):-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.

              T 1 Reply Last reply
              0
              • P PatrykDabrowski

                Yes, I delete some_bitmapX objects (when exiting the app as they are 'global'). What I care about is: 1) Performance 2) Avoid memory/resource leaks. Is CDC::CreateCompatibleDC()/DeleteDC() slower comparing to CDC::SaveDC()/RestoreDC()?? Thanks for help.

                P Offline
                P Offline
                Parthi_Appu
                wrote on last edited by
                #9

                PatrykDabrowski wrote:

                I delete some_bitmapX objects (when exiting the app as they are 'global').

                If you are creating those object once and deleting at the end, then no problem.

                PatrykDabrowski wrote:

                CreateCompatibleDC()/DeleteDC() slower comparing to CDC::SaveDC()/RestoreDC()??

                These two set of APIs are different from each other. That is, after creating a compatible DC, you have select the needed objects into the DC. At last the original object belong to the DC have to be selected (the object returned, at the first select object, note this appicable for that specific type of object). DelectDC will delete the DC that you created. But the SaveDC and RestoreDC is for making the DC to its original state, you need not worry about reselecting the original objects. see below;

                CDC dc; dc.CreateCompatibleDC(..);
                dc.SaveDC();
                dc.SelectObject(bitmap1); /* do something */
                dc.SelectObject(bitmap2); /* do something */
                dc.RestoreDC( -1 );
                dc.DeleteDC();

                By doing so, you need not have to maintain the old objects returned.


                Do your Duty and Don't expect the Result

                1 Reply Last reply
                0
                • C CPallini

                  Please revise the order of your list :):-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.

                  T Offline
                  T Offline
                  toxcct
                  wrote on last edited by
                  #10

                  CPallini wrote:

                  Please revise the order of your list

                  :laugh: so true !


                  [VisualCalc][Binary Guide][CommDialogs] | [Forums Guidelines]

                  P 1 Reply Last reply
                  0
                  • T toxcct

                    CPallini wrote:

                    Please revise the order of your list

                    :laugh: so true !


                    [VisualCalc][Binary Guide][CommDialogs] | [Forums Guidelines]

                    P Offline
                    P Offline
                    PatrykDabrowski
                    wrote on last edited by
                    #11

                    I should put 1) && 2)...in fact as long as I dont have leaks, I care more about performance:) So the order is fine:)

                    T 1 Reply Last reply
                    0
                    • P PatrykDabrowski

                      I should put 1) && 2)...in fact as long as I dont have leaks, I care more about performance:) So the order is fine:)

                      T Offline
                      T Offline
                      toxcct
                      wrote on last edited by
                      #12

                      PatrykDabrowski wrote:

                      I care more about performance:) So the order is fine:)

                      so, you prefer allocating some memory, even if you "can't" delete it, until it doesn't affect your performances ? dude, you're not alone running on the system ! what if everybody was coding like this - letting memory leaks voluntarily - because it "doesn't affect the perfrmances of the application" ?? :wtf: you should always care about leaks first (of course, thinking of not coding too dirtily, of course) and optimize only then, if necessary...


                      [VisualCalc][Binary Guide][CommDialogs] | [Forums Guidelines]

                      P 1 Reply Last reply
                      0
                      • T toxcct

                        PatrykDabrowski wrote:

                        I care more about performance:) So the order is fine:)

                        so, you prefer allocating some memory, even if you "can't" delete it, until it doesn't affect your performances ? dude, you're not alone running on the system ! what if everybody was coding like this - letting memory leaks voluntarily - because it "doesn't affect the perfrmances of the application" ?? :wtf: you should always care about leaks first (of course, thinking of not coding too dirtily, of course) and optimize only then, if necessary...


                        [VisualCalc][Binary Guide][CommDialogs] | [Forums Guidelines]

                        P Offline
                        P Offline
                        PatrykDabrowski
                        wrote on last edited by
                        #13

                        I have written "as long as I dont have leaks, I care more about performance:)";)...so my priority is to avoid memory leaks and then I optimize my code. I assume that both solutions don't cause leaks so I would like to choose faster one. (I mean CDC::CreateCompatibleDC()/DeleteDC against CDC::SaveCD()/RestoreDC() )

                        T 1 Reply Last reply
                        0
                        • P PatrykDabrowski

                          I have written "as long as I dont have leaks, I care more about performance:)";)...so my priority is to avoid memory leaks and then I optimize my code. I assume that both solutions don't cause leaks so I would like to choose faster one. (I mean CDC::CreateCompatibleDC()/DeleteDC against CDC::SaveCD()/RestoreDC() )

                          T Offline
                          T Offline
                          toxcct
                          wrote on last edited by
                          #14

                          PatrykDabrowski wrote:

                          I have written "as long as I dont have leaks, I care more about performance:)";)...so my priority is to avoid memory leaks and then I optimize my code.

                          ok for me then :cool:


                          [VisualCalc][Binary Guide][CommDialogs] | [Forums Guidelines]

                          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