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. [Resolved] CButtonST question, Remove the residue of old icon while setting a new icon with SetIcon [modified]

[Resolved] CButtonST question, Remove the residue of old icon while setting a new icon with SetIcon [modified]

Scheduled Pinned Locked Moved C / C++ / MFC
helpquestiontutorialannouncement
3 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
    Maxwell Chen
    wrote on last edited by
    #1

    I am maintaining the source code which uses CButtonST buttons as icon controls to display transparent and overlay icons (for the small arrow at the corner of the main icon) on the GUI. User can change the icon. When user is changing the icon, what I do in the code is to invoke CButtonST::SetIcon with another HICON handle. But there is the residue of the old icon which is unwanted. The new icon overlaps on top of the old one. How to remove the old residue icon? Please advise. Thanks. According to the comment by the author of CButtonST, calling SetIcon(0, 0) can remove any old icons from it. [ quote ] // Pass NULL to remove any icon from the button. [ / quote ] But in fact this call makes the application crash! [Update] I found someone had added two lines in CButtonST::FreeResources to do DeleteDC() and DeleteObject(). This issue was caused by these two calls. The problem is fixed after removing them. :-D

    Maxwell Chen

    modified on Wednesday, December 30, 2009 3:36 AM

    K 1 Reply Last reply
    0
    • M Maxwell Chen

      I am maintaining the source code which uses CButtonST buttons as icon controls to display transparent and overlay icons (for the small arrow at the corner of the main icon) on the GUI. User can change the icon. When user is changing the icon, what I do in the code is to invoke CButtonST::SetIcon with another HICON handle. But there is the residue of the old icon which is unwanted. The new icon overlaps on top of the old one. How to remove the old residue icon? Please advise. Thanks. According to the comment by the author of CButtonST, calling SetIcon(0, 0) can remove any old icons from it. [ quote ] // Pass NULL to remove any icon from the button. [ / quote ] But in fact this call makes the application crash! [Update] I found someone had added two lines in CButtonST::FreeResources to do DeleteDC() and DeleteObject(). This issue was caused by these two calls. The problem is fixed after removing them. :-D

      Maxwell Chen

      modified on Wednesday, December 30, 2009 3:36 AM

      K Offline
      K Offline
      KingsGambit
      wrote on last edited by
      #2

      Can you debug and see why SetIcon(0, 0) fails?

      M 1 Reply Last reply
      0
      • K KingsGambit

        Can you debug and see why SetIcon(0, 0) fails?

        M Offline
        M Offline
        Maxwell Chen
        wrote on last edited by
        #3

        Rejeesh.T.S wrote:

        Can you debug and see why SetIcon(0, 0) fails?

        There are 3 versions of SetIcon, one is SetIcon(int, int) and the second is SetIcon(HICON, HICON). I think the compiler links it to SetIcon(int, int) when I wrote SetIcon(NULL, NULL). So I casted it to force it invoke the correct version by SetIcon((HICON)NULL /* second arg has default val */). And it does not crash now. But there is still old residue icon. I just downloaded the demo source of CButtonST v3.9 from CodeProject, and modified the code to make it change icon dynamically. I do not see it have this problem. And I compared the source code of CButtonST between the demo source and my code. They look the same regarding the icon drawing portion. This is so weird ...

        Maxwell Chen

        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