|
How can someone always do something like me.
I wrote an ActiveX in VC ++, captured the area selected by the user, compressed it into Jpeg, then converted it to Base64, and uploaded it.
Give you the key part of the code:
HBITMAP CCopyScr :: CopyToBmp (CRect Rect)
{
// Screen and memory device description table
HDC hScrDC, hMemDC;
// bitmap handle
HBITMAP hBitmap, hOldBitmap;
// selected area coordinates
int nX, nY, nX2, nY2;
// bitmap width and height
int nWidth, nHeight;
// Screen Resolution
int xScrn, yScrn;
// make sure the selected area is not an empty rectangle
if (IsRectEmpty (&Rect))
return NULL;
// Create a device description table for the screen
hScrDC = CreateDC ("DISPLAY", NULL, NULL, NULL);
Ranch
// Create a compatible memory device description table for the screen device description table
hMemDC = CreateCompatibleDC (hScrDC);
Ranch
// get the coordinates of the selected area
nX = Rect.left;
nY = Rect.top;
nX2 = Rect.right;
nY2 = Rect.bottom;
Ranch
// Get screen resolution
xScrn = GetDeviceCaps (hScrDC, HORZRES);
yScrn = GetDeviceCaps (hScrDC, VERTRES);
Ranch
// Make sure the selected area is visible
if (nX <0)
nX = 0;
if (nY <0)
nY = 0;
if (nX2> xScrn)
nX2 = xScrn;
if (nY2> yScrn)
nY2 = yScrn;
nWidth = nX2-nX;
nHeight = nY2-nY;
Ranch
// Create a bitmap compatible with the screen device description table
hBitmap = CreateCompatibleBitmap (hScrDC, nWidth, nHeight);
Ranch
// Select the new bitmap into the memory device description table
hOldBitmap = (HBITMAP) SelectObject (hMemDC, hBitmap);
Ranch
// Copy the screen device description table to the memory device description table
BitBlt (hMemDC, 0, 0, nWidth, nHeight, hScrDC, nX, nY, SRCCOPY);
Ranch
// Get the handle of the screen bitmap
hBitmap = (HBITMAP) SelectObject (hMemDC, hOldBitmap);
Ranch
// clear
DeleteDC (hScrDC);
DeleteDC (hMemDC);
Ranch
// return the bitmap handle
return hBitmap;
} |
|