Example #1
0
void DrawImageStretched( HDC hDC, HBITMAP hBitmap, RECT& rcSource, RECT& rcDest )
{
	ASSERT( hBitmap != nullptr );
	HDC hdcMem = CreateCompatibleDC( hDC );
	if( hdcMem )
	{
		//	Select new bitmap and backup old bitmap
		HBITMAP hbmOld = SelectBitmap( hdcMem, hBitmap );

		//	Fetch and blit bitmap
		BITMAP bm;
		if( GetObject( hBitmap, sizeof( bm ), &bm ) == sizeof( bm ) )
		{
			//	Blit!
			SetStretchBltMode( hDC, BLACKONWHITE );
			StretchBlt( hDC,
						rcDest.left, rcDest.top, ( rcDest.right - rcDest.left ), ( rcDest.bottom - rcDest.top ),
						hdcMem, 
						rcSource.left, rcSource.top, ( rcSource.right - rcSource.left ), ( rcSource.bottom - rcSource.top ),
						SRCCOPY );
		}

		//	Restore old bitmap
		SelectBitmap( hdcMem, hbmOld );

		//	Discard MemDC
		DeleteDC( hdcMem );
	}
}
Example #2
0
HRGN RegionFromSkinWithOffset(HBITMAP hBmp, COLORREF crMask, int offset, int bWidth){
	
	HRGN		hRgn = CreateRectRgn(0, 0, 0, 0);
	int			x = offset;
	BITMAP		bmp;
	HDC			hdcMem;
	HBITMAP		hbOld;

	bWidth += offset;
	hdcMem = CreateCompatibleDC(GetDC(0));
	hbOld = SelectBitmap(hdcMem, hBmp);
	GetObject(hBmp, sizeof(bmp), &bmp);
	for(int y = 0; y < bmp.bmHeight; y++){
		do{
			while(x < bWidth && GetPixel(hdcMem, x, y) == crMask)
				x++;
			int leftX = x;
			while(x < bWidth && GetPixel(hdcMem, x, y) != crMask)
				++x;
			HRGN rgnTemp = CreateRectRgn(leftX, y, x, y + 1);
			CombineRgn(hRgn, hRgn, rgnTemp, RGN_OR);
			DeleteRgn(rgnTemp);
		}while(x < bWidth);
		x = offset;
	}
	SelectBitmap(hdcMem, hbOld);
	DeleteDC(hdcMem);
	return hRgn;
}
Example #3
0
void DrawImageTiled( HDC hDC, HBITMAP hBitmap, RECT& rcSource, RECT& rcDest )
{
	ASSERT( hBitmap != nullptr );
	HDC hdcMem = CreateCompatibleDC( hDC );
	if( hdcMem )
	{
		//	Select new bitmap and backup old bitmap
		HBITMAP hbmOld = SelectBitmap( hdcMem, hBitmap );

		//	Fetch and blit bitmap
		BITMAP bm;
		if( GetObject( hBitmap, sizeof( bm ), &bm ) == sizeof( bm ) )
		{
			//	Blit!
			//	Truncate the source rect if bigger than container
			if( rcSource.left < rcDest.left )
				rcSource.left += ( rcDest.left - rcSource.left );

			if( rcSource.top < rcDest.top )
				rcSource.top += ( rcDest.top - rcSource.top );

			int nSourceWidth = rcSource.right - rcSource.left;
			int nSourceHeight = rcSource.bottom - rcSource.top;

			int nTargetWidth = rcDest.right - rcDest.left;
			int nTargetHeight = rcDest.bottom - rcDest.top;

			int nWidthRemaining = nTargetWidth;
			for( int nXOffs = rcDest.left; nXOffs < rcDest.right; nXOffs += nSourceWidth )
			{
				for( int nYOffs = rcDest.top; nYOffs < rcDest.bottom; nYOffs += nSourceHeight )
				{
					int nDestLimitAtX = rcDest.right;
					int nDestLimitAtY = rcDest.bottom;

					int nWidthToCopy = nSourceWidth;
					int nHeightToCopy = nSourceHeight;

					//	If the full width of the source image goes outside the target area,
					//		Clip the rightmost/lower end of it by this much

					if( nXOffs+nSourceWidth > nDestLimitAtX )
						nWidthToCopy -= ( nXOffs+nSourceWidth - nDestLimitAtX );

					if( nYOffs+nSourceHeight >= nDestLimitAtY )
						nHeightToCopy -= ( nYOffs+nSourceHeight - nDestLimitAtY );

					if( ( nXOffs + nWidthToCopy > 0 ) && ( nYOffs + nHeightToCopy > 0 ) )
						BitBlt( hDC, nXOffs, nYOffs, nWidthToCopy, nHeightToCopy, hdcMem, 0, 0, SRCCOPY );
				}
			}
		}

		//	Restore old bitmap
		SelectBitmap( hdcMem, hbmOld );

		//	Discard MemDC
		DeleteDC( hdcMem );
	}
}
Example #4
0
HRGN Label::CreateBackgroundRegion()
{
    HRGN region = NULL;
    
    if (mBackgroundImage)
    {
        // Draw the background into a memory bitmap, then create a region from
        // non-transparent pixels in that bitmap.
        HDC windowDC = GetDC(mWindow);
        
        HDC bufferDC = CreateCompatibleDC(windowDC);
        HBITMAP bufferBitmap = CreateCompatibleBitmap(windowDC, mWidth, mHeight);
        HBITMAP oldBufferBitmap = SelectBitmap(bufferDC, bufferBitmap);
        
        DrawBackground(bufferDC);
        SelectBitmap(bufferDC, oldBufferBitmap);
        region = BitmapToRegion(bufferBitmap, RGB(255, 0, 255), 0, 0, 0);
        
        DeleteDC(bufferDC);
        DeleteBitmap(bufferBitmap);
        
        ReleaseDC(mWindow, windowDC);
    }
    else
    {
        // If there is no background image, the window is always rectangular
        region = CreateRectRgn(0, 0, mWidth, mHeight);
    }
    
    return region;
}
Example #5
0
int Icon::add_to_imagelist(HIMAGELIST himl, HDC hdc_wnd, COLORREF bk_color, HBRUSH bk_brush) const
{
    int ret;

    if (_itype == IT_SYSCACHE) {
        HIMAGELIST himl = g_Globals._icon_cache.get_sys_imagelist();

        int cx, cy;
        ImageList_GetIconSize(himl, &cx, &cy);

        HBITMAP hbmp = CreateCompatibleBitmap(hdc_wnd, cx, cy);
        HDC hdc = CreateCompatibleDC(hdc_wnd);
        HBITMAP hbmp_old = SelectBitmap(hdc, hbmp);
        ImageList_DrawEx(himl, _sys_idx, hdc, 0, 0, cx, cy, bk_color, CLR_DEFAULT, ILD_NORMAL);
        SelectBitmap(hdc, hbmp_old);
        DeleteDC(hdc);

        ret = ImageList_Add(himl, hbmp, 0);

        DeleteObject(hbmp);
    } else
        ret = ImageList_AddAlphaIcon(himl, _hicon, bk_brush, hdc_wnd);

    return ret;
}
Example #6
0
/**
 * @param hdc - drawing conImage.
 * @param prcPaint - the rectangle where the painting is requested.
 */
void CImageView::DrawImageView(HDC hdc, const RECT* prcPaint)
{
	_ASSERTE(g_pResManager != NULL);
	RECT rcClient;
	GetClientRect(m_hwnd, &rcClient);
	if (prcPaint == NULL)
		prcPaint = &rcClient;
	if (IsRectEmpty(prcPaint))
		return;

#ifdef USE_MEM_DC
	int nClientWidth = prcPaint->right - prcPaint->left;
	int nClientHeight = prcPaint->bottom - prcPaint->top;
	HBITMAP hbmpMem;
	hbmpMem = CreateCompatibleBitmap(hdc, nClientWidth, nClientHeight);
	if (hbmpMem == NULL)
		return;
	HDC hdcMem;
	hdcMem = CreateCompatibleDC(hdc);
	if (hdcMem == NULL)
	{
		DeleteBitmap(hbmpMem);
		return;
	}
	SetViewportOrgEx(hdcMem, -prcPaint->left, -prcPaint->top, NULL);
	HBITMAP hbmpSafe = SelectBitmap(hdcMem, hbmpMem);
#else
	// CS_PARENTDC sets the clipping rectangle of the child window to that of the parent window
	// so that the child can draw on the parent. Text view inherits this style from sub-classed
	// static control. This causes problems with unclipped TabbedTextOut() output.
	HRGN hrgn = CreateRectRgnIndirect(prcPaint);
	SelectClipRgn(hdc, hrgn);
	DeleteRgn(hrgn);
	HDC hdcMem = hdc;
#endif

	FillRect(hdcMem, prcPaint, g_pResManager->m_hbrWindowBrush);
	HDC hdcTemp = CreateCompatibleDC(hdc);
	if (hdcTemp)
	{
		HBITMAP hbmpSafe2 = SelectBitmap(hdcTemp, m_hAdjustedBitmap);
		int nHorPos = GetScrollPos(m_hwnd, SB_HORZ);
		int nVertPos = GetScrollPos(m_hwnd, SB_VERT);
		int nImageLeft = rcClient.right > m_szAjustedBitmapSize.cx ? (rcClient.right - m_szAjustedBitmapSize.cx) / 2 : -nHorPos;
		int nImageTop = rcClient.bottom > m_szAjustedBitmapSize.cy ? (rcClient.bottom - m_szAjustedBitmapSize.cy) / 2 : -nVertPos;
		BitBlt(hdcMem, nImageLeft, nImageTop, m_szAjustedBitmapSize.cx, m_szAjustedBitmapSize.cy, hdcTemp, 0, 0, SRCCOPY);
		SelectBitmap(hdcTemp, hbmpSafe2);
		DeleteDC(hdcTemp);
	}

#ifdef USE_MEM_DC
	BitBlt(hdc, prcPaint->left, prcPaint->top, nClientWidth, nClientHeight, hdcMem, prcPaint->left, prcPaint->top, SRCCOPY);
	SelectBitmap(hdcMem, hbmpSafe);
	DeleteDC(hdcMem);
	DeleteBitmap(hbmpMem);
#endif
}
Example #7
0
void drawHwndToFile(HWND hwnd, char *filename) {
	HDC hdc, hdcMem;
	HBITMAP hBitmap, hbmpOld;
	RECT rect;
	long w,h;

	FILE *fp = NULL;
	unsigned char *pixels;
	BITMAPINFO bmi;
	BITMAPFILEHEADER bmfilehdr;
	
	GetClientRect(hwnd, &rect);
	w = rect.right - rect.left;
	h = rect.bottom - rect.top;
	hdc = GetDC(hwnd);
	/* use a temp DC to copy the bits to a new bitmap */
	hBitmap = CreateCompatibleBitmap(hdc, w, h);
	hdcMem = CreateCompatibleDC(hdc);
	hbmpOld = SelectBitmap(hdcMem, hBitmap);
	BitBlt(hdcMem, 0, 0, w, h, hdc, 0, 0, SRCCOPY);
	SelectBitmap(hdcMem, hbmpOld);
	DeleteDC(hdcMem);

	/* copy over the bits to memory */
	memset(&bmi, 0, sizeof(BITMAPINFO));
	bmi.bmiHeader.biSize = sizeof(BITMAPINFO);
	bmi.bmiHeader.biPlanes = 1;
	bmi.bmiHeader.biWidth = w;
	bmi.bmiHeader.biHeight = h;
	bmi.bmiHeader.biBitCount = 24;
	bmi.bmiHeader.biCompression = BI_RGB;
	pixels = malloc((w + w%4) * h * 3); //scanlines must end on 4 byte boundries
	if (pixels == NULL) {
		MessageBox(hwnd, "Could not allocate memory for bitmap", "Error", MB_OK|MB_ICONERROR);
		return;
	}

	GetDIBits(hdc, hBitmap, 0, h, pixels, &bmi, DIB_RGB_COLORS);

	bmfilehdr.bfReserved1 = 0;
	bmfilehdr.bfReserved2 = 0;
	bmfilehdr.bfSize = sizeof(BITMAPFILEHEADER) + sizeof(BITMAPINFOHEADER) + bmi.bmiHeader.biSizeImage;
	bmfilehdr.bfType = 'MB';
	bmfilehdr.bfOffBits = sizeof(BITMAPFILEHEADER) + sizeof(BITMAPINFOHEADER);

	fopen_s(&fp, filename, "wb");
	fwrite(&bmfilehdr, sizeof(BITMAPFILEHEADER), 1, fp);
	fwrite(&bmi.bmiHeader, sizeof(BITMAPINFOHEADER), 1, fp);
	fwrite(pixels, bmi.bmiHeader.biSizeImage, 1, fp);
	fclose(fp);

	free(pixels);
	DeleteBitmap(hBitmap);
	//DeleteDC(hdcMem);
	ReleaseDC(hwnd, hdc);
}
Example #8
0
// Draws the bitmap in a disabled appearance. This routine assumes the
// bitmap has already been selected into the memory DC
static void NEAR
DisabledBitBlt(HDC hDestDC, RECT &r, HDC hMemDC)
{
	HDC			hMonoDC;
	HBITMAP		hMonoBitmap, hOldBitmap;
	HBRUSH		hOldBrush;
	int			nWidth = r.right - r.left;
	int			nHeight = r.bottom - r.top;
#ifndef _WIN32
	HBRUSH		hShadowBrush = CreateSolidBrush(GetSysColor(COLOR_BTNSHADOW));
#endif

	// Create a monochrome bitmap and HDC
	hMonoBitmap = CreateBitmap(nWidth, nHeight, 1, 1, NULL);
	hMonoDC = CreateCompatibleDC(NULL);
	hOldBitmap = SelectBitmap(hMonoDC, hMonoBitmap);

	// Create a mask where the button face color is 1 and everything else is 0
	SetBkColor(hMemDC, GetSysColor(COLOR_BTNFACE));
	BitBlt(hMonoDC, 0, 0, nWidth, nHeight, hMemDC, 0, 0, SRCCOPY);

	SetTextColor(hDestDC, 0L);                  // 0's in mono -> 0 (for ROP)
	SetBkColor(hDestDC, (COLORREF)0x00FFFFFFL); // 1's in mono -> 1
	
	// Every place the mask has a 0 pixel draw with button highlight color
#ifdef _WIN32
	hOldBrush = SelectBrush(hDestDC, GetSysColorBrush(COLOR_BTNHILIGHT));
#else
	hOldBrush = SelectBrush(hDestDC, GetStockObject(WHITE_BRUSH));
#endif
	BitBlt(hDestDC, r.left + 1, r.top + 1, nWidth - 1, nHeight - 1, hMonoDC,
		0, 0, ROP_PSDPxax);

	// Every place the mask has a 0 pixel draw with button shadow color
#ifdef _WIN32
	SelectBrush(hDestDC, GetSysColorBrush(COLOR_BTNSHADOW));
#else
	SelectBrush(hDestDC, hShadowBrush);
#endif
	BitBlt(hDestDC, r.left, r.top, nWidth, nHeight, hMonoDC,
		0, 0, ROP_PSDPxax);

	// Restore the destination HDC
	SelectBrush(hDestDC, hOldBrush);
#ifndef _WIN32
	DeleteObject(hShadowBrush);
#endif

	// Destroy the GDI objects
	SelectBitmap(hMonoDC, hOldBitmap);
	DeleteBitmap(hMonoBitmap);
	DeleteDC(hMonoDC);
}
Example #9
0
/*!
	AAのサムネ用イメージを作る
	@param[in]		hWnd	ウインドウハンドル
	@param[in,out]	pstItem	イメージ作りたいAAのデータとか
*/
UINT DraughtAaImageing( HWND hWnd, LPAAMATRIX pstItem )
{
	UINT_PTR	cchSize;
	LPTSTR		ptTextaa;
	INT		iRslt, iYdot, iXdot, iLine;
	HDC		hdc, hMemDC;
	HBITMAP	hOldBmp;
	RECT	rect;



	ptTextaa = SjisDecodeAlloc( pstItem->pcItem );
	StringCchLength( ptTextaa, STRSAFE_MAX_CCH, &cchSize );

	//	元AAのサイズ確定が必要
	iXdot = TextViewSizeGet( ptTextaa, &iLine );
	iYdot = iLine * LINE_HEIGHT;

	pstItem->iMaxDot = iXdot;
	pstItem->iLines  = iLine;

	if( giItemWidth >  iXdot )	iXdot = giItemWidth;
	if( giItemHeight > iYdot )	iYdot = giItemHeight;

	pstItem->stSize.cx = iXdot;
	pstItem->stSize.cy = iYdot;

	SetRect( &rect, 0, 0, iXdot, iYdot );
	//	あんまり大きいなら、左上限定とか?

	//	描画用ビットマップ作成
	hdc = GetDC( hWnd );

	//	サムネ用BMP・これはフルサイズ	//	pstItem->hThumbDC	pstItem->hOldBmp
	hMemDC = CreateCompatibleDC( hdc );
	pstItem->hThumbBmp = CreateCompatibleBitmap( hdc, rect.right, rect.bottom );
	hOldBmp = SelectBitmap( hMemDC, pstItem->hThumbBmp );
	SelectFont( hMemDC, ghAaFont );

	ReleaseDC( ghDraughtWnd, hdc );

	iRslt = PatBlt( hMemDC, 0, 0, rect.right, rect.bottom, WHITENESS );

	iRslt = DrawText( hMemDC, ptTextaa, cchSize, &rect, DT_LEFT | DT_NOPREFIX | DT_NOCLIP | DT_WORDBREAK );

	SelectFont( hMemDC, GetStockFont(DEFAULT_GUI_FONT) );
	SelectBitmap( hMemDC, hOldBmp );
	DeleteDC( hMemDC );

	FREE( ptTextaa );

	return 0;
}
Example #10
0
void gOnPaint(HWND hwnd)
{
  PAINTSTRUCT ps;
  HDC hdc = BeginPaint(hwnd,&ps);
  HDC hdcMem = CreateCompatibleDC(NULL);
  HBITMAP hbmT = SelectBitmap(hdcMem,hbm[birds]);
  BITMAP bm;
  GetObject(hbm[birds],sizeof(bm),&bm);
  BitBlt(hdc,0,0,bm.bmWidth,bm.bmHeight,hdcMem,0,0,SRCCOPY);
  SelectBitmap(hdcMem,hbmT);
  DeleteDC(hdcMem);
  EndPaint(hwnd,&ps);
}  
Example #11
0
/// Function name  : utilSetDeviceContextBitmap
// Description     : Selects a bitmap into a device context
// 
// DC_STATE*  pPrevState : [in] DeviceContextState
// HBITMAP    hBitmap    : [in] New bitmap to apply
//
UtilityAPI 
VOID  utilSetDeviceContextBitmap(DC_STATE*  pPrevState, HBITMAP  hBitmap)
{
   /// [BITMAP] Change mode and update state
   pPrevState->hOldBitmap = SelectBitmap(pPrevState->hDC, hBitmap);
   pPrevState->eState    |= DCC_BITMAP;
}
Example #12
0
BOOL OnCreate(HWND hwnd, LPCREATESTRUCT lpCreateStruct)
{
    LOGFONT lf;
    ZeroMemory(&lf, sizeof(LOGFONT));
    
    lf.lfHeight = 128;
    lf.lfWeight = FW_HEAVY;
    wcscpy_s(lf.lfFaceName, 32, L"agency fb");
    
    // lf.lfHeight = 96;
    // lf.lfWeight = FW_HEAVY;
    // wcscpy_s(lf.lfFaceName, 32, L"consolas");
    
    g_app.hFont = CreateFontIndirect(&lf);
    g_app.hPen = CreatePen(PS_SOLID, 1, RGB(0x80, 0x00, 0x00));

    HDC hdc = GetDC(hwnd);
    g_app.hdcMem = CreateCompatibleDC(hdc);
    g_app.hBmp = CreateCompatibleBitmap(hdc, GetSystemMetrics(SM_CXSCREEN), GetSystemMetrics(SM_CYSCREEN));
    SelectBitmap(g_app.hdcMem, g_app.hBmp);
    ReleaseDC(hwnd, hdc);

    SetTimer(hwnd, 1, 1, NULL);
    SetTimer(hwnd, 2, 10, NULL);
    SetTimer(hwnd, 3, 100, NULL);
    SetTimer(hwnd, 4, 1000, NULL);

    ShowWindow(hwnd, SW_SHOW);
    return TRUE;
}
Example #13
0
// ÓÎÏ·³õʼ»¯
BOOL GameInit(HWND hWnd)
{
	HDC hdc = GetDC(hWnd);
	g_hdcMem = CreateCompatibleDC(hdc);
	g_hdcMem1 = CreateCompatibleDC(hdc);
	g_hBmpMem = CreateCompatibleBitmap(hdc, 640, 480);
	SelectBitmap(g_hdcMem, g_hBmpMem);
	ReleaseDC(hWnd, hdc);

	// ¼ÓÔØλͼ
	g_hBmpBackground = (HBITMAP)LoadImage(g_hInst, _T("Res/background.bmp"), IMAGE_BITMAP, 640, 480, LR_LOADFROMFILE);
	g_hBmpPlayer = (HBITMAP)LoadImage(g_hInst, _T("Res/boy.bmp"), IMAGE_BITMAP, 280, 992, LR_LOADFROMFILE);

	g_nWidth = 70;
	g_nHeight = 124;
	g_ptActive.x = 320;
	g_ptActive.y = 240;
	g_emDirection = DOWN;
	g_nDistance = 5;
	g_bMove = FALSE;
	
	SetRect(&g_rtClip, 35, 62, 640-35, 480-62);
	SetRect(&g_rtBk, -320, -240, 320, 240);

	return TRUE;
}
      // Draw text to full-screen sized bitmap, cleared to <bgcolor>
      // Draw boxes for each word on EyeLink tracker display if <dotrack> set
      // Use font selected with get_new_font(), and draws it in <fgcolor>
      // RECT <margins> sets margins, and <lspace> sets pixels between lines
HBITMAP text_bitmap(char *txt, COLORREF fgcolor, COLORREF bgcolor, 
                               RECT margins, int lspace, int dotrack)
{
  HDC hdc;
  HBITMAP hbm;
  HDC mdc;
  HBRUSH oBrush;
  HBITMAP obm;

  hdc = GetDC(NULL);                 
  mdc = CreateCompatibleDC(hdc);     // create display-compatible memory context
  hbm = CreateCompatibleBitmap(hdc, SCRWIDTH, SCRHEIGHT);
  obm = SelectObject(mdc, hbm);      // create DDB bitmap, select into context
                                     
  oBrush = SelectObject(mdc, CreateSolidBrush(bgcolor | 0x02000000L));  // brush to fill with 
  PatBlt(mdc, 0, 0, SCRWIDTH, SCRHEIGHT, PATCOPY);                      // CLEAR BITMAP
  DeleteObject(SelectObject(mdc, oBrush));

  draw_text_box(mdc, txt, fgcolor, margins, lspace, dotrack);  // DRAW THE TEXT

  GdiFlush();     // ADDED for Wimdows 2000/XP: Forces drawing to be immediate      

  SelectBitmap(mdc, obm);     // Release the GDI resources
  DeleteDC(mdc);
  ReleaseDC(NULL, hdc);
  return hbm;                 // Return the new bitmap
}
Example #15
0
static void create_memory_dc(struct graphics_priv *gr)
{
    HDC hdc;
    BITMAPINFO bOverlayInfo;

    if (gr->hMemDC)
    {
        (void)SelectBitmap(gr->hMemDC, gr->hOldBitmap);
        DeleteBitmap(gr->hBitmap);
        DeleteDC(gr->hMemDC);

        (void)SelectBitmap(gr->hPrebuildDC, gr->hOldPrebuildBitmap);
        DeleteBitmap(gr->hPrebuildBitmap);
        DeleteDC(gr->hPrebuildDC);
        gr->hPrebuildDC = 0;
    }


    hdc = GetDC( gr->wnd_handle );
    // Creates memory DC
    gr->hMemDC = CreateCompatibleDC(hdc);
    dbg(0, "resize memDC to: %d %d \n", gr->width, gr->height );


#ifndef  FAST_TRANSPARENCY

    memset(&bOverlayInfo, 0, sizeof(BITMAPINFO));
    bOverlayInfo.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
    bOverlayInfo.bmiHeader.biWidth = gr->width;
    bOverlayInfo.bmiHeader.biHeight = -gr->height;
    bOverlayInfo.bmiHeader.biBitCount = 32;
    bOverlayInfo.bmiHeader.biCompression = BI_RGB;
    bOverlayInfo.bmiHeader.biPlanes = 1;
    gr->hPrebuildDC = CreateCompatibleDC(NULL);
    gr->hPrebuildBitmap = CreateDIBSection(gr->hMemDC, &bOverlayInfo, DIB_RGB_COLORS , (void **)&gr->pPixelData, NULL, 0);
    gr->hOldPrebuildBitmap = SelectBitmap(gr->hPrebuildDC, gr->hPrebuildBitmap);

#endif
    gr->hBitmap = CreateCompatibleBitmap(hdc, gr->width, gr->height );

    if ( gr->hBitmap )
    {
        gr->hOldBitmap = SelectBitmap( gr->hMemDC, gr->hBitmap);
    }
    ReleaseDC( gr->wnd_handle, hdc );
}
Example #16
0
void Label::DrawImage(HDC hDC, int x, int y)
{
    int w = 0;
    int h = 0;
    
    // Get the image's size
    GetLSBitmapSize(mImage, &w, &h);
    
    HDC imageDC = CreateCompatibleDC(hDC);
    HBITMAP oldImageBitmap = SelectBitmap(imageDC, mImage);
    
    // Draw the image transparently
    TransparentBltLS(hDC, x, y, w, h, imageDC, 0, 0, RGB(255, 0, 255));
    
    SelectBitmap(imageDC, oldImageBitmap);
    DeleteDC(imageDC);
}
Example #17
0
/* This finishes a drag operation.
 */
WINCOMMCTRLAPI void WINAPI EXPORT Amctl_ImageList_EndDrag( void )
{
   Amctl_ImageList_DragLeave( hwndDrag );
   SelectBitmap( hdcSaved, hbmpOldSaved );
   DeleteDC( hdcSaved );
   DeleteBitmap( hbmpSaved );
   Amctl_ImageList_Destroy( himlDrag );
   himlDrag = NULL;
}
Example #18
0
void OnDestroy(HWND hwnd)
{
    if (g_hdcMem != NULL) {
        HBITMAP hBmpOld = SelectBitmap(g_hdcMem, NULL);
        if (hBmpOld != NULL) DeleteBitmap(hBmpOld);
        DeleteDC(g_hdcMem);
    }
    PostQuitMessage(0);
}
Example #19
0
void xcfg_OnPaint(  HWND hwnd){
  cPaintCanvas canvas(hwnd);
  cMemCanvas canvMem(/*like*/canvas);
  HGDIOBJ hbmT = canvMem.SelectObject(bmBk);
  BitBlt(canvas,0,0,640,480,canvMem,0,0,SRCCOPY);
  SliceM->draw(canvas);
  SelectBitmap(canvMem,hbmT);
  
 }  
Example #20
0
void WINAPI
DrawBitmapButton(LPDRAWITEMSTRUCT lpdis, HBITMAP hBitmap, HDC hMemDC)
{
	UINT	uState;
	
	// Draw the button borders
#ifdef _WIN32
	uState = DFCS_BUTTONPUSH | DFCS_ADJUSTRECT;

	if (lpdis->itemState & ODS_SELECTED)
		uState |= DFCS_PUSHED;
	DrawFrameControl(lpdis->hDC, &lpdis->rcItem, DFC_BUTTON, uState);
#else
	uState = DPBCS_ADJUSTRECT;
	
	if (lpdis->itemState & ODS_SELECTED)
		uState |= DPBCS_PUSHED;
	DrawPushButtonControl(lpdis->hDC, &lpdis->rcItem, uState);
#endif

	// If the button's selected, then shift everything down and over to the right
	if (lpdis->itemState & ODS_SELECTED)
		OffsetRect(&lpdis->rcItem, 1, 1);
	
	// Draw the bitmap
	HBITMAP	hOldBitmap = SelectBitmap(hMemDC, hBitmap);

	if (lpdis->itemState & ODS_DISABLED)
		DisabledBitBlt(lpdis->hDC, lpdis->rcItem, hMemDC);
	else
		BitBlt(lpdis->hDC, lpdis->rcItem.left, lpdis->rcItem.top, lpdis->rcItem.right -
			lpdis->rcItem.left, lpdis->rcItem.bottom - lpdis->rcItem.top, hMemDC,
			0, 0, SRCCOPY);
	
	// Resore the memory DC
	SelectBitmap(hMemDC, hOldBitmap);

	// Draw the focus rect if requested
	if ((lpdis->itemAction & ODA_FOCUS) || (lpdis->itemState & ODS_FOCUS)) {
		lpdis->rcItem.right--;
		lpdis->rcItem.bottom--;
		DrawFocusRect(lpdis->hDC, &lpdis->rcItem);
	}
}
Example #21
0
HBITMAP    Icon::create_bitmap(COLORREF bk_color, HBRUSH hbrBkgnd, HDC hdc_wnd) const
{
    if (_itype == IT_SYSCACHE) {
        HIMAGELIST himl = g_Globals._icon_cache.get_sys_imagelist();

        int cx, cy;
        ImageList_GetIconSize(himl, &cx, &cy);

        HBITMAP hbmp = CreateCompatibleBitmap(hdc_wnd, cx, cy);
        HDC hdc = CreateCompatibleDC(hdc_wnd);
        HBITMAP hbmp_old = SelectBitmap(hdc, hbmp);
        ImageList_DrawEx(himl, _sys_idx, hdc, 0, 0, cx, cy, bk_color, CLR_DEFAULT, ILD_NORMAL);
        SelectBitmap(hdc, hbmp_old);
        DeleteDC(hdc);

        return hbmp;
    } else
        return create_bitmap_from_icon(_hicon, hbrBkgnd, hdc_wnd);
}
Example #22
0
void ScreenDown(HDC hdc, HDC hdc_src, int width, int height, int split_width, int delay, double accelerate, COLORREF background_color)
{
  HBITMAP hbm_buffer = CreateCompatibleBitmap(hdc, width, height);
  HDC hdc_buffer = CreateCompatibleDC(hdc);
  HBRUSH hbr_backgound = CreateSolidBrush(background_color);
  int *arr, arr_count = width / split_width + (width % split_width == 0 ? 0 : 1);
  int i, t = 0;

  SelectBitmap(hdc_buffer, hbm_buffer);

  arr = (int *)malloc(sizeof(*arr) * arr_count);

  if (!arr)
  {
    return;
  }

  for (i = 0; i < arr_count; i++)
  {
    arr[i] = -i * delay;
  }

  BitBlt(hdc_buffer, 0, 0, width, height, hdc_src, 0, 0, SRCCOPY);

  while (t < arr_count)
  {
    t = DrawScreenBitmap1(hdc_src, hdc, hdc_buffer, arr, arr_count, split_width, width, height, accelerate, hbr_backgound);
    for (i = 0; i < arr_count; i++)
    {
      arr[i]++;
    }
  }

  for (i = 0; i < arr_count; i++)
  {
    arr[i] = -i * delay;
  }

  t = 0;
  while (t < arr_count)
  {
    t = DrawScreenBitmap2(hdc_src, hdc, hdc_buffer, arr, arr_count, split_width, width, height, accelerate, hbr_backgound);
    for (i = 0; i < arr_count; i++)
    {
      arr[i]++;
    }
  }

  DeleteBrush(hbr_backgound);
  DeleteDC(hdc_buffer);
  DeleteBitmap(hbm_buffer);

  free(arr);
}
Example #23
0
void DrawImage( HDC hDC, HBITMAP hBitmap, int nX, int nY, int nW, int nH )
{
	ASSERT( hBitmap != nullptr );
	HDC hdcMem = CreateCompatibleDC( hDC );
	if( hdcMem )
	{
		//	Select new bitmap and backup old bitmap
		HBITMAP hbmOld = SelectBitmap( hdcMem, hBitmap );

		//	Fetch and blit bitmap
		BITMAP bm;
		if( GetObject( hBitmap, sizeof( bm ), &bm ) == sizeof( bm ) )
			BitBlt( hDC, nX, nY, nW, nH, hdcMem, 0, 0, SRCCOPY );	//	Blit!

		//	Restore old bitmap
		SelectBitmap( hdcMem, hbmOld );

		//	Discard MemDC
		DeleteDC( hdcMem );
	}
}
Example #24
0
// ÓÎÏ·»æÖÆ
BOOL GamePaint(HWND hWnd)
{
	// »æÖƵØͼ
	SelectBitmap(g_hdcMem1, g_hBmpBackground);
	BitBlt(g_hdcMem, g_rtBk.left, g_rtBk.top, 640, 480, g_hdcMem1, 0, 0, SRCCOPY);
	BitBlt(g_hdcMem, g_rtBk.right, g_rtBk.top, 640, 480, g_hdcMem1, 0, 0, SRCCOPY);
	BitBlt(g_hdcMem, g_rtBk.left, g_rtBk.bottom, 640, 480, g_hdcMem1, 0, 0, SRCCOPY);
	BitBlt(g_hdcMem, g_rtBk.right, g_rtBk.bottom, 640, 480, g_hdcMem1, 0, 0, SRCCOPY);
	
	// »æÖƽÇÉ«
	static int sTag=0, sDir=0;
	static DWORD sTickWalk = GetTickCount();
	if (g_bMove)
	{
		if (sDir != g_emDirection)
		{
			sTag = 0;
			sDir = g_emDirection;
		}
		else if (GetTickCount() - sTickWalk > 150)
		{
			sTag = (sTag + 1) % 4;
			sTickWalk = GetTickCount();
		}
	}
	else
	{
		sTag = 0;
	}

	SelectBitmap(g_hdcMem1, g_hBmpPlayer);
	TransparentBlt(g_hdcMem, g_ptActive.x-35, g_ptActive.y-62, 70, 124,
				   g_hdcMem1, 70*sTag, 124*sDir, 70, 124, RGB(255, 255, 255));

	HDC hdc = GetDC(hWnd);
	BitBlt(hdc, 0, 0, 640, 480, g_hdcMem, 0, 0, SRCCOPY);
	ReleaseDC(hWnd, hdc);

	return TRUE;
}
Example #25
0
void CLrcMask::DrawBkMask()
{
	HDC hTempDc = GetDC(m_hWnd);
	HDC hMenDc = CreateCompatibleDC(hTempDc);

	DuiLib::CDuiRect rc;
	GetClientRect(&rc);

	HBITMAP hbmp;
	BITMAPINFO bitmapinfo;
	bitmapinfo.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
	bitmapinfo.bmiHeader.biBitCount = 32;
	bitmapinfo.bmiHeader.biHeight = rc.GetHeight();
	bitmapinfo.bmiHeader.biWidth = rc.GetWidth();
	bitmapinfo.bmiHeader.biPlanes = 1;
	bitmapinfo.bmiHeader.biCompression=BI_RGB;
	bitmapinfo.bmiHeader.biXPelsPerMeter=0;
	bitmapinfo.bmiHeader.biYPelsPerMeter=0;
	bitmapinfo.bmiHeader.biClrUsed=0;
	bitmapinfo.bmiHeader.biClrImportant=0;
	bitmapinfo.bmiHeader.biSizeImage = bitmapinfo.bmiHeader.biWidth * bitmapinfo.bmiHeader.biHeight * bitmapinfo.bmiHeader.biBitCount / 8;

	hbmp = CreateDIBSection(hMenDc,&bitmapinfo,0,NULL,0,0);
	SelectBitmap(hMenDc,hbmp);

	Graphics graphics(hMenDc);

	graphics.SetSmoothingMode(SmoothingModeAntiAlias);
	graphics.SetInterpolationMode(InterpolationModeHighQualityBicubic);
	SolidBrush brush(Color(50,200,200,200));
	Pen pen1(Color(155,223,223,223));
	Pen pen2(Color(55,223,223,223));
	LPRECT lpRect = &rc;
	RectF rect((Gdiplus::REAL)lpRect->left,(Gdiplus::REAL)lpRect->top,(Gdiplus::REAL)(lpRect->right-lpRect->left),(Gdiplus::REAL)(lpRect->bottom-lpRect->top));

	graphics.FillRectangle(&brush,rect);
	graphics.DrawRectangle(&pen1,rect.GetLeft()+2,rect.GetTop()+2,rect.Width - 4,rect.Height -4);
	graphics.DrawRectangle(&pen2,rect.GetLeft()+1,rect.GetTop()+1,rect.Width - 2,rect.Height -2);

	DuiLib::CDuiRect rtWnd;
	GetWindowRect(&rtWnd);

	DuiLib::CPoint dstPt(0,0);
	DuiLib::CPoint winPt(rtWnd.left,rtWnd.top);
	DuiLib::CSize size(rc.GetWidth(),rc.GetHeight());
	BLENDFUNCTION blend = {AC_SRC_OVER,0,255,AC_SRC_ALPHA};
	BOOL bret = ::UpdateLayeredWindow(m_hWnd,hTempDc,&winPt,&size,hMenDc,&dstPt,0,&blend,ULW_ALPHA);
	DeleteDC(hMenDc);
	ReleaseDC(m_hWnd,hTempDc);	

//	assert(bret);
}
Example #26
0
/// Function name  : utilRestoreDeviceContext
// Description     : Reverts a DeviceContext to the state it was in when the object was created
// 
// DC_STATE*  pPrevState   : [in] DeviceContext state
// 
UtilityAPI 
VOID  utilRestoreDeviceContext(DC_STATE*  pPrevState)
{
   // [BACKGROUND MODE]
   if (pPrevState->eState INCLUDES DCC_BACKGROUND_MODE)
   {
      SetBkMode(pPrevState->hDC, pPrevState->iOldBackgroundMode);
      pPrevState->eState ^= DCC_BACKGROUND_MODE;
   }

   // [BACKGROUND COLOUR]
   if (pPrevState->eState INCLUDES DCC_BACKGROUND_COLOUR)
   {
      SetBkColor(pPrevState->hDC, pPrevState->clOldBackgroundColour);
      pPrevState->eState ^= DCC_BACKGROUND_COLOUR;
   }

   // [BITMAP]
   if (pPrevState->eState INCLUDES DCC_BITMAP)
   {
      SelectBitmap(pPrevState->hDC, pPrevState->hOldBitmap);
      pPrevState->eState ^= DCC_BITMAP;
   }

   // [BRUSH]
   if (pPrevState->eState INCLUDES DCC_BRUSH)
   {
      SelectBrush(pPrevState->hDC, pPrevState->hOldBrush);
      pPrevState->eState ^= DCC_BRUSH;
   }

   // [FONT]
   if (pPrevState->eState INCLUDES DCC_FONT)
   {
      SelectFont(pPrevState->hDC, pPrevState->hOldFont);
      pPrevState->eState ^= DCC_FONT;
   }

   // [PEN]
   if (pPrevState->eState INCLUDES DCC_PEN)
   {
      SelectPen(pPrevState->hDC, pPrevState->hOldPen);
      pPrevState->eState ^= DCC_PEN;
   }

   // [TEXT COLOUR]
   if (pPrevState->eState INCLUDES DCC_TEXT_COLOUR)
   {
      SetTextColor(pPrevState->hDC, pPrevState->clOldTextColour);
      pPrevState->eState ^= DCC_TEXT_COLOUR;
   }
}
Example #27
0
CCacheDC::CCacheDC(HDC hDC, RECT& rcPaint):
m_hOriginal(hDC),
m_rcPaint(rcPaint)
{
	CreateCompatibleDC(m_hOriginal);
	ATLASSERT(m_hDC != NULL);

	HBITMAP hBmp = CreateCompatibleBitmap(hDC,RECT_WIDTH(rcPaint),RECT_HEIGHT(rcPaint));
	m_hCanvasBmp.Attach(hBmp);
	ATLASSERT(m_hCanvasBmp.m_hBitmap != NULL);

	m_hOldBmp = SelectBitmap(m_hCanvasBmp);
}
Example #28
0
BOOL GRenderWinG::DisplayBits(LPBITMAPINFO lpDisplayBitmapInfo, LPBYTE lpDisplayBits)
{
	BOOL ok = FALSE;

	if (lpBitmapInfo && lpBits && RenderDC)
	{
		HBITMAP hOldBitmap;

		hOldBitmap = SelectBitmap( OffScreenDC, WinGBitmap );
		if (hOldBitmap)
		{
			ok = pWinGBitBlt( RenderDC->m_hDC,			// dest
								WRect.left, WRect.top,		// dest XY
								WRect.right-WRect.left,
								WRect.bottom-WRect.top,
								OffScreenDC,				// source
								0,0							// source XY
							);
			SelectBitmap( OffScreenDC, hOldBitmap );
		}
	}
	return ok;
}
Example #29
0
Canvas::~Canvas()
{
    if (m_hBmpCanvas != NULL)
    {
        assert(m_hMemDC != NULL);
        SelectBitmap(m_hMemDC, m_hBmpOld);
        DeleteObject(m_hBmpCanvas);
    }

    if (m_hMemDC != NULL)
    {
        DeleteDC(m_hMemDC);
    }
}
Example #30
0
void MainWnd_OnDrawItem(HWND hwnd, const DRAWITEMSTRUCT * lpDrawItem) {
    if (lpDrawItem->itemID == -1)
        return;
    RECT rect = lpDrawItem->rcItem;
    project_t *project = project_get(lpDrawItem->itemID);
    WCHAR *name = U2W(project_name(project));
    HFONT hOldFont;

    // http://www.codeproject.com/KB/combobox/TransListBox.aspx
    switch (lpDrawItem->itemAction) {
        case ODA_SELECT:
        case ODA_DRAWENTIRE:
            if (lpDrawItem->itemState & ODS_SELECTED) {
                DrawState(lpDrawItem->hDC, NULL, NULL, (LPARAM)g_hListBoxSelectionBgBitmap, 0, rect.left, rect.top, 0, 0, DST_BITMAP);
            } else {
                RECT parentRect = rect;
                MapWindowPoints(g_hProjectListView, g_hMainWindow, (LPPOINT)&parentRect, 2);

                HDC hBitmapDC = CreateCompatibleDC(lpDrawItem->hDC);
                HBITMAP hOldBitmap = SelectBitmap(hBitmapDC, g_hMainWindowBgBitmap);
                BitBlt(lpDrawItem->hDC, rect.left, rect.top, rect.right-rect.left, rect.bottom-rect.top,
                    hBitmapDC, parentRect.left, parentRect.top, SRCCOPY);
                SelectBitmap(hBitmapDC, hOldBitmap);
                DeleteDC(hBitmapDC);
            }
            DrawState(lpDrawItem->hDC, NULL, NULL, (LPARAM)g_hProjectIcon, 0, rect.left + 18, rect.top + 2, 0, 0, DST_ICON);
            SetTextAlign(lpDrawItem->hDC, TA_TOP | TA_LEFT);
            hOldFont = SelectFont(lpDrawItem->hDC, g_hNormalFont12);
            if (lpDrawItem->itemState & ODS_SELECTED) {
                SetTextColor(lpDrawItem->hDC, RGB(0xFF, 0xFF, 0xFF));
            } else {
                SetTextColor(lpDrawItem->hDC, RGB(0x00, 0x00, 0x00));
            }
            TextOut(lpDrawItem->hDC, rect.left + 39, rect.top + 1, name, wcslen(name));
            SelectFont(lpDrawItem->hDC, hOldFont);
    }
}