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. Transparent Window using SetLayeredWindowAttributes

Transparent Window using SetLayeredWindowAttributes

Scheduled Pinned Locked Moved C / C++ / MFC
c++visual-studiohelptutorial
7 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.
  • A Offline
    A Offline
    Aabid
    wrote on last edited by
    #1

    hello all i am using VS 6.0, VC++, Win32 My Task is to display png image on Transparent window..... i used SetLayeredWindowAttributes to make my window transparent and it works fine......but the problem is my image also gets transparent and nothing is displayed ...... can anybody suggest me how to overcome this problem.....i.e only window should become transparent but not the image..... Thankx:::

    enhzflepE 1 Reply Last reply
    0
    • A Aabid

      hello all i am using VS 6.0, VC++, Win32 My Task is to display png image on Transparent window..... i used SetLayeredWindowAttributes to make my window transparent and it works fine......but the problem is my image also gets transparent and nothing is displayed ...... can anybody suggest me how to overcome this problem.....i.e only window should become transparent but not the image..... Thankx:::

      enhzflepE Offline
      enhzflepE Offline
      enhzflep
      wrote on last edited by
      #2

      You can use an image with a solid colour applied in the parts that should be transparent. You then display the image using alpha keying, which renders the image except pixels that are this colour. Here is code that displays an an image with 75% opacity, except for pixels that are RGB(255,0,0) - which are not displayed at all. SetLayeredWindowAttributes(hwnd, RGB(255,0,0), (75*255)/100, ULW_COLORKEY|LWA_ALPHA); If you remove the |LWA_ALPHA part, you get full opacity on all pixels except the red ones, which are not shown at all.

      A 1 Reply Last reply
      0
      • enhzflepE enhzflep

        You can use an image with a solid colour applied in the parts that should be transparent. You then display the image using alpha keying, which renders the image except pixels that are this colour. Here is code that displays an an image with 75% opacity, except for pixels that are RGB(255,0,0) - which are not displayed at all. SetLayeredWindowAttributes(hwnd, RGB(255,0,0), (75*255)/100, ULW_COLORKEY|LWA_ALPHA); If you remove the |LWA_ALPHA part, you get full opacity on all pixels except the red ones, which are not shown at all.

        A Offline
        A Offline
        Aabid
        wrote on last edited by
        #3

        Thankx For ur reply But it gives compilation error as ULW_COLORKEY undefined

        enhzflepE 1 Reply Last reply
        0
        • A Aabid

          Thankx For ur reply But it gives compilation error as ULW_COLORKEY undefined

          enhzflepE Offline
          enhzflepE Offline
          enhzflep
          wrote on last edited by
          #4

          Oops, sorry about that - i forget which one it is, you need one of these #defines (I think it's the first one) #define _WIN32_WINNT 0x0601 #define _WIN32_IE 0x0300

          A 1 Reply Last reply
          0
          • enhzflepE enhzflep

            Oops, sorry about that - i forget which one it is, you need one of these #defines (I think it's the first one) #define _WIN32_WINNT 0x0601 #define _WIN32_IE 0x0300

            A Offline
            A Offline
            Aabid
            wrote on last edited by
            #5

            in both #defines i got the same error as error C2065: 'ULW_COLORKEY' : undeclared identifier

            C enhzflepE 2 Replies Last reply
            0
            • A Aabid

              in both #defines i got the same error as error C2065: 'ULW_COLORKEY' : undeclared identifier

              C Offline
              C Offline
              Code o mat
              wrote on last edited by
              #6

              I think you need one of these (put that into the PreProcessor settings of your project): _WIN32_IE=0x0500 WINVER=0x0500

              > The problem with computers is that they do what you tell them to do and not what you want them to do. <

              1 Reply Last reply
              0
              • A Aabid

                in both #defines i got the same error as error C2065: 'ULW_COLORKEY' : undeclared identifier

                enhzflepE Offline
                enhzflepE Offline
                enhzflep
                wrote on last edited by
                #7

                Taken from winuser.h (mingw 3.4.5) #if (_WIN32_WINNT >= 0x0500) #define LWA_COLORKEY 0x01 #define LWA_ALPHA 0x02 #define ULW_COLORKEY 0x01 #define ULW_ALPHA 0x02 #define ULW_OPAQUE 0x04 #endif

                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