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. Windows Messages and Pixel colors..

Windows Messages and Pixel colors..

Scheduled Pinned Locked Moved C / C++ / MFC
question
10 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.
  • _ Offline
    _ Offline
    __Cerb
    wrote on last edited by
    #1

    Is it possible to grab a certain pixel's color using WM messages? If so, which WM should I send and what kind of wParam and lParam would I need to send? Thanks, ~Mike

    H 1 Reply Last reply
    0
    • _ __Cerb

      Is it possible to grab a certain pixel's color using WM messages? If so, which WM should I send and what kind of wParam and lParam would I need to send? Thanks, ~Mike

      H Offline
      H Offline
      Hesham Amin
      wrote on last edited by
      #2

      you can use GetPixel COLORREF GetPixel( HDC hdc, // handle to DC int nXPos, // x-coordinate of pixel int nYPos // y-coordinate of pixel ); why do you need SendMessage ?

      _ 1 Reply Last reply
      0
      • H Hesham Amin

        you can use GetPixel COLORREF GetPixel( HDC hdc, // handle to DC int nXPos, // x-coordinate of pixel int nYPos // y-coordinate of pixel ); why do you need SendMessage ?

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

        Because I need to retrieve pixel colors from an inactive window.. Is it possible? Thanks ~Mike

        H 1 Reply Last reply
        0
        • _ __Cerb

          Because I need to retrieve pixel colors from an inactive window.. Is it possible? Thanks ~Mike

          H Offline
          H Offline
          Hesham Amin
          wrote on last edited by
          #4

          __Cerb wrote: Is it possible? not sure... an inactive window isn't drawn!! .. needs to get the wm_paint to be redrawn..

          _ 1 Reply Last reply
          0
          • H Hesham Amin

            __Cerb wrote: Is it possible? not sure... an inactive window isn't drawn!! .. needs to get the wm_paint to be redrawn..

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

            What about ::GetDC(HWND hwnd) and ::ScreenToClient(HWND hwnd, LPPOINT lpPoint) ??? is there a way I could use those to get a pixel color?

            _ H 2 Replies Last reply
            0
            • _ __Cerb

              What about ::GetDC(HWND hwnd) and ::ScreenToClient(HWND hwnd, LPPOINT lpPoint) ??? is there a way I could use those to get a pixel color?

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

              Do I need to use ::GetDC, ::GetWindowDC, ::ScreenToClient, ::BitBlt, I really need to figure out how can I retrieve a pixel color from an inactive window. Thanks a lot, any help greatly appreciated ~Cerb

              1 Reply Last reply
              0
              • _ __Cerb

                What about ::GetDC(HWND hwnd) and ::ScreenToClient(HWND hwnd, LPPOINT lpPoint) ??? is there a way I could use those to get a pixel color?

                H Offline
                H Offline
                Hesham Amin
                wrote on last edited by
                #7

                if you have the window handle then use GetWindowDC to get the HDC (device context) then use GetPixel directly... but the problem is when the window needs repaint.. in this case it amy give you another color,,, try this first and let us know the results :)

                _ 1 Reply Last reply
                0
                • H Hesham Amin

                  if you have the window handle then use GetWindowDC to get the HDC (device context) then use GetPixel directly... but the problem is when the window needs repaint.. in this case it amy give you another color,,, try this first and let us know the results :)

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

                  Damn, it still won't work. CString szWndName,szWndClass; szWndName = "My window"; szWndClass = "My window's class"; HWND hwnd = ::FindWindow(szWndName,szWndClass); ::PostMessage(hwnd,WM_PAINT,0,0); HDC hDC = ::GetWindowDC(hwnd); CString str; int iPixel; iPixel = ::GetPixel(hDC,50,75); str.Format("%d",iPixel); AfxMessageBox(str); It keeps returning -1, and it should return 263172 Any ideas?

                  _ 1 Reply Last reply
                  0
                  • _ __Cerb

                    Damn, it still won't work. CString szWndName,szWndClass; szWndName = "My window"; szWndClass = "My window's class"; HWND hwnd = ::FindWindow(szWndName,szWndClass); ::PostMessage(hwnd,WM_PAINT,0,0); HDC hDC = ::GetWindowDC(hwnd); CString str; int iPixel; iPixel = ::GetPixel(hDC,50,75); str.Format("%d",iPixel); AfxMessageBox(str); It keeps returning -1, and it should return 263172 Any ideas?

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

                    Help please?

                    H 1 Reply Last reply
                    0
                    • _ __Cerb

                      Help please?

                      H Offline
                      H Offline
                      Hesham Amin
                      wrote on last edited by
                      #10

                      can you tell me what is the purpose of this operation ? maybe wecan find a way around it... why do you need to get the color of an in-active window ?

                      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