cwinapicolorsscreenshotprintscreen

Need a winapi function with the ability to print screen


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


Solution

  • 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