As for how to copy the screen and save, there are already examples, I do not have to go to copy people, I always do not like copy. Here is a complete example that can be seen.
http://msdn.microsoft.com/EN-US/library/windows/desktop/dd183402 (v=vs.85). aspx
Copy the contents of the screen to the client area of the window, usually using the BitBlt function, function is to copy a color data from a DC to another DC, which I do not know how to translate a bit more popular. Let's say that you intercept a rectangular region from the graphics surface of the source device context and copy it to the area of another device context. Just like we're going to do a screenshot tool, copy part of the screen to the window.
Next, I use another function to copy the--STRETCHBLT function, which is similar to BitBlt, but it has a bit of stretching the source image according to the area of the target.
Watch the code.
{
///Screen DC
HDC hdcscreen = GetDC (NULL);
The DC
HDC Hdcwindow = GetDC (hWnd) of this window;
The width of the screen
int scrwidth = GetSystemMetrics (sm_cxscreen);
The height of the screen
int scrheight = GetSystemMetrics (sm_cyscreen);
The client area of the window
RECT rectclient;
GetClientRect (HWnd, &rectclient);
Use StretchBlt to replicate
StretchBlt
(hdcwindow,0,0,rectclient.right,rectclient.bottom,hdcscreen,0,0, Scrwidth,scrheight,srccopy
);
Release DC
ReleaseDC (NULL, hdcscreen);
ReleaseDC (HWnd, Hdcwindow);
}
Now, we want to make it clear that we're going to copy things from the screen to the window area, so we thought we had to have two DCs first, one for the screen and the other for the Windows DC. The DC can be obtained by the GETDC function, and the parameter is set to NULL, that is, the DC handle of the main screen is obtained, NULL can be considered to get the DC of the desktop.
After getting to the DC, we must also know the width and height of the source area and the width and height of the target window area.
The source area is the screen, so as long as we know the height and width of the current screen, GetSystemMetrics (Sm_cxscreen) returns the width of the current screen, GetSystemMetrics (sm_cyscreen) Gets the height of the current screen.
And the size of the window's area? We may want to first get the window client area rectangle size, with the GetClientRect function to fill a RECT structure, this structure is the right member of the window client area width, bottom member is the window client area height.
Well, with these basic parameters, the following things will be done.
BOOL StretchBlt (_in_ HDC hdcdest, _in_ int nxorigindest, _in_ int nyorigindest, _in_ int nwidthdest, _in_ int nheightdest , _in_ HDC hdcsrc, _in_ int nxoriginsrc, _in_ int nyoriginsrc, _in_ int nwidthsrc, _in_ int nheightsrc, _in_ DWORD dwrop);