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. GetPixel() help needed

GetPixel() help needed

Scheduled Pinned Locked Moved C / C++ / MFC
helptutorial
13 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.
  • _ __Cerb

    Ok, I know how to use the GetPixel function, the only problem is that I must get the DC of an inactive/minimized window. I've tried HDC hdc = ::GetWindowDC(hwnd), HDC hdc = ::GetDC(hwnd), HDC hdc = ::LockWindowUpdate(hwnd), but all of them returns -1 when I call the GetPixel function on any pixel of that DC. If I can figure this out, it would GREATLY help my project. Thanks a lot in advance ~Mike

    J Offline
    J Offline
    Jorgen Sigvardsson
    wrote on last edited by
    #2

    You can't get pixels from a minimized window. There is no "canvas". :) -- Seraphim Shock. Gold for your ears.

    _ 1 Reply Last reply
    0
    • J Jorgen Sigvardsson

      You can't get pixels from a minimized window. There is no "canvas". :) -- Seraphim Shock. Gold for your ears.

      _ Offline
      _ Offline
      __Cerb
      wrote on last edited by
      #3

      So in no way I can do this? Damn, that sucks. With this, my project would have been so great...

      J 1 Reply Last reply
      0
      • _ __Cerb

        So in no way I can do this? Damn, that sucks. With this, my project would have been so great...

        J Offline
        J Offline
        Jorgen Sigvardsson
        wrote on last edited by
        #4

        Not to my knowledge, no. The device context mirrors what's shown on screen. If there's nothing on screen, then there are no pixels to grab. This window you're trying to snatch pixels from.. is it in the same process as your pixel grabbing routine? If it is, you could always make the "source window" double buffered. That is, it keeps a bitmap of itself internally. That way you could access the bitmap for pixels. Otherwise it's a pretty tough job I reckon. By the way, after GetPixel() returns -1, have you checked the error code? Either call GetLastError() or add the @err pseudo-variable in the watch window in the debugger. -- Seraphim Shock. Gold for your ears.

        _ 1 Reply Last reply
        0
        • J Jorgen Sigvardsson

          Not to my knowledge, no. The device context mirrors what's shown on screen. If there's nothing on screen, then there are no pixels to grab. This window you're trying to snatch pixels from.. is it in the same process as your pixel grabbing routine? If it is, you could always make the "source window" double buffered. That is, it keeps a bitmap of itself internally. That way you could access the bitmap for pixels. Otherwise it's a pretty tough job I reckon. By the way, after GetPixel() returns -1, have you checked the error code? Either call GetLastError() or add the @err pseudo-variable in the watch window in the debugger. -- Seraphim Shock. Gold for your ears.

          _ Offline
          _ Offline
          __Cerb
          wrote on last edited by
          #5

          Well, I have a game window opened and minimized, I'm using ::FindWindow to get its HWND value, I tried all possible ways to get the window's DC, but couldn't. Would it be possible to get a bitmap or a BitBlt and get the pixel I want from it? If so, how could I do it? Thanks a lot for your help ~Mike

          L 1 Reply Last reply
          0
          • _ __Cerb

            Well, I have a game window opened and minimized, I'm using ::FindWindow to get its HWND value, I tried all possible ways to get the window's DC, but couldn't. Would it be possible to get a bitmap or a BitBlt and get the pixel I want from it? If so, how could I do it? Thanks a lot for your help ~Mike

            L Offline
            L Offline
            l a u r e n
            wrote on last edited by
            #6

            i think u can send it a wm_paint message and pass a dc in then it draws to that dc and u can grab what u like


            "there is no spoon"
            biz stuff   about me

            _ 1 Reply Last reply
            0
            • L l a u r e n

              i think u can send it a wm_paint message and pass a dc in then it draws to that dc and u can grab what u like


              "there is no spoon"
              biz stuff   about me

              _ Offline
              _ Offline
              __Cerb
              wrote on last edited by
              #7

              Uh? Pass a DC in a WM_PAINT message? How do you do that? I doubt it's possible... ~Mike

              L 1 Reply Last reply
              0
              • _ __Cerb

                Uh? Pass a DC in a WM_PAINT message? How do you do that? I doubt it's possible... ~Mike

                L Offline
                L Offline
                l a u r e n
                wrote on last edited by
                #8

                sorry brainfreeze wm_print or wm_printclient ;)


                "there is no spoon"
                biz stuff   about me

                _ 1 Reply Last reply
                0
                • L l a u r e n

                  sorry brainfreeze wm_print or wm_printclient ;)


                  "there is no spoon"
                  biz stuff   about me

                  _ Offline
                  _ Offline
                  __Cerb
                  wrote on last edited by
                  #9

                  Uh this won't work. Sending a message to a window is not like retrieving a HDC, so it won't return the HDC of the window.

                  L 1 Reply Last reply
                  0
                  • _ __Cerb

                    Uh this won't work. Sending a message to a window is not like retrieving a HDC, so it won't return the HDC of the window.

                    L Offline
                    L Offline
                    l a u r e n
                    wrote on last edited by
                    #10

                    dude u pass the hdc in as athe wparam and the app _might_ paint on it if ur lucky i thought that was what u wanted?


                    "there is no spoon"
                    biz stuff   about me

                    _ J 2 Replies Last reply
                    0
                    • L l a u r e n

                      dude u pass the hdc in as athe wparam and the app _might_ paint on it if ur lucky i thought that was what u wanted?


                      "there is no spoon"
                      biz stuff   about me

                      _ Offline
                      _ Offline
                      __Cerb
                      wrote on last edited by
                      #11

                      Whatever, any serious responses please?

                      1 Reply Last reply
                      0
                      • L l a u r e n

                        dude u pass the hdc in as athe wparam and the app _might_ paint on it if ur lucky i thought that was what u wanted?


                        "there is no spoon"
                        biz stuff   about me

                        J Offline
                        J Offline
                        Jorgen Sigvardsson
                        wrote on last edited by
                        #12

                        I don't think it'll work with WM_PRINT. HDCs are inprocess handles I believe (not entirely sure about that though). Sending an HDC from one process to another will at best result in nothing. I think the only way is to grab a handle to the window, and then acquire a HDC from that window handle. -- Seraphim Shock. Gold for your ears.

                        L 1 Reply Last reply
                        0
                        • J Jorgen Sigvardsson

                          I don't think it'll work with WM_PRINT. HDCs are inprocess handles I believe (not entirely sure about that though). Sending an HDC from one process to another will at best result in nothing. I think the only way is to grab a handle to the window, and then acquire a HDC from that window handle. -- Seraphim Shock. Gold for your ears.

                          L Offline
                          L Offline
                          l a u r e n
                          wrote on last edited by
                          #13

                          hmmmmmmm i remember doing it a whiles ago and it worked some apps dont handle those messages tho so it isnt guaranteed


                          "there is no spoon"
                          biz stuff   about me

                          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