-1

I want to create a small utility 'ColorPic', below is its picture.

In fact, I can get RGB of the pixel where the cursor is over.

But I want to create a window which "prints" part of the screen (near the cursor) into this window.

The most important is that I need an option to zoom in and zoom out, which means that I could represent a pixel by a 4x4, 8x8, 16x16 or 32x32 rectangle...

I know there is a SetPixel function, but this is not what I want.

Is there a very efficient functon to do this, something like "PrintScreen" (and one can specified a rectangle as argument)?? By very efficient, I mean when one move the mouse, the function can refresh the window very fast and do not use too much system resource.

enter image description heres

user565739
  • 1,302
  • 4
  • 23
  • 46

1 Answers1

6

I've found this:

    HBITMAP MakePrintScreen()
    {
          HWND hWindow = GetDesktopWindow();
          HDC hdcScreen = GetDC(hWindow);
          RECT rect;
          HBITMAP hbmC;

          GetClientRect(hWindow,&rect);

          if((hbmC = CreateCompatibleBitmap(hdcScreen,rect.right,rect.bottom)) != NULL)
          {
                HDC hdcC;
                if((hdcC = CreateCompatibleDC(hdcScreen)) != NULL)
                {
                      HBITMAP hbmOld = (HBITMAP)SelectObject(hdcC,hbmC);

                      BitBlt(hdcC,0,0,rect.right,rect.bottom,hdcScreen,0,0,SRCCOPY);

                      SelectObject(hdcC,hbmOld);
                      DeleteDC(hdcC);
                }
          }

          ReleaseDC(hWindow,hdcScreen);

          return hbmC;
    }

From:

http://forum.4programmers.net/C_i_C++/149036-WINAPI_Print_screen_przyslonietego_okna

kmdv
  • 126
  • 2
  • 2
    That copies the pixels into a bitmap. To put a large version of that bitmap in a different window, you need to call [`StretchBlt`][http://msdn.microsoft.com/en-us/library/windows/desktop/dd145120(v=vs.85).aspx]. – Adrian McCarthy Aug 31 '12 at 19:55
  • Very useful answer, kmdv. But I give upvote for Adrian also, since this is the final step and an important step to finish the job! – user565739 Sep 01 '12 at 01:10