当前位置: 首页>>代码示例>>C++>>正文


C++ GetDIBits函数代码示例

本文整理汇总了C++中GetDIBits函数的典型用法代码示例。如果您正苦于以下问题:C++ GetDIBits函数的具体用法?C++ GetDIBits怎么用?C++ GetDIBits使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了GetDIBits函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: CopyScreenToBitmap

HBITMAP CopyScreenToBitmap(LPRECT lpRect, BYTE *pData, BITMAPINFO *pHeader)
{
    HDC         hScrDC, hMemDC;         // screen DC and memory DC
    HBITMAP     hBitmap, hOldBitmap;    // handles to deice-dependent bitmaps
    int         nX, nY, nX2, nY2;       // coordinates of rectangle to grab
    int         nWidth, nHeight;        // DIB width and height
    int         xScrn, yScrn;           // screen resolution

    // check for an empty rectangle
    if (IsRectEmpty(lpRect))
      return NULL;

    // create a DC for the screen and create
    // a memory DC compatible to screen DC   
    hScrDC = CreateDC(TEXT("DISPLAY"), NULL, NULL, NULL);
    hMemDC = CreateCompatibleDC(hScrDC);

    // get points of rectangle to grab
    nX  = lpRect->left;
    nY  = lpRect->top;
    nX2 = lpRect->right;
    nY2 = lpRect->bottom;

    // get screen resolution
    xScrn = GetDeviceCaps(hScrDC, HORZRES);
    yScrn = GetDeviceCaps(hScrDC, VERTRES);

    //make sure bitmap rectangle 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;

    // create a bitmap compatible with the screen DC
    hBitmap = CreateCompatibleBitmap(hScrDC, nWidth, nHeight);

    // select new bitmap into memory DC
    hOldBitmap = (HBITMAP) SelectObject(hMemDC, hBitmap);

    // bitblt screen DC to memory DC
    BitBlt(hMemDC, 0, 0, nWidth, nHeight, hScrDC, nX, nY, SRCCOPY);

    // select old bitmap back into memory DC and get handle to
    // bitmap of the screen   
    hBitmap = (HBITMAP)  SelectObject(hMemDC, hOldBitmap);

    // Copy the bitmap data into the provided BYTE buffer
    GetDIBits(hScrDC, hBitmap, 0, nHeight, pData, pHeader, DIB_RGB_COLORS);

    // clean up
    DeleteDC(hScrDC);
    DeleteDC(hMemDC);

    // return handle to the bitmap
    return hBitmap;
}
开发者ID:Essjay1,项目名称:Windows-classic-samples,代码行数:63,代码来源:DibHelper.cpp

示例2: memset

QPixmap QPixmap::fromWinHBITMAP(HBITMAP bitmap, HBitmapFormat format)
{
    // Verify size
    BITMAP bitmap_info;
    memset(&bitmap_info, 0, sizeof(BITMAP));

    int res = GetObject(bitmap, sizeof(BITMAP), &bitmap_info);
    if (!res) {
        qErrnoWarning("QPixmap::fromWinHBITMAP(), failed to get bitmap info");
        return QPixmap();
    }
    int w = bitmap_info.bmWidth;
    int h = bitmap_info.bmHeight;

    BITMAPINFO bmi;
    memset(&bmi, 0, sizeof(bmi));
    bmi.bmiHeader.biSize        = sizeof(BITMAPINFOHEADER);
    bmi.bmiHeader.biWidth       = w;
    bmi.bmiHeader.biHeight      = -h;
    bmi.bmiHeader.biPlanes      = 1;
    bmi.bmiHeader.biBitCount    = 32;
    bmi.bmiHeader.biCompression = BI_RGB;
    bmi.bmiHeader.biSizeImage   = w * h * 4;

    QImage result;
    // Get bitmap bits
    uchar *data = (uchar *) qMalloc(bmi.bmiHeader.biSizeImage);

    HDC display_dc = GetDC(0);
    if (GetDIBits(display_dc, bitmap, 0, h, data, &bmi, DIB_RGB_COLORS)) {

        QImage::Format imageFormat = QImage::Format_ARGB32_Premultiplied;
        uint mask = 0;
        if (format == NoAlpha) {
            imageFormat = QImage::Format_RGB32;
            mask = 0xff000000;
        }

        // Create image and copy data into image.
        QImage image(w, h, imageFormat);
        if (!image.isNull()) { // failed to alloc?
            int bytes_per_line = w * sizeof(QRgb);
            for (int y=0; y<h; ++y) {
                QRgb *dest = (QRgb *) image.scanLine(y);
                const QRgb *src = (const QRgb *) (data + y * bytes_per_line);
                for (int x=0; x<w; ++x) {
                    const uint pixel = src[x];
                    if ((pixel & 0xff000000) == 0 && (pixel & 0x00ffffff) != 0)
                        dest[x] = pixel | 0xff000000;
                    else
                        dest[x] = pixel | mask;
                }
            }
        }
        result = image;
    } else {
        qWarning("QPixmap::fromWinHBITMAP(), failed to get bitmap bits");
    }
    ReleaseDC(0, display_dc);
    qFree(data);
    return fromImage(result);
}
开发者ID:phen89,项目名称:rtqt,代码行数:62,代码来源:qpixmap_win.cpp

示例3: createBMPFile

void createBMPFile(LPTSTR pszFile, PBITMAPINFO pbi, 
                  HBITMAP hBMP, HDC hDC) 
{ 
    
    HANDLE hf;                  // file handle 
    BITMAPFILEHEADER hdr;       // bitmap file-header 
    PBITMAPINFOHEADER pbih;     // bitmap info-header 
    LPBYTE lpBits;              // memory pointer 
    DWORD dwTotal;              // total count of bytes 
    DWORD cb;                   // incremental count of bytes 
    BYTE *hp;                   // byte pointer 
    DWORD dwTmp; 

    pbih = (PBITMAPINFOHEADER) pbi; 
    lpBits = (LPBYTE) GlobalAlloc(GMEM_FIXED, pbih->biSizeImage);

    if (!lpBits) 
         throw "Global alloc error";

    // Retrieve the color table (RGBQUAD array) and the bits 
    // (array of palette indices) from the DIB. 
    if (!GetDIBits(hDC, hBMP, 0, (WORD) pbih->biHeight, lpBits, pbi, 
        DIB_RGB_COLORS)) 
    {
        throw "GetDIBits error";
    }

    // Create the .BMP file. 
    hf = CreateFile(pszFile, 
                   GENERIC_READ | GENERIC_WRITE, 
                   (DWORD) 0, 
                    NULL, 
                   CREATE_ALWAYS, 
                   FILE_ATTRIBUTE_NORMAL, 
                   (HANDLE) NULL); 
    if (hf == INVALID_HANDLE_VALUE) 
        throw "CreateFile error";
        
    hdr.bfType = 0x4d42;        // 0x42 = "B" 0x4d = "M" 
    // Compute the size of the entire file. 
    hdr.bfSize = (DWORD) (sizeof(BITMAPFILEHEADER) + 
                 pbih->biSize + pbih->biClrUsed 
                 * sizeof(RGBQUAD) + pbih->biSizeImage); 
    hdr.bfReserved1 = 0; 
    hdr.bfReserved2 = 0; 

    // Compute the offset to the array of color indices. 
    hdr.bfOffBits = (DWORD) sizeof(BITMAPFILEHEADER) + 
                    pbih->biSize + pbih->biClrUsed 
                    * sizeof (RGBQUAD); 

    // Copy the BITMAPFILEHEADER into the .BMP file. 
    if (!WriteFile(hf, (LPVOID) &hdr, sizeof(BITMAPFILEHEADER), 
        (LPDWORD) &dwTmp,  NULL)) 
    {
        throw "WriteFile error 1";
       
    }

    // Copy the BITMAPINFOHEADER and RGBQUAD array into the file. 
    if (!WriteFile(hf, (LPVOID) pbih, sizeof(BITMAPINFOHEADER) 
                  + pbih->biClrUsed * sizeof (RGBQUAD), 
                  (LPDWORD) &dwTmp, ( NULL)) )
        throw "WriteFile error 2";

    // Copy the array of color indices into the .BMP file. 
    dwTotal = cb = pbih->biSizeImage; 
    hp = lpBits; 
    if (!WriteFile(hf, (LPSTR) hp, (int) cb, (LPDWORD) &dwTmp,NULL)) 
           throw "WriteFile error 3";

    // Close the .BMP file. 
     if (!CloseHandle(hf)) 
           throw "CloseFile error";

    // Free memory. 
    GlobalFree((HGLOBAL)lpBits);
}
开发者ID:derekqian,项目名称:GPUSim_ATTILA,代码行数:78,代码来源:WriteBMP.cpp

示例4: MFDRV_StretchBlt

BOOL MFDRV_StretchBlt( PHYSDEV devDst, INT xDst, INT yDst, INT widthDst,
		       INT heightDst, PHYSDEV devSrc, INT xSrc, INT ySrc,
		       INT widthSrc, INT heightSrc, DWORD rop )
{
    BOOL ret;
    DWORD len;
    METARECORD *mr;
    BITMAP BM;
    METAFILEDRV_PDEVICE *physDevSrc = (METAFILEDRV_PDEVICE *)devSrc;
#ifdef STRETCH_VIA_DIB
    LPBITMAPINFOHEADER lpBMI;
    WORD nBPP;
#endif
    HBITMAP hBitmap = GetCurrentObject(physDevSrc->hdc, OBJ_BITMAP);

    if (GetObjectW(hBitmap, sizeof(BITMAP), &BM) != sizeof(BITMAP))
    {
        WARN("bad bitmap object %p passed for hdc %p\n", hBitmap, physDevSrc->hdc);
        return FALSE;
    }
#ifdef STRETCH_VIA_DIB
    nBPP = BM.bmPlanes * BM.bmBitsPixel;
    if(nBPP > 8) nBPP = 24; /* FIXME Can't get 16bpp to work for some reason */
    len = sizeof(METARECORD) + 10 * sizeof(INT16)
            + sizeof(BITMAPINFOHEADER) + (nBPP <= 8 ? 1 << nBPP: 0) * sizeof(RGBQUAD)
              + DIB_GetDIBWidthBytes(BM.bmWidth, nBPP) * BM.bmHeight;
    if (!(mr = HeapAlloc( GetProcessHeap(), 0, len)))
	return FALSE;
    mr->rdFunction = META_DIBSTRETCHBLT;
    lpBMI=(LPBITMAPINFOHEADER)(mr->rdParm+10);
    lpBMI->biSize      = sizeof(BITMAPINFOHEADER);
    lpBMI->biWidth     = BM.bmWidth;
    lpBMI->biHeight    = BM.bmHeight;
    lpBMI->biPlanes    = 1;
    lpBMI->biBitCount  = nBPP;
    lpBMI->biSizeImage = DIB_GetDIBWidthBytes(BM.bmWidth, nBPP) * lpBMI->biHeight;
    lpBMI->biClrUsed   = nBPP <= 8 ? 1 << nBPP : 0;
    lpBMI->biCompression = BI_RGB;
    lpBMI->biXPelsPerMeter = MulDiv(GetDeviceCaps(physDevSrc->hdc,LOGPIXELSX),3937,100);
    lpBMI->biYPelsPerMeter = MulDiv(GetDeviceCaps(physDevSrc->hdc,LOGPIXELSY),3937,100);
    lpBMI->biClrImportant  = 0;                          /* 1 meter  = 39.37 inch */

    TRACE("MF_StretchBltViaDIB->len = %ld  rop=%lx  PixYPM=%ld Caps=%d\n",
	  len,rop,lpBMI->biYPelsPerMeter,GetDeviceCaps(physDevSrc->hdc, LOGPIXELSY));

    if (GetDIBits(physDevSrc->hdc, hBitmap, 0, (UINT)lpBMI->biHeight,
                  (LPSTR)lpBMI + DIB_BitmapInfoSize( (BITMAPINFO *)lpBMI,
                                                     DIB_RGB_COLORS ),
                  (LPBITMAPINFO)lpBMI, DIB_RGB_COLORS))
#else
    len = sizeof(METARECORD) + 15 * sizeof(INT16) + BM.bmWidthBytes * BM.bmHeight;
    if (!(mr = HeapAlloc( GetProcessHeap(), 0, len )))
	return FALSE;
    mr->rdFunction = META_STRETCHBLT;
    *(mr->rdParm +10) = BM.bmWidth;
    *(mr->rdParm +11) = BM.bmHeight;
    *(mr->rdParm +12) = BM.bmWidthBytes;
    *(mr->rdParm +13) = BM.bmPlanes;
    *(mr->rdParm +14) = BM.bmBitsPixel;
    TRACE("len = %ld  rop=%lx\n", len, rop);
    if (GetBitmapBits( hBitmap, BM.bmWidthBytes * BM.bmHeight, mr->rdParm + 15))
#endif
    {
      mr->rdSize = len / sizeof(INT16);
      *(mr->rdParm) = LOWORD(rop);
      *(mr->rdParm + 1) = HIWORD(rop);
      *(mr->rdParm + 2) = heightSrc;
      *(mr->rdParm + 3) = widthSrc;
      *(mr->rdParm + 4) = ySrc;
      *(mr->rdParm + 5) = xSrc;
      *(mr->rdParm + 6) = heightDst;
      *(mr->rdParm + 7) = widthDst;
      *(mr->rdParm + 8) = yDst;
      *(mr->rdParm + 9) = xDst;
      ret = MFDRV_WriteRecord( devDst, mr, mr->rdSize * 2);
    }
    else
        ret = FALSE;
    HeapFree( GetProcessHeap(), 0, mr);
    return ret;
}
开发者ID:howard5888,项目名称:wineT,代码行数:81,代码来源:bitblt.c

示例5: BugDlg_CompressScreenshot

//-----------------------------------------------------------------------------
//	BugDlg_CompressScreenshot
//
//	Compress .BMP to .JPG, Delete .BMP
//-----------------------------------------------------------------------------
bool BugDlg_CompressScreenshot()
{
	if ( !g_bug_szScreenshot[0] )
	{
		return false;
	}

	bool bSuccess = false;
	HBITMAP hBitmap = NULL;
	HDC hDC = NULL;
	char *pBMPBits = NULL;

	CUtlBuffer buf( 0, 0 );

	hBitmap = (HBITMAP)LoadImage( NULL, g_bug_szScreenshot, IMAGE_BITMAP, 0, 0, LR_CREATEDIBSECTION | LR_DEFAULTSIZE | LR_LOADFROMFILE );
	if ( !hBitmap )
		goto cleanUp;

	hDC = CreateCompatibleDC( NULL );
	if ( !hDC )
		goto cleanUp;

	BITMAPINFO bitmapInfo;
	ZeroMemory( &bitmapInfo, sizeof( BITMAPINFO ) );
	bitmapInfo.bmiHeader.biSize = sizeof( BITMAPINFOHEADER );

	// populate the bmp info
	if ( !GetDIBits( hDC, hBitmap, 0, 0, NULL, &bitmapInfo, DIB_RGB_COLORS ) )
		goto cleanUp;

	pBMPBits = (char *)Sys_Alloc( bitmapInfo.bmiHeader.biSizeImage );
	if ( !pBMPBits )
		goto cleanUp;
	
	// could be bottom-up or top-down
	int nHeight = abs( bitmapInfo.bmiHeader.biHeight );

	if ( bitmapInfo.bmiHeader.biBitCount != 32 )
	{
		// unexpected format
		goto cleanUp;
	}

	if ( bitmapInfo.bmiHeader.biCompression != BI_RGB && bitmapInfo.bmiHeader.biCompression != BI_BITFIELDS )
	{
		// unexpected format
		goto cleanUp;
	}

	// don't want color masks
	bitmapInfo.bmiHeader.biCompression = BI_RGB;

	// get the raw bits
	if ( !GetDIBits( hDC, hBitmap, 0, nHeight, pBMPBits, &bitmapInfo, DIB_RGB_COLORS ) )
		goto cleanUp;

	JSAMPROW row_pointer[1]; 

	// compression data structure
	struct jpeg_compress_struct cinfo;
	ZeroMemory( &cinfo, sizeof( jpeg_compress_struct ) );

	// point at stderr
	struct jpeg_error_mgr jerr;
	cinfo.err = jpeg_std_error( &jerr );

	// create compressor
	jpeg_create_compress( &cinfo );

	// Hook CUtlBuffer to compression
	jpeg_UtlBuffer_dest( &cinfo, &buf );

	// image width and height, in pixels
	cinfo.image_width = bitmapInfo.bmiHeader.biWidth;
	cinfo.image_height = nHeight;
	cinfo.input_components = 3;
	cinfo.in_color_space = JCS_RGB;

	// Apply settings
	jpeg_set_defaults( &cinfo );
	jpeg_set_quality( &cinfo, 50, TRUE );

	// Start compressor
	jpeg_start_compress( &cinfo, TRUE);
	
	char *pRowBuffer = (char*)_alloca( bitmapInfo.bmiHeader.biWidth * 3 );
	row_pointer[0] = (JSAMPROW)pRowBuffer;

	// Write scanlines
	while ( cinfo.next_scanline < cinfo.image_height ) 
	{
		char *pSrc;
		if ( bitmapInfo.bmiHeader.biHeight < 0 )
		{
			// top down
//.........这里部分代码省略.........
开发者ID:DeadZoneLuna,项目名称:SourceEngine2007,代码行数:101,代码来源:bug.cpp

示例6: GetDesktopWindow


//.........这里部分代码省略.........
    if (fm) {
        x += 1;
    }
    y = topLeftY - textMetric.tmAscent;
    err = ExtTextOutW(hMemoryDC, x, y, ETO_GLYPH_INDEX|ETO_OPAQUE,
                (LPRECT)&rect, (LPCWSTR)&glyphCode, 1, NULL);
    if (err == 0) {
        FREE_AND_RETURN;
    }

    /* Now get the image into a DIB.
     * MS docs for GetDIBits says the compatible bitmap must not be
     * selected into a DC, so restore the original first.
     */
    SelectObject(hMemoryDC, hOrigBM);
    SelectObject(hMemoryDC, oldFont);
    DeleteObject(hFont);

    memset(&bmi, 0, sizeof(BITMAPINFO));
    bmi.bmiHeader.biSize = sizeof(bmi.bmiHeader);
    bmi.bmiHeader.biWidth = width;
    bmi.bmiHeader.biHeight = -height;
    bmi.bmiHeader.biPlanes = 1;
    bmi.bmiHeader.biBitCount = 24;
    bmi.bmiHeader.biCompression = BI_RGB;

    dibImage = SAFE_SIZE_ARRAY_ALLOC(malloc, dibBytesWidth, height);
    if (dibImage == NULL) {
        FREE_AND_RETURN;
    }
    dibImageSize = dibBytesWidth*height;
    memset(dibImage, 0, dibImageSize);

    err = GetDIBits(hMemoryDC, hBitmap, 0, height, dibImage,
                    &bmi, DIB_RGB_COLORS);

    if (err == 0) {        /* GetDIBits failed. */
        FREE_AND_RETURN;
    }

    err = SystemParametersInfo(SPI_GETFONTSMOOTHINGORIENTATION, 0, &orient, 0);
    if (err == 0) {
        FREE_AND_RETURN;
    }
    err = SystemParametersInfo(SPI_GETFONTSMOOTHINGCONTRAST, 0, &gamma, 0);
    if (err == 0) {
        FREE_AND_RETURN;
    }
    igTable = getIGTable(gamma/10);
    if (igTable == NULL) {
        FREE_AND_RETURN;
    }

    /* Now copy glyph image into a GlyphInfo structure and return it.
     * NB the xadvance calculated here may be overwritten by the caller.
     * 1 is subtracted from the bitmap width to get the glyph width, since
     * that extra "1" was added as padding, so the sub-pixel positioning of
     * fractional metrics could index into it.
     */
    glyphInfo = (GlyphInfo*)SAFE_SIZE_STRUCT_ALLOC(malloc, sizeof(GlyphInfo),
            bytesWidth, height);
    if (glyphInfo == NULL) {
        FREE_AND_RETURN;
    }
    imageSize = bytesWidth*height;
    glyphInfo->cellInfo = NULL;
开发者ID:sakeinntojiu,项目名称:openjdk8-jdk,代码行数:67,代码来源:lcdglyph.c

示例7: winQueryScreenDIBFormat

static
Bool
winQueryScreenDIBFormat (ScreenPtr pScreen, BITMAPINFOHEADER *pbmih)
{
  winScreenPriv(pScreen);
  HBITMAP		hbmp;
#if CYGDEBUG
  LPDWORD		pdw = NULL;
#endif
  
  /* Create a memory bitmap compatible with the screen */
  hbmp = CreateCompatibleBitmap (pScreenPriv->hdcScreen, 1, 1);
  if (hbmp == NULL)
    {
      ErrorF ("winQueryScreenDIBFormat - CreateCompatibleBitmap failed\n");
      return FALSE;
    }
  
  /* Initialize our bitmap info header */
  ZeroMemory (pbmih, sizeof (BITMAPINFOHEADER) + 256 * sizeof (RGBQUAD));
  pbmih->biSize = sizeof (BITMAPINFOHEADER);

  /* Get the biBitCount */
  if (!GetDIBits (pScreenPriv->hdcScreen,
		  hbmp,
		  0, 1,
		  NULL,
		  (BITMAPINFO*) pbmih,
		  DIB_RGB_COLORS))
    {
      ErrorF ("winQueryScreenDIBFormat - First call to GetDIBits failed\n");
      DeleteObject (hbmp);
      return FALSE;
    }

#if CYGDEBUG
  /* Get a pointer to bitfields */
  pdw = (DWORD*) ((CARD8*)pbmih + sizeof (BITMAPINFOHEADER));

  winDebug ("winQueryScreenDIBFormat - First call masks: %08x %08x %08x\n",
	  pdw[0], pdw[1], pdw[2]);
#endif

  /* Get optimal color table, or the optimal bitfields */
  if (!GetDIBits (pScreenPriv->hdcScreen,
		  hbmp,
		  0, 1,
		  NULL,
		  (BITMAPINFO*)pbmih,
		  DIB_RGB_COLORS))
    {
      ErrorF ("winQueryScreenDIBFormat - Second call to GetDIBits "
	      "failed\n");
      DeleteObject (hbmp);
      return FALSE;
    }

  /* Free memory */
  DeleteObject (hbmp);
  
  return TRUE;
}
开发者ID:Agnarr,项目名称:xserver,代码行数:62,代码来源:winshadgdi.c

示例8: WndProc

LRESULT CALLBACK WndProc( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam )
{
   switch( uMsg )
   {
      case WM_COMMAND :
              switch( LOWORD( wParam ) )
              {
                 case IDM_TEST :
                        {
                           BITMAPINFOHEADER  bi;
                           BITMAPINFOHEADER* lpbi;
                           HBITMAP           hBitmap;
                           HDC               hDC, hMemDC;
                           HANDLE            hDIB;

                           // Initialize the BITMAPINFOHEADER structure.
                           //...........................................
                           bi.biSize     = sizeof( BITMAPINFOHEADER );
                           bi.biWidth    = 50;
                           bi.biHeight   = 50;
                           bi.biPlanes   = 1;
                           bi.biBitCount = 4;
                           bi.biCompression   = BI_RGB;
                           bi.biSizeImage     = 0;
                           bi.biXPelsPerMeter = 0;
                           bi.biYPelsPerMeter = 0;
                           bi.biClrUsed       = 0;
                           bi.biClrImportant  = 0;

                           hDC = GetDC( hWnd );

                           // Create DIB.
                           //............
                           hBitmap = CreateDIBitmap( hDC, &bi, 0L, NULL, 
                                                     NULL, 0 );

                           // Allocate memory for BITMAPINFO structure.
                           //..........................................
                           hDIB    = GlobalAlloc( GHND, 
                                                  sizeof( BITMAPINFOHEADER )+
                                                  16 * sizeof( RGBQUAD ) );

                           lpbi = (BITMAPINFOHEADER*)GlobalLock( hDIB );

                           // Copy bi to top of BITMAPINFO structure.
                           //........................................
                           *lpbi = bi;

                           // Use GetDIBits() to init bi struct data.
                           //........................................
                           GetDIBits( hDC, hBitmap, 0, 50, NULL, 
                                      (LPBITMAPINFO)lpbi, DIB_RGB_COLORS );
                           GlobalUnlock( hDIB );

                           // Create a memory device context 
                           // and select the DIB into it.
                           //...............................
                           hMemDC = CreateCompatibleDC( hDC );
                           SelectObject( hMemDC, hBitmap );

                           // Paint on memory device context.
                           //................................
                           SelectObject( hMemDC, GetStockObject(BLACK_BRUSH));
                           Rectangle( hMemDC, 0, 0, 50, 50 );

                           SelectObject( hMemDC, GetStockObject(WHITE_BRUSH));
                           Ellipse( hMemDC, 0, 0, 50, 50 );
                           Ellipse( hMemDC, 10, 0, 40, 50 );
                           Ellipse( hMemDC, 20, 0, 30, 50 );

                           // Paint the bitmap on the display.
                           //.................................
                           BitBlt( hDC, 0, 0, 50, 50,
                                   hMemDC, 0, 0, SRCCOPY );

                           DeleteDC( hMemDC );
                           GlobalFree( hDIB );
                           ReleaseDC( hWnd, hDC );
                        }
                        break;

                 case IDM_ABOUT :
                        DialogBox( hInst, "AboutBox", hWnd, (DLGPROC)About );
                        break;

                 case IDM_EXIT :
                        DestroyWindow( hWnd );
                        break;
              }
              break;
      
      case WM_DESTROY :
              PostQuitMessage(0);
              break;

      default :
            return( DefWindowProc( hWnd, uMsg, wParam, lParam ) );
   }

   return( 0L );
//.........这里部分代码省略.........
开发者ID:d4nie1,项目名称:TotulDespreCPP,代码行数:101,代码来源:Create_DIB_Bitmap.cpp

示例9: TextProcessor

static void TextProcessor(INT hdlImage,CHAR *lpText)
{
	BYTE *lp;
	CHAR szTesto[1024];
	POINT pt;
	IMGHEADER *Img;
	HDC hDC,hDClone;
	HBITMAP hbCopy;
	BYTE *lpSorg;
	INT iLx,iLy;
	BITMAPINFOHEADER *BmpHeader;
	BITMAPINFO *BmpInfo;
	INT iAlt=12;
	INT iCol1=0;
	INT iCol2=-1;
	BOOL fBold=FALSE;

	// ----------------------------------------------------------------------------
	// Creo una zona di memoria tipo video delle dimensioni dell'immagine
	//
	//memcpy(&ImgHeader,memoLock(hdlImage),sizeof(IMGHEADER));
	printf("Elaborazione TextProcessor [%s]" CRLF,lpText); //Sleep(2000);
	//ehLogWrite("> %s" CRLF,lpText);
	if (!*lpText) return;

	Img=memoLock(hdlImage);
	BmpInfo=(BITMAPINFO *) &Img->bmiHeader;
	BmpHeader=(BITMAPINFOHEADER *) &Img->bmiHeader;
    iLy=BmpHeader->biHeight; if (iLy<0) iLy=-BmpHeader->biHeight;
    iLx=BmpHeader->biWidth;

    hDC=GetDC(NULL); hDClone=CreateCompatibleDC(hDC); 
	SetMapMode(hDClone, MM_TEXT);
	hbCopy = CreateCompatibleBitmap(hDC, iLx, iLy);
	SelectObject(hDClone, hbCopy);
	ReleaseDC(NULL,hDC);

    lpSorg=(BYTE *) Img;  lpSorg+=Img->Offset;

	// Scrivo l'immagine in questa zona di memoria
	if (StretchDIBits(hDClone, 
					  // Coordinate e dimensioni di stampa a video
					  0,0,
					  iLx, 
					  iLy,

					  // Coordinate e dimensioni di lettura nel sorgente
					  0,
					  iLy+1,
					  iLx,
					  -iLy,
					  lpSorg,
					  (BITMAPINFO *) &Img->bmiHeader,
					  DIB_RGB_COLORS, 
					  SRCCOPY) == GDI_ERROR) {printf("StretchDIBits Failed");}

	// Ci faccio quello che ci devo fare con i comandi
	lp=strtok(lpText,"|");
	*szTesto=0;
	ZeroFill(pt);
	while (lp)
	{
		//printf("[%s]" CRLF,lp); 

		if (!memcmp(lp,"TEXT=",5)) strcpy(szTesto,lp+5);
		if (!memcmp(lp,"PX=",3)) pt.x=atoi(lp+3);
		if (!memcmp(lp,"PY=",3)) pt.y=atoi(lp+3);
		if (!memcmp(lp,"ALT=",3)) iAlt=atoi(lp+3);
		if (!memcmp(lp,"COL=",4)) iCol1=ColorConvert(lp+4);
		if (!memcmp(lp,"BG=",3)) iCol2=ColorConvert(lp+3);
		if (!memcmp(lp,"BOLD=",5)) fBold=atoi(lp+5);
		
		if (*lp=='*') 
		{
			//printf("Stampo: %d,%d,%s" CRLF,pt.x,pt.y,szTesto);
			//ehLogWrite("Stampo: %d,%d,%s",pt.x,pt.y,szTesto);
			LPrint(hDClone,pt.x,pt.y,iCol1,iCol2,"Arial",iAlt,fBold,szTesto);
		}

		lp=strtok(NULL,"|");
	}

	// Mi riprendo la zona di memoria video e la rimetto nell'immagine
	//BmpHeader->biHeight*=-1;
	GetDIBits(
		hDClone,           // handle to device context
		hbCopy,      // handle to bitmap
		0,   // first scan line to set in destination bitmap
		iLy,   // number of scan lines to copy
		lpSorg,    // address of array for bitmap bits
		(BITMAPINFO *) &Img->bmiHeader, // address of structure with bitmap data
		DIB_RGB_COLORS        // RGB or palette index
		);
	
	if (!DeleteDC(hDClone)) 
	{
		ehLogWrite("Errore in cancellazione DC %d",GetLastError());
		ehExit("Errore in cancellazione DC");
	}

//.........这里部分代码省略.........
开发者ID:ferrasrl,项目名称:easyHand,代码行数:101,代码来源:imgResizer.c

示例10: plogpal

void PLWEMFDecoder::GetImage (PLBmpBase & Bmp)
{
	HPALETTE hpal = NULL;
  LPLOGPALETTE plogpal (0);

  if (GetBitsPerPixel() == 8) {
		plogpal = (LPLOGPALETTE)new PLBYTE[sizeof(LOGPALETTE) + (sizeof(PALETTEENTRY) * 256)];
		memset(plogpal,0x0,sizeof(LOGPALETTE) + sizeof(PALETTEENTRY)*256);
		plogpal->palVersion = 0x300;
		plogpal->palNumEntries = 256;
		if (plogpal == NULL) {
			PLASSERT(false);
			raiseError (PL_ERRNO_MEMORY,"Cannot allocate palette.");
		}
    UINT pe = GetEnhMetaFilePaletteEntries(m_hemf, 0, NULL);
		GetEnhMetaFilePaletteEntries(m_hemf, pe, plogpal->palPalEntry);
	}

	// Setup a logical palette for our memory dc and also a
	// paintlib compatible palette for the paintlib bitmap
  PLPixel32 pPal[256];
	if (plogpal) {
		for (UINT i = 0; i < 256; i++) {
			pPal[i] = *(PLPixel32*)&plogpal->palPalEntry[i];
		}

		if ((hpal = CreatePalette((LPLOGPALETTE)plogpal))) {
			m_holdpal = SelectPalette(m_memdc, hpal, false);
			RealizePalette(m_memdc);
		}
		Bmp.SetPalette(pPal);
		delete [] plogpal;
	}

	// Play the metafile into the device context
	// First, setup a bounding rectangle and fill
	// the memory dc with white (some metafiles only
	// use a black pen to draw and have no actual fill
	// color set, This would cause a black on black
	// painting which is rather useless
	RECT rc;
	rc.left = rc.top = 0;
	rc.bottom = GetHeight();
	rc.right = GetWidth();

	FillRect(m_memdc,&rc,(HBRUSH)GetStockObject(WHITE_BRUSH));

	// Heeere we go....
	BOOL bres = PlayEnhMetaFile(m_memdc,m_hemf,&rc);

	// Finally, convert the Windows bitmap into a paintlib bitmap
	PLWinBmp& winbmp = dynamic_cast<PLWinBmp&>(Bmp);
	BITMAPINFO* pBMI = (BITMAPINFO*)winbmp.GetBMI();
	PLBYTE* pBits = (PLBYTE*)winbmp.GetBits();
	if (GetBitsPerPixel() == 8) {
		GetDIBits(m_dc, m_bm, 0, GetHeight(), winbmp.GetBits(), pBMI, DIB_RGB_COLORS);
	}
	else {
		GetDIBits(m_dc, m_bm, 0, GetHeight(), winbmp.GetBits(), pBMI, DIB_PAL_COLORS);
	}
}
开发者ID:JesperMikkelsen,项目名称:Big-Numbers,代码行数:61,代码来源:plwemfdec.cpp

示例11: CxImage

//////////////////////////////////////////////////////////////////////////////
// CMainFrame message handlers
void CMainFrame::OnEditPaste() 
{
	CDemoDoc *NewDoc=(CDemoDoc*)((CDemoApp*)AfxGetApp())->demoTemplate->OpenDocumentFile(NULL); 

	if (NewDoc)
	{
		if (OpenClipboard())
		{
			HANDLE hData=NULL;
			
			if (hData = GetClipboardData(((CDemoApp*)AfxGetApp())->GetCF())){ //custom CxImage object
				CxImage *newima = new CxImage();
				DWORD dwSize = GlobalSize(hData);
				if (dwSize) {
					BYTE *lpVoid = (BYTE *)GlobalLock(hData);
					newima->UnDump(lpVoid);
					GlobalUnlock(lpVoid);
				}
				NewDoc->image = newima;
			} else if (hData = GetClipboardData(CF_DIB)){ // check if bitmap
				CxImage *newima = new CxImage();
				newima->CreateFromHANDLE(hData);
				NewDoc->image = newima;
			} else  {		
#if CXIMAGE_SUPPORT_WMF
				if (hData = GetClipboardData(CF_ENHMETAFILE)) //check if metafile
				{
					HENHMETAFILE hMeta = (HENHMETAFILE)hData;
					ENHMETAHEADER emh;
					GetEnhMetaFileHeader(hMeta, sizeof(emh), &emh); 

					int	cx,cy;
					cx = (int)((emh.rclBounds.right - emh.rclBounds.left)/2.54);
					cy = (int)((emh.rclBounds.bottom - emh.rclBounds.top)/2.54);

					HDC hDC0 = ::GetDC(0); // screen dc
					HBITMAP hBitmap = CreateCompatibleBitmap(hDC0, cx, cy);
					HDC	hDC = CreateCompatibleDC(hDC0);	// memory dc compatible with screen
					::ReleaseDC(0, hDC0);	// don't need anymore. get rid of it.

					if (hDC && hBitmap){

						RECT rc = {0,0,cx,cy};
						int bpp = ::GetDeviceCaps(hDC, BITSPIXEL);

						HBITMAP hBitmapOld = (HBITMAP)SelectObject(hDC, hBitmap);

						// paint the background
						DWORD	dwBack = RGB(255, 255, 255); //GetSysColor(COLOR_WINDOW);
						DWORD OldColor = SetBkColor(hDC, dwBack);
						ExtTextOut(hDC, 0, 0, ETO_OPAQUE, &rc, NULL, 0, NULL);
						SetBkColor(hDC, OldColor);

						// Play the Metafile into Memory DC
						BOOL bRet = PlayEnhMetaFile(hDC, hMeta,	&rc);

						SelectObject(hDC, hBitmapOld);

						CxImage *newima = new CxImage();
						if(bRet && newima->Create(cx, cy, bpp, CXIMAGE_FORMAT_WMF)){
							
							bRet = GetDIBits(hDC, hBitmap, 0,	(UINT)cy, newima->GetBits(),
								             (LPBITMAPINFO)newima->GetDIB(), DIB_RGB_COLORS);

							NewDoc->image = newima;
						}
						else
						{
							delete newima;
						}
					}
					if (hBitmap) DeleteObject(hBitmap);
					if (hDC) DeleteDC(hDC);
				}
#endif
			}
		}

		CloseClipboard();

		CString s;
		s.Format(_T("Clipboard Image %d"),((CDemoApp*)AfxGetApp())->m_nDocCount++);
		NewDoc->SetTitle(s);
		NewDoc->UpdateAllViews(0,WM_USER_NEWIMAGE);
		NewDoc->UpdateStatusBar();
	}
}
开发者ID:Aliceljm1,项目名称:CxImageVS2010,代码行数:89,代码来源:MainFrm.cpp

示例12: HDumpGraf

/* EXPORT->HDumpGraf: dump a BMP image of current display into fname */
void HDumpGraf(char *fname)
{
   BITMAPFILEHEADER FileHeader;
   BITMAPINFOHEADER BitmapHeader;
   BITMAPINFO *Info;
   int ColorTableSize;
   int ImageSize;
   FILE *fp;
   char *img;
   HDC dc = GetDC(theWindow);
   HBITMAP temp = CreateCompatibleBitmap(memDC,1,1);
     
   SelectObject(memDC,temp);
     
   /* retrieve information about the bitmap */
   BitmapHeader.biSize = sizeof(BITMAPINFOHEADER);
   BitmapHeader.biBitCount = 0;
   GetDIBits(memDC,theBitmap,0,0,NULL,&BitmapHeader,BI_RGB);
     
   switch (BitmapHeader.biCompression) {
   case BI_RGB:
      if (BitmapHeader.biBitCount > 8) {
         ColorTableSize = 0;
      }
      else {
         ColorTableSize = BitmapHeader.biClrUsed*sizeof(RGBQUAD);
      }
      break;
   case BI_RLE8:
   case BI_RLE4:
      ColorTableSize = BitmapHeader.biClrUsed*sizeof(RGBQUAD); 
      break;
   case BI_BITFIELDS:
      ColorTableSize = 3*sizeof(DWORD);
   }
     
   Info = (BITMAPINFO *) New(&gcheap,sizeof(BITMAPINFOHEADER) + ColorTableSize);
   memcpy(Info,&BitmapHeader,sizeof(BITMAPINFOHEADER));
     
   ImageSize = BitmapHeader.biSizeImage;
   img = New(&gcheap,ImageSize);
     
   GetDIBits(memDC,theBitmap,0,ClientRect.bottom,img,Info,BI_RGB);
     
   FileHeader.bfType = 0x4d42;  /* 'BM' */
   FileHeader.bfSize = sizeof(BITMAPINFOHEADER) + sizeof(BITMAPFILEHEADER) + 
      ImageSize + ColorTableSize;
   FileHeader.bfReserved1 = FileHeader.bfReserved2 = 0;
   FileHeader.bfOffBits = sizeof(BITMAPFILEHEADER) + sizeof(BITMAPINFOHEADER) + ColorTableSize; 
     
   fp = fopen(fname,"wb");
   fwrite(&FileHeader,1,sizeof(BITMAPFILEHEADER),fp);
   fwrite(Info,1,sizeof(BITMAPINFOHEADER) + ColorTableSize,fp);
   fwrite(img,1,ImageSize,fp);
   fclose(fp);

   SelectObject(memDC,theBitmap);
   DeleteObject(temp);
   Dispose(&gcheap,Info);
   Dispose(&gcheap,img);
}
开发者ID:botonchou,项目名称:AlgoFinal,代码行数:62,代码来源:HGraf_WIN32.c

示例13: sizeof

HBITMAP MonitorImageSource::GetImage(int width, int height)
{
   DISPLAY_DEVICE named_device;
   named_device.cb = sizeof(DISPLAY_DEVICE);

   for (int deviceId = 0;;deviceId++) {
      DISPLAY_DEVICE device;
      device.cb = sizeof(DISPLAY_DEVICE);

      BOOL result = ::EnumDisplayDevices(NULL, deviceId, &device, 0);
      if (result == 0) break;

      if (device.StateFlags & DISPLAY_DEVICE_ATTACHED_TO_DESKTOP) {
         result = ::EnumDisplayDevices(device.DeviceName, 0, &named_device, 0);
      }
   }

   HBITMAP hbmScreen = NULL;
   BITMAP bmpScreen;

   // Retrieve the handle to a display device context for the client 
   // area of the window.
   Win32::DisplayDeviceContext hdcScreen("DISPLAY");
   Win32::WindowDeviceContext hdcWindow(::GetDesktopWindow());

   // Create a compatible DC which is used in a BitBlt from the window DC
   Win32::MemoryDeviceContext hdcMemDC(hdcWindow); 

   //This is the best stretch mode
   ::SetStretchBltMode(hdcWindow,HALFTONE);

   //The source DC is the entire screen and the destination DC is the current window (HWND)
   if(!::StretchBlt(hdcWindow, 
      0,0, width, height, 
      hdcScreen,
      0, 0,
      GetSystemMetrics(SM_CXVIRTUALSCREEN),
      GetSystemMetrics(SM_CYVIRTUALSCREEN),
      SRCCOPY))
   {
   }

   // Create a compatible bitmap from the Window DC
   hbmScreen = CreateCompatibleBitmap(hdcWindow, width, height);
   if(!hbmScreen)
   {
      //TODO: Error handling
   }

   // Select the compatible bitmap into the compatible memory DC.
   SelectObject(hdcMemDC,hbmScreen);

   // Bit block transfer into our compatible memory DC.
   if(!BitBlt(hdcMemDC, 
      0,0, width, height, 
      hdcWindow, 
      0,0,
      SRCCOPY))
   {
      //TODO: Error handling
   }

   // Get the BITMAP from the HBITMAP
   GetObject(hbmScreen,sizeof(BITMAP),&bmpScreen);

   BITMAPFILEHEADER   bmfHeader;    
   BITMAPINFOHEADER   bi;

   bi.biSize = sizeof(BITMAPINFOHEADER);    
   bi.biWidth = bmpScreen.bmWidth;    
   bi.biHeight = bmpScreen.bmHeight;  
   bi.biPlanes = 1;    
   bi.biBitCount = 32;    
   bi.biCompression = BI_RGB;    
   bi.biSizeImage = 0;  
   bi.biXPelsPerMeter = 0;    
   bi.biYPelsPerMeter = 0;    
   bi.biClrUsed = 0;    
   bi.biClrImportant = 0;

   DWORD dwBmpSize = ((bmpScreen.bmWidth * bi.biBitCount + 31) / 32) * 4 * bmpScreen.bmHeight;

   // Starting with 32-bit Windows, GlobalAlloc and LocalAlloc are implemented as wrapper functions that 
   // call HeapAlloc using a handle to the process's default heap. Therefore, GlobalAlloc and LocalAlloc 
   // have greater overhead than HeapAlloc.
   HANDLE hDIB = GlobalAlloc(GHND,dwBmpSize); 
   char *lpbitmap = (char *)GlobalLock(hDIB);    

   // Gets the "bits" from the bitmap and copies them into a buffer 
   // which is pointed to by lpbitmap.
   GetDIBits(hdcWindow, hbmScreen, 0,
      (UINT)bmpScreen.bmHeight,
      lpbitmap,
      (BITMAPINFO *)&bi, DIB_RGB_COLORS);

   // A file is created, this is where we will save the screen capture.
   HANDLE hFile = CreateFile(L"captureqwsx.bmp",
      GENERIC_WRITE,
      0,
      NULL,
//.........这里部分代码省略.........
开发者ID:bstewart00,项目名称:remote-screen,代码行数:101,代码来源:MonitorImageSource.cpp

示例14: fbx_init

int fbx_init(fbx_struct *fb, fbx_wh wh, int width_, int height_, int useShm)
{
	int width, height;
	int rmask, gmask, bmask, ps, i;
	#ifdef _WIN32
	BMINFO bminfo;  HBITMAP hmembmp=0;  RECT rect;  HDC hdc=NULL;
	#else
	XWindowAttributes xwa;  int shmok=1, alphaFirst, pixmap=0;
	#endif

	if(!fb) _throw("Invalid argument");

	#ifdef _WIN32

	if(!wh) _throw("Invalid argument");
	_w32(GetClientRect(wh, &rect));
	if(width_>0) width=width_;
	else
	{
		width=rect.right-rect.left;  if(width<=0) width=MINWIDTH;
	}
	if(height_>0) height=height_;
	else
	{
		height=rect.bottom-rect.top;  if(height<=0) height=MINHEIGHT;
	}
	if(fb->wh==wh)
	{
		if(width==fb->width && height==fb->height && fb->hmdc && fb->hdib
			&& fb->bits)
			return 0;
		else if(fbx_term(fb)==-1) return -1;
	}
	memset(fb, 0, sizeof(fbx_struct));
	fb->wh=wh;

	_w32(hdc=GetDC(fb->wh));
	_w32(fb->hmdc=CreateCompatibleDC(hdc));
	_w32(hmembmp=CreateCompatibleBitmap(hdc, width, height));
	_w32(GetDeviceCaps(hdc, RASTERCAPS)&RC_BITBLT);
	_w32(GetDeviceCaps(fb->hmdc, RASTERCAPS)&RC_DI_BITMAP);
	bminfo.bmi.bmiHeader.biSize=sizeof(BITMAPINFOHEADER);
	bminfo.bmi.bmiHeader.biBitCount=0;
	_w32(GetDIBits(fb->hmdc, hmembmp, 0, 1, NULL, &bminfo.bmi, DIB_RGB_COLORS));
	_w32(GetDIBits(fb->hmdc, hmembmp, 0, 1, NULL, &bminfo.bmi, DIB_RGB_COLORS));
	_w32(DeleteObject(hmembmp));  hmembmp=0;
		/* (we only needed it to get the screen properties) */
	ps=bminfo.bmi.bmiHeader.biBitCount/8;
	if(width>0) bminfo.bmi.bmiHeader.biWidth=width;
	if(height>0) bminfo.bmi.bmiHeader.biHeight=height;
	fb->width=bminfo.bmi.bmiHeader.biWidth;
	fb->height=bminfo.bmi.bmiHeader.biHeight;

	if(ps<3)
	{
		/* Make the buffer BGRA */
		bminfo.bmi.bmiHeader.biCompression=BI_BITFIELDS;
		bminfo.bmi.bmiHeader.biBitCount=32;
		ps=4;
		(*(DWORD *)&bminfo.bmi.bmiColors[0])=0xFF0000;
		(*(DWORD *)&bminfo.bmi.bmiColors[1])=0xFF00;
		(*(DWORD *)&bminfo.bmi.bmiColors[2])=0xFF;
	}

	fb->pitch=BMPPAD(fb->width*ps);  /* Windoze bitmaps are always padded */

	if(bminfo.bmi.bmiHeader.biCompression==BI_BITFIELDS)
	{
		rmask=(*(DWORD *)&bminfo.bmi.bmiColors[0]);
		gmask=(*(DWORD *)&bminfo.bmi.bmiColors[1]);
		bmask=(*(DWORD *)&bminfo.bmi.bmiColors[2]);
	}
	else
	{
		rmask=0xFF0000;
		gmask=0xFF00;
		bmask=0xFF;
	}

	fb->format=-1;
	for(i=0; i<FBX_FORMATS; i++)
		if(rmask==fbx_rmask[i] && gmask==fbx_gmask[i] && bmask==fbx_bmask[i]
			&& ps==fbx_ps[i] && fbx_alphafirst[i]==0) fb->format=i;
	if(fb->format==-1) _throw("Display has unsupported pixel format");

	bminfo.bmi.bmiHeader.biHeight=-bminfo.bmi.bmiHeader.biHeight;
		/* (our convention is top-down) */
	_w32(fb->hdib=CreateDIBSection(hdc, &bminfo.bmi, DIB_RGB_COLORS,
		(void **)&fb->bits, NULL, 0));
	_w32(SelectObject(fb->hmdc, fb->hdib));
	ReleaseDC(fb->wh, hdc);
	return 0;

	finally:
	if(hmembmp) DeleteObject(hmembmp);
	if(hdc) ReleaseDC(fb->wh, hdc);

	#else

	if(!wh.dpy || !wh.d) _throw("Invalid argument");
//.........这里部分代码省略.........
开发者ID:coffee8651,项目名称:turbovnc,代码行数:101,代码来源:fbx.c

示例15: takescreenshot

/*
	Takes a screenshot of the screen and saves it in memory
*/
int takescreenshot(unsigned char **screenshotbuffer,int *screenshotbuffersize){
	//declaring & initializing needed vars
	HDC screendc = NULL;
	HDC compatiblescreendc = NULL;
	HBITMAP compatiblebitmap = NULL;
	HGDIOBJ selectedobject = NULL;
	BOOL bitbltresult = FALSE;
	int getobjectresult = 0;
	BITMAP finalbmp = {0};
	BITMAPFILEHEADER bmfileheader = {0};    
	BITMAPINFOHEADER bminfoheader = {0};
	DWORD dwBmpSize = 0;
	HANDLE hDIB = NULL;
	unsigned char *lpbitmap = NULL;
	int getdibitsresult = 0;	
	DWORD dwSizeofDIB = 0;
	int screenwidth = 0;
	int screenheight = 0;
	int leftxscreenpos = 0;
	int leftyscreenpos = 0;	
	char currentpath[MAX_PATH] = {0};

	//left side virtual screen coordinates
	leftxscreenpos = GetSystemMetrics(SM_XVIRTUALSCREEN);
	//top side virtual screen coordinates
	leftyscreenpos = GetSystemMetrics(SM_YVIRTUALSCREEN);	
	//width in pixels of the virtual screen
	screenwidth = GetSystemMetrics(SM_CXVIRTUALSCREEN);
	//height in pixels of the virtual screen
	screenheight = GetSystemMetrics(SM_CYVIRTUALSCREEN);
	/*actually take the screenshot*/
	screendc = GetDC(NULL); 
	if(screendc == NULL){
		outputerror(DBG_ERROR,"%s\n","takescreenshot::GetDC() Failed");
		return 1;
	}
	compatiblescreendc = CreateCompatibleDC(screendc);
	if(compatiblescreendc == NULL){
		outputerror(DBG_ERROR,"%s\n","takescreenshot::CreateCompatibleDC() Failed");
		ReleaseDC(NULL,screendc);
		return 1;
	}
	compatiblebitmap = CreateCompatibleBitmap(screendc,screenwidth,screenheight);
	if(compatiblebitmap == NULL){
		outputerror(DBG_ERROR,"%s\n","takescreenshot::CreateCompatibleBitmap() Failed");
		ReleaseDC(NULL,screendc);
		DeleteDC(compatiblescreendc);
		return 1;
	}
	selectedobject = SelectObject(compatiblescreendc,compatiblebitmap);
	if(selectedobject == NULL || selectedobject == HGDI_ERROR){
		outputerror(DBG_ERROR,"%s\n","takescreenshot::SelectObject() Failed");
		ReleaseDC(NULL,screendc);
		DeleteDC(compatiblescreendc);
		DeleteObject(compatiblebitmap);
		return 1;
	}
	bitbltresult = BitBlt(compatiblescreendc,0,0,screenwidth,screenheight,screendc,leftxscreenpos,leftyscreenpos,SRCCOPY);
	if(bitbltresult == 0){
		outputerror(DBG_ERROR,"%s %d\n","takescreenshot::BitBlt() Failed", GetLastError());
		ReleaseDC(NULL,screendc);
		DeleteDC(compatiblescreendc);
		DeleteObject(compatiblebitmap);		
		return 1;
	}
	/*save the screenshot to file*/
	getobjectresult = GetObject(compatiblebitmap,sizeof(BITMAP),&finalbmp);
	if(getobjectresult == 0){
		outputerror(DBG_ERROR,"%s\n","takescreenshot::GetObject() Failed");
		ReleaseDC(NULL,screendc);
		DeleteDC(compatiblescreendc);
		DeleteObject(compatiblebitmap);
		return 1;
	}

	//bmp file format good read: http://en.wikipedia.org/wiki/BMP_file_format
	bminfoheader.biSize = sizeof(BITMAPINFOHEADER);    
    bminfoheader.biWidth = screenwidth;    
    bminfoheader.biHeight = screenheight;  
    bminfoheader.biPlanes = 1;    
    bminfoheader.biBitCount = 32;    
    bminfoheader.biCompression = BI_RGB;    
    bminfoheader.biSizeImage = 0;  
    bminfoheader.biXPelsPerMeter = 0;    
    bminfoheader.biYPelsPerMeter = 0;    
    bminfoheader.biClrUsed = 0;    
    bminfoheader.biClrImportant = 0;

	dwBmpSize = ((screenwidth * bminfoheader.biBitCount + 31) / 32) * 4 * screenheight;

	hDIB = GlobalAlloc(GHND,dwBmpSize); 
    lpbitmap = (unsigned char *)GlobalLock(hDIB);  
	//get the actual bitmap 'bits'
	getdibitsresult = GetDIBits(compatiblescreendc, compatiblebitmap, 0,(UINT)finalbmp.bmHeight, lpbitmap, (BITMAPINFO *)&bminfoheader, DIB_RGB_COLORS);
	if(getdibitsresult == 0){
		outputerror(DBG_ERROR,"%s\n","takescreenshot::GetDIBits() Failed");
		ReleaseDC(NULL,screendc);
//.........这里部分代码省略.........
开发者ID:DiabloHorn,项目名称:cryptoshot,代码行数:101,代码来源:screenshot.c


注:本文中的GetDIBits函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。