Today, I bored the code, turn out a function of a previous written C # screen capture ... I will share it with you. This code is rewritten with the C code of the online screen capture. Only declare the API. . after each API is also attached for reference if there are questions of welcome that:.. AppleDotnet
/// // Intercept section /// //// ////// ////// // / 是 是 full screen /// Return Value Bitmappublic static Bitmap getPartScreen (Point P1, Point P2, Bool Full) {INTPTR HSCRDC , HMEMDC; INTPTR HBitmap, Holdbitmap; INT NX, NY, NX2, NY2; Nx = NY = Nx2 = NY2 = 0; int NWidth, NHEIGHT; int xscrn, yscrn; hscrdc = created, null, 0 ); // Create DC handle hmemdc = CreateCompatibleDC (hscrdc); // Create a memory DC xscrn = GetDeviceCaps (hscrdc, GetDeviceCapsIndex.HORZRES); // Get the screen width yscrn = GetDeviceCaps (hscrdc, GetDeviceCapsIndex.VERTRES); // Get Screen height if (full) // If it is intercepting the entire screen {nx = 0; Ny = 0; Nx2 = xscrn; NY2 = YSCRN;} else {nx = p1.x; ny = p1.y; nx2 = p2.x NY2 = p2.y; // Check the numerical legitimacy IF (Nx <0) Nx = 0; if (Ny <0) NY = 0; IF (Nx2> XSCRN) NX2 = xscrn; if (NY2> YSCRN) NY2 = YSCRN;} nwidth = NX2 - NX; // The width of the interception range NHEight = NY2 - NY; / / Intercept range HBitmap = CreateCompATIBLEBITMAP (HSCRDC, NWIDTH, NHEIGHT); // Copy from memory DC to HBitmap handle Holdbitmap = SelectObjec T (HMEMDC, HBitmap); Bitblt (HMEMDC, 0, 0, NWIDTH, NHEIGHT, HSCRDC, NX, NY, (UINT32) 0XCC0020; hbitmap = selectObject (HMEMDC, HoldbitMap); deletedc (hscrdc); // Delete Object deletedc (hmemdc); // Remove used object return bitmap.fromhbitmap (hbitmap); // Return Bitmap from Hbitmap with Bitmap.Fromhbitmap}
The API used is declared: