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. CButton with Bitmap Transparency

CButton with Bitmap Transparency

Scheduled Pinned Locked Moved C / C++ / MFC
questioncsharpvisual-studiographics
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.
  • F Offline
    F Offline
    fjlv2005
    wrote on last edited by
    #1

    Hello, I have a CButton created dynamically with bitmap: CButton m_mybutton.Create(NULL,WS_CHILD|WS_VISIBLE|BS_OWNERDRAW,CRect(1,87,110,107),this, ID_BTNHEADBOOKMARK); m_mybutton.LoadBitmaps(IDB_LISTHBOOKMARK, IDB_LISTHBOOKMARK, IDB_LISTHBOOKMARK, IDB_LISTHBOOKMARK); The image have some area with Color RGB(255,0,255). I wanted those area with that color above to be transparent. How can I do it?:confused: Hope i could get a response ASAP (if possible ) Also im using EVC, you can try it Visual Studio and if works, i'll try it to EVC3.0. Thanks you very much.

    L 1 Reply Last reply
    0
    • F fjlv2005

      Hello, I have a CButton created dynamically with bitmap: CButton m_mybutton.Create(NULL,WS_CHILD|WS_VISIBLE|BS_OWNERDRAW,CRect(1,87,110,107),this, ID_BTNHEADBOOKMARK); m_mybutton.LoadBitmaps(IDB_LISTHBOOKMARK, IDB_LISTHBOOKMARK, IDB_LISTHBOOKMARK, IDB_LISTHBOOKMARK); The image have some area with Color RGB(255,0,255). I wanted those area with that color above to be transparent. How can I do it?:confused: Hope i could get a response ASAP (if possible ) Also im using EVC, you can try it Visual Studio and if works, i'll try it to EVC3.0. Thanks you very much.

      L Offline
      L Offline
      Lane Yu
      wrote on last edited by
      #2

      My suggestion: Derive a subclass from CButton, modify its style as owner-draw. Overwrite the DrawItem() and use TransparentBlt() to paint the bitmap by yourself. Lane

      F 1 Reply Last reply
      0
      • L Lane Yu

        My suggestion: Derive a subclass from CButton, modify its style as owner-draw. Overwrite the DrawItem() and use TransparentBlt() to paint the bitmap by yourself. Lane

        F Offline
        F Offline
        fjlv2005
        wrote on last edited by
        #3

        Lane, I understand how to override DrawItem by creating a class derived from CButton, however there no TransparentBlt API in EVC3.0. Anyway to do TransparentBlt?:( Thanks Lane

        P L 2 Replies Last reply
        0
        • F fjlv2005

          Lane, I understand how to override DrawItem by creating a class derived from CButton, however there no TransparentBlt API in EVC3.0. Anyway to do TransparentBlt?:( Thanks Lane

          P Offline
          P Offline
          PJ Arends
          wrote on last edited by
          #4

          NewVCbie wrote: Anyway to do TransparentBlt? You can use the "True Mask" method. It is the method used by windows to draw icons. It involves creating a black and white mask bitmap that uses white as the transparent part and black as the opaque part. You can have a look at my article at http://www.codeproject.com/bitmap/pjaimage.asp[^] where I use the method to draw transparent bitmaps. Look at the CPJAImage::DrawTransparent() method. Google[^]


          "You're obviously a superstar." - Christian Graus about me - 12 Feb '03 "Obviously ???  You're definitely a superstar!!!" - mYkel - 21 Jun '04 "There's not enough blatant self-congratulatory backslapping in the world today..." - HumblePie - 21 Jun '05 Within you lies the power for good - Use it!

          1 Reply Last reply
          0
          • F fjlv2005

            Lane, I understand how to override DrawItem by creating a class derived from CButton, however there no TransparentBlt API in EVC3.0. Anyway to do TransparentBlt?:( Thanks Lane

            L Offline
            L Offline
            Lane Yu
            wrote on last edited by
            #5

            You can use several call of BitBlt to implement. Just type "Transparent Bitmap" in Google, you'll find many articles. One in CodeProject: http://www.codeproject.com/bitmap/transbitmapmask.asp[^] Lane

            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