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. Layered window !

Layered window !

Scheduled Pinned Locked Moved C / C++ / MFC
helpannouncement
16 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.
  • A Adno

    yes is the handle to the window and no is not a child window. i've also posted on this forum the code: http://www.gamedev.net/community/forums/topic.asp?topic\_id=449081 thank you

    M Offline
    M Offline
    Mark Salsbery
    wrote on last edited by
    #5

    Also, check success or fail of UpdateLayeredWindow() call BEFORE calling GetLastError() - in other words, only call GetLastError() if the UpdateLayeredWindow() call fails. Not all APIs clear the thread's last error when they succeed. Mark

    "Posting a VB.NET question in the C++ forum will end in tears." Chris Maunder

    A 1 Reply Last reply
    0
    • M Mark Salsbery

      Cool thanks for the link! I don't think you should be calling SetLayeredWindowAttributes(). Try commenting out that call. :) Mark

      "Posting a VB.NET question in the C++ forum will end in tears." Chris Maunder

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

      hehe the window does not show if i do that.

      M 1 Reply Last reply
      0
      • M Mark Salsbery

        Also, check success or fail of UpdateLayeredWindow() call BEFORE calling GetLastError() - in other words, only call GetLastError() if the UpdateLayeredWindow() call fails. Not all APIs clear the thread's last error when they succeed. Mark

        "Posting a VB.NET question in the C++ forum will end in tears." Chris Maunder

        A Offline
        A Offline
        Adno
        wrote on last edited by
        #7

        yes but UpdateLayeredWindow() returns 0 which means is failing. and the fact that is not doing anything :)

        1 Reply Last reply
        0
        • A Adno

          hehe the window does not show if i do that.

          M Offline
          M Offline
          Mark Salsbery
          wrote on last edited by
          #8

          OK but they are not meant to be used together - they cause the window updates to be done two different ways. If you must use both, the docs state "Note that once SetLayeredWindowAttributes has been called for a layered window, subsequent UpdateLayeredWindow calls will fail until the layering style bit is cleared and set again."

          "Posting a VB.NET question in the C++ forum will end in tears." Chris Maunder

          A 1 Reply Last reply
          0
          • M Mark Salsbery

            OK but they are not meant to be used together - they cause the window updates to be done two different ways. If you must use both, the docs state "Note that once SetLayeredWindowAttributes has been called for a layered window, subsequent UpdateLayeredWindow calls will fail until the layering style bit is cleared and set again."

            "Posting a VB.NET question in the C++ forum will end in tears." Chris Maunder

            A Offline
            A Offline
            Adno
            wrote on last edited by
            #9

            without the SetLayeredWindowAttributes i dont get the 87 error code form getlast error which is a good news, but the window is not showing and UpdateLayeredWindow is returning 0;

            M 1 Reply Last reply
            0
            • A Adno

              without the SetLayeredWindowAttributes i dont get the 87 error code form getlast error which is a good news, but the window is not showing and UpdateLayeredWindow is returning 0;

              M Offline
              M Offline
              Mark Salsbery
              wrote on last edited by
              #10

              Lamefif wrote:

              the window is not showing and UpdateLayeredWindow is returning 0;

              If it's returning 0 then it's still failing, right? Or do you mean GetLastError() returns 0? ACK I just noticed in your code on the other site - you are destroying the memDC. I'm pretty sure the system is going to need that to draw the window! Try keeping it around for the life of the window instead. Mark

              "Posting a VB.NET question in the C++ forum will end in tears." Chris Maunder

              A 1 Reply Last reply
              0
              • M Mark Salsbery

                Lamefif wrote:

                the window is not showing and UpdateLayeredWindow is returning 0;

                If it's returning 0 then it's still failing, right? Or do you mean GetLastError() returns 0? ACK I just noticed in your code on the other site - you are destroying the memDC. I'm pretty sure the system is going to need that to draw the window! Try keeping it around for the life of the window instead. Mark

                "Posting a VB.NET question in the C++ forum will end in tears." Chris Maunder

                A Offline
                A Offline
                Adno
                wrote on last edited by
                #11

                Thanks mark you've been a great help, the window is now showing. it was blend.SourceConstantAlpha = 255; set to 0 i think. but i still have some problems im using this image, http://mathforum.org/library/drmath/gifs/analog\_clock.jpg the white part of the image is showing the blue part is transparent. and mouse clicks go through the window, regardless where i click on it.

                A M 2 Replies Last reply
                0
                • A Adno

                  Thanks mark you've been a great help, the window is now showing. it was blend.SourceConstantAlpha = 255; set to 0 i think. but i still have some problems im using this image, http://mathforum.org/library/drmath/gifs/analog\_clock.jpg the white part of the image is showing the blue part is transparent. and mouse clicks go through the window, regardless where i click on it.

                  A Offline
                  A Offline
                  Adno
                  wrote on last edited by
                  #12

                  using LWA_COLORKEY gets around that it seems, but the window comes out pixilated . now i have to figure out how to use an alpha channel :(

                  M 1 Reply Last reply
                  0
                  • A Adno

                    Thanks mark you've been a great help, the window is now showing. it was blend.SourceConstantAlpha = 255; set to 0 i think. but i still have some problems im using this image, http://mathforum.org/library/drmath/gifs/analog\_clock.jpg the white part of the image is showing the blue part is transparent. and mouse clicks go through the window, regardless where i click on it.

                    M Offline
                    M Offline
                    Mark Salsbery
                    wrote on last edited by
                    #13

                    To hide the white you'll need to use UpdateLayeredWindow(hwnd, NULL, NULL, NULL, dcMem, NULL, RGB(255,255,255), 0, ULW_COLORKEY); To use alpha blending on the entire bitmap you'd use UpdateLayeredWindow(hwnd, NULL, NULL, NULL, dcMem, NULL, 0, &blend, LWA_ALPHA); To use both alpha and color key, you need to use SetLayeredWindowAttributes() instead of UpdateLayeredWindow()... SetLayeredWindowAttributes(hwnd, RGB(255,255,255), alphavalue, LWA_COLORKEY | LWA_ALPHA); Then you'd have to draw the bitmap yourself in response to WM_PAINT. Mark

                    "Posting a VB.NET question in the C++ forum will end in tears." Chris Maunder

                    A 1 Reply Last reply
                    0
                    • A Adno

                      using LWA_COLORKEY gets around that it seems, but the window comes out pixilated . now i have to figure out how to use an alpha channel :(

                      M Offline
                      M Offline
                      Mark Salsbery
                      wrote on last edited by
                      #14

                      Lamefif wrote:

                      the window comes out pixilated

                      Because you've sized the window bigger than the bitmap??

                      "Posting a VB.NET question in the C++ forum will end in tears." Chris Maunder

                      1 Reply Last reply
                      0
                      • M Mark Salsbery

                        To hide the white you'll need to use UpdateLayeredWindow(hwnd, NULL, NULL, NULL, dcMem, NULL, RGB(255,255,255), 0, ULW_COLORKEY); To use alpha blending on the entire bitmap you'd use UpdateLayeredWindow(hwnd, NULL, NULL, NULL, dcMem, NULL, 0, &blend, LWA_ALPHA); To use both alpha and color key, you need to use SetLayeredWindowAttributes() instead of UpdateLayeredWindow()... SetLayeredWindowAttributes(hwnd, RGB(255,255,255), alphavalue, LWA_COLORKEY | LWA_ALPHA); Then you'd have to draw the bitmap yourself in response to WM_PAINT. Mark

                        "Posting a VB.NET question in the C++ forum will end in tears." Chris Maunder

                        A Offline
                        A Offline
                        Adno
                        wrote on last edited by
                        #15

                        im having trouble with the pixilated edge, i tried adding a png file with an alpha cannel as a resource but it came out as row data.. ups. i want to use perpixilalpha as you can tell, whats the best way to go about this? thanks again

                        M 1 Reply Last reply
                        0
                        • A Adno

                          im having trouble with the pixilated edge, i tried adding a png file with an alpha cannel as a resource but it came out as row data.. ups. i want to use perpixilalpha as you can tell, whats the best way to go about this? thanks again

                          M Offline
                          M Offline
                          Mark Salsbery
                          wrote on last edited by
                          #16

                          Have you tried using CImage or the GdiPlus::Bitmap class to load the png? Then you should be able to use the associated HBITMAP, selected into the dcMem and use UpdateLayeredWindow() like this: blend.BlendOp = AC_SRC_OVER; blend.BlendFlags = 0; blend.SourceConstantAlpha = 255; blend.AlphaFormat = AC_SRC_ALPHA; UpdateLayeredWindow(hwnd, NULL, NULL, NULL, dcMem, NULL, 0, &blend, LWA_ALPHA);

                          "Posting a VB.NET question in the C++ forum will end in tears." Chris Maunder

                          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