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. SelectObject() Rules

SelectObject() Rules

Scheduled Pinned Locked Moved C / C++ / MFC
graphicstutorialquestionlearning
6 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.
  • O Offline
    O Offline
    Obliterator
    wrote on last edited by
    #1

    Hi all, I'm suffering a major resource leak on Win95/98/Me in one of my drawing routines. I realise that before an object is destroyed one must ensure it is not selected in the device context by selecting the old object beforehand. However where my knowledge is lacking is with the use of multiple pens: For example suppose I have a red and a blue pen. Currently I store the old pen when selecting the red. I then use the red pen. Next I select the blue pen, ignoring the returned pen. After using the blue pen, before exiting I reselect the old pen (stored when selecting the red) I then call DestroyObject for both the red and blue pens. Is this sufficient or must I store the oldpen each time and restore it before selecting a new one? Surely not?! This leak is driving me insane! I know the leak is in this function because if I remove the call no crash occurs. However I cannot for the life of me see the leak! I've tried using the example here on CP to Save and Restore the DC state before and after drawing, without success. Thanks -- The Obliterator

    P 1 Reply Last reply
    0
    • O Obliterator

      Hi all, I'm suffering a major resource leak on Win95/98/Me in one of my drawing routines. I realise that before an object is destroyed one must ensure it is not selected in the device context by selecting the old object beforehand. However where my knowledge is lacking is with the use of multiple pens: For example suppose I have a red and a blue pen. Currently I store the old pen when selecting the red. I then use the red pen. Next I select the blue pen, ignoring the returned pen. After using the blue pen, before exiting I reselect the old pen (stored when selecting the red) I then call DestroyObject for both the red and blue pens. Is this sufficient or must I store the oldpen each time and restore it before selecting a new one? Surely not?! This leak is driving me insane! I know the leak is in this function because if I remove the call no crash occurs. However I cannot for the life of me see the leak! I've tried using the example here on CP to Save and Restore the DC state before and after drawing, without success. Thanks -- The Obliterator

      P Offline
      P Offline
      Prem Kumar
      wrote on last edited by
      #2

      If you are using MFC, every thing is taken care of if all the objects are local objects. But if you are programming in SDK you need to make calls to DeleteObject with the resource handle.

      O A 2 Replies Last reply
      0
      • P Prem Kumar

        If you are using MFC, every thing is taken care of if all the objects are local objects. But if you are programming in SDK you need to make calls to DeleteObject with the resource handle.

        O Offline
        O Offline
        Obliterator
        wrote on last edited by
        #3

        I'm using MFC - and all is definitely not taken care of! Anyhow it looks like I've finally found the leak - I'll be testing on Win9x tomorrow to be sure! There was a pen constructed inside an if statement then selected. The old pen should have been reselected before leaving the if statement. As it was not I'm guessing the pen could not be correctly destroyed as its scope was lost. Thanks anyhow. -- The Obliterator

        M 1 Reply Last reply
        0
        • O Obliterator

          I'm using MFC - and all is definitely not taken care of! Anyhow it looks like I've finally found the leak - I'll be testing on Win9x tomorrow to be sure! There was a pen constructed inside an if statement then selected. The old pen should have been reselected before leaving the if statement. As it was not I'm guessing the pen could not be correctly destroyed as its scope was lost. Thanks anyhow. -- The Obliterator

          M Offline
          M Offline
          Michael Dunn
          wrote on last edited by
          #4

          Correct, a GDI object that is selected into a DC cannot be destroyed. --Mike-- Just released - RightClick-Encrypt v1.3 - Adds fast & easy file encryption to Explorer My really out-of-date homepage Sonork-100.19012 Acid_Helm

          O 1 Reply Last reply
          0
          • M Michael Dunn

            Correct, a GDI object that is selected into a DC cannot be destroyed. --Mike-- Just released - RightClick-Encrypt v1.3 - Adds fast & easy file encryption to Explorer My really out-of-date homepage Sonork-100.19012 Acid_Helm

            O Offline
            O Offline
            Obliterator
            wrote on last edited by
            #5

            Wouldn't you have thought it could assert in the destructor if selected in the DC??? -- The Obliterator

            1 Reply Last reply
            0
            • P Prem Kumar

              If you are using MFC, every thing is taken care of if all the objects are local objects. But if you are programming in SDK you need to make calls to DeleteObject with the resource handle.

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

              Check your knowledge on DC b4 replying.. Sudip Stupidity Sucks

              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