Example #1
1
void CVirtualLCD::hpInitBitmap(void)
{	
  if (m_hBitmap!=0) DeleteObject(m_hBitmap);
  if (m_hMyBitmap!=0) DeleteObject(m_hMyBitmap);
  if (m_hMemDC!=0) DeleteObject(m_hMemDC);
  if (m_hMyDC!=0) DeleteObject(m_hMyDC);
  if (m_hBrush!=0) DeleteObject(m_hBrush);
  if (m_hBrushRepaint!=0) DeleteObject(m_hBrushRepaint);

  HDC hdc= ::GetDC(m_hWnd);
  m_hBitmap= CreateCompatibleBitmap(hdc, Skin.HighResScreen.x, Skin.HighResScreen.y);
  m_hMyBitmap= CreateCompatibleBitmap(hdc, Skin.screen.right,Skin.screen.bottom);
  ::ReleaseDC(m_hWnd, hdc);
	
  if(!m_hBitmap)return ;
  if (!m_hMyBitmap)	return ;

  m_hMemDC	= CreateCompatibleDC (::GetDC(m_hWnd)) ;
  if(!m_hMemDC) return;

  m_hMyDC	= CreateCompatibleDC (::GetDC(m_hWnd)) ;
  if(!m_hMyDC) return;

  SelectObject (m_hMemDC, m_hBitmap);
  SelectObject (m_hMyDC, m_hMyBitmap);
	
  m_hBrush	= CreateSolidBrush(Skin.screenfore);
  m_hBrushRepaint = CreateSolidBrush(Skin.screenback);
  if(!m_hBrush)	return;

  SelectObject (m_hMemDC, m_hBrush);
  SelectObject (m_hMyDC, m_hBrush);

}
Example #2
0
// game start
void GameObject::GameStart()
{
	// create DC
	g_hdc = GetDC(hwnd);
	g_mdc = CreateCompatibleDC(g_hdc);
	HBITMAP whiteBmp = CreateCompatibleBitmap(g_hdc,WINDOW_WIDTH,WINDOW_HEIGHT);
	SelectObject(g_mdc,whiteBmp);
	g_bufdc = CreateCompatibleDC(g_hdc);

	// hwnd
	myGameMenu.setHWND(hwnd);
	myGamePlaying.setHWND(hwnd);
	myGameResult.setHWND(hwnd);

	// Initialization
	myGameMenu.Init();
	myGamePlaying.Init();
	myGameResult.Init();

	// set the initial state--- gameMenu
	myGameState = GS_Menu;
	myGameMenu.Start();
	//myGameState = GS_Result;
	//myGameResult.Start();
	//myGameState = GS_Playing;
	//myGamePlaying.Start();
}
Example #3
0
HBITMAP CreateBitmapMask(HBITMAP hbmColour, COLORREF crTransparent)
{
	HDC hdcMem, hdcMem2;
	HBITMAP hbmMask;
	BITMAP bm;

	GetObject(hbmColour, sizeof(BITMAP), &bm);
	hbmMask = CreateBitmap(bm.bmWidth, bm.bmHeight, 1, 1, NULL);

	hdcMem = CreateCompatibleDC(0);
	hdcMem2 = CreateCompatibleDC(0);

	SelectObject(hdcMem, hbmColour);
	SelectObject(hdcMem2, hbmMask);

	SetBkColor(hdcMem, crTransparent);

	BitBlt(hdcMem2, 0, 0, bm.bmWidth, bm.bmHeight, hdcMem, 0, 0, SRCCOPY);

	BitBlt(hdcMem, 0, 0, bm.bmWidth, bm.bmHeight, hdcMem2, 0, 0, SRCINVERT);

	DeleteDC(hdcMem);
	DeleteDC(hdcMem2);

	return hbmMask;
}
//==== private
HBITMAP image::getReversedBitmap(HDC hdc, HBITMAP hBitmap, int sourWidth, int sourHeight)
{
	HDC sourDC = CreateCompatibleDC(hdc);
	HDC destDC = CreateCompatibleDC(hdc);
	HBITMAP hResultBit = CreateCompatibleBitmap(hdc, sourWidth, sourHeight);
	HBITMAP hOldSourBit = (HBITMAP)SelectObject(sourDC, hBitmap);
	HBITMAP hOldDestBit = (HBITMAP)SelectObject(destDC, hResultBit);

	StretchBlt(destDC, 
		sourWidth,				//복사될 좌표 시작점 X
		0,						//복사될 좌표 시작점 Y
		-sourWidth-1,			//복사될 크기 width
		sourHeight,				//복사될 크기 height
		sourDC,					//복사대상 DC,
		0,						//복사 시작지점 x
		0,						//복사 시작지점 y
		sourWidth,				//복사될 영역지정 width
		sourHeight,
		SRCCOPY);

	SelectObject(sourDC, hOldSourBit);
	SelectObject(destDC, hOldDestBit);
	DeleteObject(sourDC);
	DeleteObject(destDC);

	return hResultBit;
}
//리소스로부터 읽어온다
HRESULT	image::init(const DWORD resID, int width, 
	int height, BOOL trans, COLORREF transColor)
{
	//재초기화에 대비..
	if (_imageInfo != NULL) release();

	//DC 얻는다
	HDC hdc = GetDC(_hWnd);

	//이미지 정보 생성
	_imageInfo					= new IMAGE_INFO;
	_imageInfo->loadType		= LOAD_RESOURCE;
	_imageInfo->resID			= resID;
	_imageInfo->hMemDC			= CreateCompatibleDC(hdc);
	_imageInfo->hBit			= (HBITMAP)LoadBitmap(_hInstance, MAKEINTRESOURCE(_imageInfo->resID));
	_imageInfo->hOBit			= (HBITMAP)SelectObject(_imageInfo->hMemDC, _imageInfo->hBit);
	_imageInfo->x				= 0;
	_imageInfo->y				= 0;
	_imageInfo->currentFrameX	= 0;
	_imageInfo->currentFrameY	= 0;
	_imageInfo->width			= width;
	_imageInfo->height			= height;
	_imageInfo->frameWidth		= width;
	_imageInfo->frameHeight		= height;
	_imageInfo->maxFrameX		= 0;
	_imageInfo->maxFrameY		= 0;

	_fileName				= NULL;

	//투명 컬러 셋팅
	_trans = FALSE;
	_transColor = RGB(0, 0, 0);

	//알파 블렌드 옵션
	_blendFunc.BlendFlags = 0;
	_blendFunc.AlphaFormat = 0;
	_blendFunc.BlendOp = AC_SRC_OVER;
	
	//알파 블렌드 사용을 위한 이미지 설정
	_blendImage = new IMAGE_INFO;
	_blendImage->loadType = LOAD_EMPTY;				//로드타입
	_blendImage->resID = 0;						//리소스 ID
	_blendImage->hMemDC = CreateCompatibleDC(hdc);	//비트맵을 출력하기 위해 메모리 DC를 만들어 준다
	_blendImage->hBit = (HBITMAP)CreateCompatibleBitmap(hdc, WINSIZEX, WINSIZEY);
	_blendImage->hOBit = (HBITMAP)SelectObject(_blendImage->hMemDC, _blendImage->hBit);
	_blendImage->width = WINSIZEX;
	_blendImage->height = WINSIZEY;

	//얻은 DC 해제
	ReleaseDC(_hWnd, hdc);

	//리소스 얻기에 실패하면...
	if (_imageInfo->hBit == 0)
	{
		release();
		return E_FAIL;
	}

	return S_OK;
}
Example #6
0
int Print::start_print(HWND ohwnd,HINSTANCE hThis) {

    hdc = GetDC(ohwnd);
    memDC = CreateCompatibleDC(hdc);

    print_init(&printdlg, ohwnd, hThis);
    if(!PrintDlg(&printdlg)) return 0;

    docinfo.cbSize = sizeof(DOCINFO);
    docinfo.lpszDocName = "Printing bitmaps";
    docinfo.lpszOutput = NULL;
    docinfo.lpszDatatype = NULL;
    docinfo.fwType = 0;

    if(!(GetDeviceCaps(printdlg.hDC, RASTERCAPS)
	 & (RC_BITBLT | RC_STRETCHBLT|RC_BITMAP64 |
	    RC_DI_BITMAP| RC_DIBTODEV |RC_PALETTE |RC_SCALING |RC_STRETCHBLT|RC_STRETCHDIB))) {
	/*
	  MessageBox(ohwnd, "Cannot Print Raster Images",
	  "Error", MB_OK);
	*/
	return NULL;
    }

    StartDoc(printdlg.hDC, &docinfo);
    //##	begin	zhoubin	000406
    printer_mem_dc = CreateCompatibleDC(printdlg.hDC);
    //##	end		zhoubin	000406

    return 1;
}
Example #7
0
void CBuffer::CreateDoubleBuffering(HWND hWndNew)
{
    // Assign the window handle to our structure
    hWnd = hWndNew;

    // Store the client rectangle in our structure
    GetClientRect(hWnd, &(scrnRect));

    // Get a handle to the device context and store it as the front buffer
    hdcFront = GetDC(hWnd);

    // Create a compatible device context for the backbuffer
    hdcBack = CreateCompatibleDC(hdcFront);

    // Create another hdc to store the bitmap in before the backbuffer
    hdcBitmap = CreateCompatibleDC(hdcFront);

    // Create a dummy bitmap handle to store in the front buffer
    hCompBitmap = CreateCompatibleBitmap(hdcFront, scrnRect.right, scrnRect.bottom);

    // Select the bitmap handle into the back buffer to make it the same size as the front hdc
    hOldCompBitmap = (HBITMAP)SelectObject(hdcBack, hCompBitmap);

    // Also select it int the bitmap hdc so we can store its original handle to put back later
    hOldDispBitmap = (HBITMAP)SelectObject(hdcBack, hCompBitmap);
}
Example #8
0
void DrawBall(HDC hdc, RECT* prc)
{
	HDC hdcBuffer = CreateCompatibleDC(hdc);
	HBITMAP hbmBuffer = CreateCompatibleBitmap(hdc, prc->right, prc->bottom);
	HBITMAP hbmOldBuffer = (HBITMAP)SelectObject(hdcBuffer, hbmBuffer);

	HDC hdcMem = CreateCompatibleDC(hdc);
	HBITMAP hbmOld = (HBITMAP)SelectObject(hdcMem, g_hbmMask);

	FillRect(hdcBuffer, prc, (HBRUSH)GetStockObject(WHITE_BRUSH));

	BitBlt(hdcBuffer, g_ballInfo.x, g_ballInfo.y, g_ballInfo.width, g_ballInfo.height, hdcMem, 0, 0, SRCAND);

	SelectObject(hdcMem, g_hbmBall);
	BitBlt(hdcBuffer, g_ballInfo.x, g_ballInfo.y, g_ballInfo.width, g_ballInfo.height, hdcMem, 0, 0, SRCPAINT);

	BitBlt(hdc, 0, 0, prc->right, prc->bottom, hdcBuffer, 0, 0, SRCCOPY);

	SelectObject(hdcMem, hbmOld);
	DeleteDC(hdcMem);

	SelectObject(hdcBuffer, hbmOldBuffer);
	DeleteDC(hdcBuffer);
	DeleteObject(hbmBuffer);
}
Example #9
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;
}
Example #10
0
BOOL ScreenSnapshot::snapshotScreen()
{
	if (m_hMemDC)
	{
		DeleteObject(m_hMemBitmap);
		DeleteDC(m_hMemDC);
		m_hMemBitmap = NULL;
		m_hMemDC = NULL;
	}
	if (m_hBkgMemDC)
	{
		DeleteObject(m_hBkBitmap);
		DeleteDC(m_hBkgMemDC);
		m_hBkBitmap = NULL;
		m_hBkgMemDC = NULL;
	}
	if (m_hDrawMemDC)
	{
		DeleteObject(m_hDrawBitmap);
		DeleteDC(m_hDrawMemDC);
		m_hDrawBitmap = NULL;
		m_hDrawMemDC = NULL;
	}

	//
	HWND hDesktopWnd = GetDesktopWindow();
	HDC hScreenDC = GetDC(hDesktopWnd);

	RECT rc = { 0 };
	GetWindowRect(hDesktopWnd, &rc);
	int cx = rc.right - rc.left;
	int cy = rc.bottom - rc.top;

	HBITMAP hBitmap = CreateCompatibleBitmap(hScreenDC, cx, cy);
	m_hMemDC = CreateCompatibleDC(hScreenDC);
	HGDIOBJ hOldBitmap = SelectObject(m_hMemDC, (HGDIOBJ)hBitmap);
	BitBlt(m_hMemDC, 0, 0, cx, cy, hScreenDC, 0, 0, SRCCOPY);

	m_hBkgMemDC = CreateCompatibleDC(hScreenDC);
	HBITMAP hBkgBitmap = CreateCompatibleBitmap(hScreenDC, cx, cy);
	SelectObject(m_hBkgMemDC, (HGDIOBJ)hBkgBitmap);
	BitBlt(m_hBkgMemDC, 0, 0, cx, cy, hScreenDC, 0, 0, SRCCOPY);

	HDC hMaskDC = CreateCompatibleDC(hScreenDC);
	HBITMAP hMaskBitmap = CreateCompatibleBitmap(hScreenDC, cx, cy);
	SelectObject(hMaskDC, (HGDIOBJ)hMaskBitmap);

	BLENDFUNCTION ftn = { AC_SRC_OVER, 0, 100, 0 }; 
	AlphaBlend(m_hBkgMemDC, 0, 0, cx, cy, hMaskDC, 0, 0, cx, cy, ftn);
	DeleteObject(hMaskBitmap);
	DeleteDC(hMaskDC);

	m_hDrawMemDC = CreateCompatibleDC(hScreenDC);
	HBITMAP hDrawBitmap = CreateCompatibleBitmap(hScreenDC, cx, cy);
	SelectObject(m_hDrawMemDC, hDrawBitmap);

	ReleaseDC(hDesktopWnd, hScreenDC);
	return TRUE;
}
Example #11
0
void CBuffer::OpaqueBlit(HDC hdc, int destX, int destY, int destWidth, int destHeight,
                         HDC hdc2, int srcX, int srcY, int alpha)
{
    unsigned char* pImageBits = NULL;
    unsigned char* pBackBits = NULL;
    BITMAPINFO bmBitmapInfo = {0};
    HBITMAP hBitmap, hBitmap2, hOldBitmap, hOldBitmap2;
    HDC compHDC;
    HDC compHDC2;

    // Fill in our BitmapInfo structure (we want a 24 bit image)
    bmBitmapInfo.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
    bmBitmapInfo.bmiHeader.biCompression = BI_RGB;
    bmBitmapInfo.bmiHeader.biHeight = destHeight;
    bmBitmapInfo.bmiHeader.biWidth = destWidth;
    bmBitmapInfo.bmiHeader.biBitCount = 24;
    bmBitmapInfo.bmiHeader.biClrUsed = 0;
    bmBitmapInfo.bmiHeader.biPlanes = 1;

    // Create 2 DIB Sections.  One for the Front Buffer and one for the BackBuffer
    hBitmap  = CreateDIBSection(hdc,  &bmBitmapInfo, DIB_RGB_COLORS,(void **)&pImageBits, 0,0);
    hBitmap2  = CreateDIBSection(hdc,  &bmBitmapInfo, DIB_RGB_COLORS,(void **)&pBackBits, 0,0);

    // Create a compatible DC for the front buffer and Select our Dib Section into it
    compHDC = CreateCompatibleDC(hdc);
    hOldBitmap = (HBITMAP)SelectObject(compHDC, hBitmap);

    // Create a compatible DC for the back buffer and Select our Dib Section into it
    compHDC2 = CreateCompatibleDC(hdc2);
    hOldBitmap2 = (HBITMAP)SelectObject(compHDC2, hBitmap2);

    // Blit the front buffer to our compatible DC that will hold the destination bits
    BitBlt(compHDC, 0, 0, destWidth, destHeight, hdc, destX, destY, SRCCOPY);

    // Blit the back buffer to our compatible DC that will hold the source bits
    BitBlt(compHDC2, 0, 0, destWidth, destHeight, hdc2, srcX, srcY, SRCCOPY);

    // Loop through the 24 bit image (Times 3 for R G and B)
    for(int i = 0; i < destHeight * destWidth * 3; i += 3)
    {
        // Calculate the opacity
        pImageBits[i]     += ((pBackBits[i] - pImageBits[i]) * alpha + 255) >> 8;
        pImageBits[i + 1] += ((pBackBits[i+1] - pImageBits[i + 1]) * alpha + 255) >> 8;
        pImageBits[i + 2] += ((pBackBits[i+2] - pImageBits[i + 2]) * alpha + 255) >> 8;
    }

    // Blit the opaque image to the front buffer (Voila!)
    BitBlt(hdc, destX, destY, destWidth, destHeight, compHDC, 0, 0, SRCCOPY);

    // Cleanup the monochrome bitmaps
    SelectObject(compHDC, hOldBitmap);
    SelectObject(compHDC2, hOldBitmap2);

    // Free GDI Resources
    DeleteObject(hBitmap);
    DeleteObject(hBitmap2);
    DeleteDC(compHDC);
    DeleteDC(compHDC2);
}
Example #12
0
/**
 * @param hdc - drawing conImage.
 * @param prcPaint - the rectangle where the painting is requested.
 */
void CImageView::DrawImageView(HDC hdc, const RECT* prcPaint)
{
	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 #13
0
bool CToolImg::CreateField(int nImgWidth, int nImgHeight, COLORREF clrBackground)
{
	_ASSERTE(mh_BmpDc == NULL);

	int nBPP = -1;
	bool bComp = (gnOsVer < 0x600);
	if (!bComp)
	{
		mh_BmpDc = CreateCompatibleDC(NULL);
		nBPP = GetDeviceCaps(mh_BmpDc, BITSPIXEL);
		if (nBPP < 32)
		{
			bComp = true;
			DeleteDC(mh_BmpDc);
			mh_BmpDc = NULL;
		}
	}

	HDC hScreen = bComp ? GetDC(NULL) : NULL;

	// Create memory DC
	if (!mh_BmpDc)
		mh_BmpDc = CreateCompatibleDC(hScreen);

	if (!mh_BmpDc)
	{
		_ASSERTE(mh_BmpDc!=NULL);
	}
	else
	{
		// Create memory bitmap (WinXP and lower toolbar has some problem with true-color buttons, so - 8bit/compatible)
		if (bComp)
			mh_Bmp = CreateCompatibleBitmap(hScreen, nImgWidth, nImgHeight);
		else
			mh_Bmp = CreateBitmap(nImgWidth, nImgHeight, 1, 32, NULL);
	}

	if (hScreen)
		ReleaseDC(NULL, hScreen);

	if (!mh_Bmp)
	{
		FreeDC();
		return false;
	}

	mh_OldBmp = (HBITMAP)SelectObject(mh_BmpDc, mh_Bmp);

	// Prefill with background
	RECT rcFill = {0, 0, nImgWidth, nImgHeight};
	HBRUSH hbr = CreateSolidBrush(clrBackground);
	FillRect(mh_BmpDc, &rcFill, hbr);
	DeleteObject(hbr);

	return true;
}
Example #14
0
// Video initialize
int VideoRend_GDI_Init(HWND hWnd, int width, int height, int fullscreen)
{
	BITMAPINFO BitmapInfo;
	RECT fsRect;

	// Bitmap Structure
	BitmapInfo.bmiHeader.biSize = sizeof(BitmapInfo.bmiHeader);
	BitmapInfo.bmiHeader.biWidth = width;
	BitmapInfo.bmiHeader.biHeight = -height;
	BitmapInfo.bmiHeader.biPlanes = 1;
	BitmapInfo.bmiHeader.biBitCount = 32;
	BitmapInfo.bmiHeader.biCompression = BI_RGB;
	BitmapInfo.bmiHeader.biSizeImage = 0;
	BitmapInfo.bmiHeader.biXPelsPerMeter = 96;
	BitmapInfo.bmiHeader.biYPelsPerMeter = 96;
	BitmapInfo.bmiHeader.biClrUsed = 0;
	BitmapInfo.bmiHeader.biClrImportant = 0;
	RendHDC[0] = CreateCompatibleDC(NULL);
	RendHDC[1] = CreateCompatibleDC(NULL);
	if (!RendHDC[0] || !RendHDC[1]) {
		MessageBox(0, "Can't create compatible DC", "GDI Video", MB_OK | MB_ICONERROR);
		VideoRend_GDI_Terminate();
		return 0;
	}

	// Create DIB Bitmap
	RendImgWidth = width;
	RendImgHeight = height;
	RendBitmap[0] = CreateDIBSection(RendHDC[0], &BitmapInfo, DIB_RGB_COLORS, (void **)&RendVideoBuff[0], NULL, 0);
	RendBitmap[1] = CreateDIBSection(RendHDC[1], &BitmapInfo, DIB_RGB_COLORS, (void **)&RendVideoBuff[1], NULL, 0);
	if (!RendBitmap[0] || !RendBitmap[1]) {
		MessageBox(0, "Can't create bitmap", "GDI Video", MB_OK | MB_ICONERROR);
		VideoRend_GDI_Terminate();
		return 0;
	}

	// Assign DIB Bitmap into the device
	GdiFlush();
	SelectObject(RendHDC[0], RendBitmap[0]);
	SelectObject(RendHDC[1], RendBitmap[1]);

	// Fullscreen
	if (fullscreen) {
		GetWindowRect(GetDesktopWindow(), &fsRect);
		MoveWindow(hWnd, 0, 0, fsRect.right, fsRect.bottom, 0);
	}

	// Clear the image
	RendFrame = 0;
	RendWasInit = 1;
	VideoRend_GDI_ClearVideo();
	VideoRend_GDI_Flip(hWnd);
	VideoRend_GDI_ClearVideo();

	return 32;
}
Example #15
0
void addImage(HIMAGELIST il, HWND hwnd, HBITMAP bitmap, int origwid, int oright, int width, int height)
{
	BOOL wasScaled = FALSE;
	HDC winDC, scaledDC, origDC;
	HBITMAP scaled;
	HBITMAP prevscaled, prevorig;

	// first we need to scale the bitmap
	if (origwid == width && oright == height) {
		scaled = bitmap;
		goto noscale;
	}
	wasScaled = TRUE;
	winDC = GetDC(hwnd);
	if (winDC == NULL)
		xpanic("error getting DC for window", GetLastError());
	origDC = CreateCompatibleDC(winDC);
	if (origDC == NULL)
		xpanic("error getting DC for original ImageList bitmap", GetLastError());
	prevorig = SelectObject(origDC, bitmap);
	if (prevorig == NULL)
		xpanic("error selecting original ImageList bitmap into DC", GetLastError());
	scaledDC = CreateCompatibleDC(origDC);
	if (scaledDC == NULL)
		xpanic("error getting DC for scaled ImageList bitmap", GetLastError());
	scaled = CreateCompatibleBitmap(origDC, width, height);
	if (scaled == NULL)
		xpanic("error creating scaled ImageList bitmap", GetLastError());
	prevscaled = SelectObject(scaledDC, scaled);
	if (prevscaled == NULL)
		xpanic("error selecting scaled ImageList bitmap into DC", GetLastError());
	if (SetStretchBltMode(scaledDC, COLORONCOLOR) == 0)
		xpanic("error setting scaling mode", GetLastError());
	if (StretchBlt(scaledDC, 0, 0, width, height,
		origDC, 0, 0, origwid, oright,
		SRCCOPY) == 0)
		xpanic("error scaling ImageList bitmap down", GetLastError());
	if (SelectObject(origDC, prevorig) != bitmap)
		xpanic("error selecting previous bitmap into original image's DC", GetLastError());
	if (DeleteDC(origDC) == 0)
		xpanic("error deleting original image's DC", GetLastError());
	if (SelectObject(scaledDC, prevscaled) != scaled)
		xpanic("error selecting previous bitmap into scaled image's DC", GetLastError());
	if (DeleteDC(scaledDC) == 0)
		xpanic("error deleting scaled image's DC", GetLastError());
	if (ReleaseDC(hwnd, winDC) == 0)
		xpanic("error deleting window DC", GetLastError());

noscale:
	if ((*fv_ImageList_Add)(il, scaled, NULL) == -1)
		xpanic("error adding ImageList image to image list", GetLastError());
	if (wasScaled)		// clean up
		if (DeleteObject(scaled) == 0)
			xpanic("error deleting scaled bitmap", GetLastError());
}
Example #16
0
static HCURSOR CreateCompatibleCursor(FTexture *cursorpic)
{
	int picwidth = cursorpic->GetWidth();
	int picheight = cursorpic->GetHeight();

	// Create bitmap masks for the cursor from the texture.
	HDC dc = GetDC(NULL);
	if (dc == NULL)
	{
		return false;
	}
	HDC and_mask_dc = CreateCompatibleDC(dc);
	HDC xor_mask_dc = CreateCompatibleDC(dc);
	HBITMAP and_mask = CreateCompatibleBitmap(dc, 32, 32);
	HBITMAP xor_mask = CreateCompatibleBitmap(dc, 32, 32);
	ReleaseDC(NULL, dc);

	SelectObject(and_mask_dc, and_mask);
	SelectObject(xor_mask_dc, xor_mask);

	// Initialize with an invisible cursor.
	SelectObject(and_mask_dc, GetStockObject(WHITE_PEN));
	SelectObject(and_mask_dc, GetStockObject(WHITE_BRUSH));
	Rectangle(and_mask_dc, 0, 0, 32, 32);
	SelectObject(xor_mask_dc, GetStockObject(BLACK_PEN));
	SelectObject(xor_mask_dc, GetStockObject(BLACK_BRUSH));
	Rectangle(xor_mask_dc, 0, 0, 32, 32);

	FBitmap bmp;
	const BYTE *pixels;

	bmp.Create(picwidth, picheight);
	cursorpic->CopyTrueColorPixels(&bmp, 0, 0);
	pixels = bmp.GetPixels();

	// Copy color data from the source texture to the cursor bitmaps.
	for (int y = 0; y < picheight; ++y)
	{
		for (int x = 0; x < picwidth; ++x)
		{
			const BYTE *bgra = &pixels[x*4 + y*bmp.GetPitch()];
			if (bgra[3] != 0)
			{
				SetPixelV(and_mask_dc, x, y, RGB(0,0,0));
				SetPixelV(xor_mask_dc, x, y, RGB(bgra[2], bgra[1], bgra[0]));
			}
		}
	}
	DeleteDC(and_mask_dc);
	DeleteDC(xor_mask_dc);

	// Create the cursor from the bitmaps.
	return CreateBitmapCursor(cursorpic->LeftOffset, cursorpic->TopOffset, and_mask, xor_mask);
}
Example #17
0
static GpStatus get_path_hrgn(GpPath *path, GpGraphics *graphics, HRGN *hrgn)
{
    HDC new_hdc=NULL;
    GpGraphics *new_graphics=NULL;
    GpStatus stat;
    INT save_state;

    if (!graphics)
    {
        new_hdc = CreateCompatibleDC(0);
        if (!new_hdc)
            return OutOfMemory;

        stat = GdipCreateFromHDC(new_hdc, &new_graphics);
        graphics = new_graphics;
        if (stat != Ok)
        {
            DeleteDC(new_hdc);
            return stat;
        }
    }
    else if (!graphics->hdc)
    {
        graphics->hdc = new_hdc = CreateCompatibleDC(0);
        if (!new_hdc)
            return OutOfMemory;
    }

    save_state = SaveDC(graphics->hdc);
    EndPath(graphics->hdc);

    SetPolyFillMode(graphics->hdc, (path->fill == FillModeAlternate ? ALTERNATE
                                                                    : WINDING));

    stat = trace_path(graphics, path);
    if (stat == Ok)
    {
        *hrgn = PathToRegion(graphics->hdc);
        stat = *hrgn ? Ok : OutOfMemory;
    }

    RestoreDC(graphics->hdc, save_state);
    if (new_hdc)
    {
        DeleteDC(new_hdc);
        if (new_graphics)
            GdipDeleteGraphics(new_graphics);
        else
            graphics->hdc = NULL;
    }

    return stat;
}
Example #18
0
/* Unit ball initialization function.
 * ARGUMENTS:
 *   - self-pointer to unit object:
 *       ds1UNIT_BALL *Uni;
 *   - animation context:
 *       ds1ANIM *Ani;
 * RETURNS: None.
 */
static VOID DS1_UnitInit( ds1UNIT_SPRITE *Uni, ds1ANIM *Ani )
{
  
  Uni->hBmAND = LoadImage(NULL, Uni->FileAND, IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE);
  Uni->hDCAND = CreateCompatibleDC(Ani->hDC);
  SelectObject(Uni->hDCAND, Uni->hBmAND);
  GetObject(Uni->hBmAND, sizeof(Uni->Bm), &Uni->Bm);;

  Uni->hBmXOR = LoadImage(NULL, Uni->FileXOR, IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE);
  Uni->hDCXOR = CreateCompatibleDC(Ani->hDC);
  SelectObject(Uni->hDCXOR, Uni->hBmXOR);

} /* End of 'DS1_UnitInit' function */
Example #19
0
HBITMAP StretchBitmap (HBITMAP hBitmap1)
{
     BITMAP     bm1, bm2 ;
     HBITMAP    hBitmap2 ;
     HDC        hdc, hdcMem1, hdcMem2 ;
     int        cxChar, cyChar ;

          // Get the width and height of a system font character

     cxChar = LOWORD (GetDialogBaseUnits ()) ;
     cyChar = HIWORD (GetDialogBaseUnits ()) ;

          // Create 2 memory DCs compatible with the display
     
     hdc = CreateIC (TEXT ("DISPLAY"), NULL, NULL, NULL) ;
     hdcMem1 = CreateCompatibleDC (hdc) ;
     hdcMem2 = CreateCompatibleDC (hdc) ;
     DeleteDC (hdc) ;

          // Get the dimensions of the bitmap to be stretched
     
     GetObject (hBitmap1, sizeof (BITMAP), (PTSTR) &bm1) ;

          // Scale these dimensions based on the system font size
     
     bm2 = bm1 ;
     bm2.bmWidth      = (cxChar * bm2.bmWidth)  / 4 ;
     bm2.bmHeight     = (cyChar * bm2.bmHeight) / 8 ;
     bm2.bmWidthBytes = ((bm2.bmWidth + 15) / 16) * 2 ;

          // Create a new bitmap of larger size
     
     hBitmap2 = CreateBitmapIndirect (&bm2) ;

          // Select the bitmaps in the memory DCs and do a StretchBlt
     
     SelectObject (hdcMem1, hBitmap1) ;
     SelectObject (hdcMem2, hBitmap2) ;
     
     StretchBlt (hdcMem2, 0, 0, bm2.bmWidth, bm2.bmHeight,
                 hdcMem1, 0, 0, bm1.bmWidth, bm1.bmHeight, SRCCOPY) ;

          // Clean up
     
     DeleteDC (hdcMem1) ;
     DeleteDC (hdcMem2) ;
     DeleteObject (hBitmap1) ;
     
     return hBitmap2 ;
}
Example #20
0
HBITMAP CopyBitmapTo32(HBITMAP hBitmap)
{
	BITMAP bmp;
	GetObject(hBitmap, sizeof(bmp), &bmp);

	DWORD dwLen = bmp.bmWidth * bmp.bmHeight * 4;
	BYTE *p = (BYTE *)malloc(dwLen);
	if (p == nullptr)
		return nullptr;

	// Create bitmap
	BITMAPINFO RGB32BitsBITMAPINFO;
	memset(&RGB32BitsBITMAPINFO, 0, sizeof(BITMAPINFO));
	RGB32BitsBITMAPINFO.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
	RGB32BitsBITMAPINFO.bmiHeader.biWidth = bmp.bmWidth;
	RGB32BitsBITMAPINFO.bmiHeader.biHeight = bmp.bmHeight;
	RGB32BitsBITMAPINFO.bmiHeader.biPlanes = 1;
	RGB32BitsBITMAPINFO.bmiHeader.biBitCount = 32;

	BYTE *ptPixels;
	HBITMAP hDirectBitmap = CreateDIBSection(nullptr, (BITMAPINFO *)&RGB32BitsBITMAPINFO, DIB_RGB_COLORS, (void **)&ptPixels, nullptr, 0);

	// Copy data
	if (bmp.bmBitsPixel != 32) {
		HDC hdcOrig = CreateCompatibleDC(nullptr);
		HBITMAP oldOrig = (HBITMAP)SelectObject(hdcOrig, hBitmap);

		HDC hdcDest = CreateCompatibleDC(nullptr);
		HBITMAP oldDest = (HBITMAP)SelectObject(hdcDest, hDirectBitmap);

		BitBlt(hdcDest, 0, 0, bmp.bmWidth, bmp.bmHeight, hdcOrig, 0, 0, SRCCOPY);

		SelectObject(hdcDest, oldDest);
		DeleteObject(hdcDest);
		SelectObject(hdcOrig, oldOrig);
		DeleteObject(hdcOrig);

		// Set alpha
		FreeImage_CorrectBitmap32Alpha(hDirectBitmap, FALSE);
	}
	else {
		GetBitmapBits(hBitmap, dwLen, p);
		SetBitmapBits(hDirectBitmap, dwLen, p);
	}

	free(p);

	return hDirectBitmap;
}
Example #21
0
void PaintImageEx( HDC dc )
{
	if(!*pathOut) return;

	HBITMAP hbmp = (HBITMAP)LoadImage(NULL, pathOut, IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE | LR_LOADTRANSPARENT);
	BITMAP bmp;
	GetObject(hbmp, sizeof(bmp), &bmp);

	HDC hMemDC = CreateCompatibleDC(dc);
	BITMAPINFOHEADER * bmp_header = new BITMAPINFOHEADER;
	memset(bmp_header, 0, sizeof(BITMAPINFOHEADER));   
	bmp_header->biSize = sizeof (BITMAPINFOHEADER);
	bmp_header->biWidth = bmp.bmWidth;   
	bmp_header->biHeight = bmp.bmHeight;   
	bmp_header->biPlanes = 1 ;   
	bmp_header->biBitCount = 32;    
	bmp_header->biCompression = BI_RGB;   
	bmp_header->biSizeImage = 0;   
	bmp_header->biXPelsPerMeter = 0;   
	bmp_header->biYPelsPerMeter = 0;   
	bmp_header->biClrUsed = 0;   
	bmp_header->biClrImportant = 0;   
	void* dib = NULL;

	HBITMAP bitmap = ::CreateDIBSection(hMemDC, (BITMAPINFO *)bmp_header, 0, &dib, NULL, 0) ;
	delete bmp_header;
	HBITMAP oldBitmap = (HBITMAP)SelectObject(hMemDC, bitmap);

	BLENDFUNCTION bn;
	bn.AlphaFormat = AC_SRC_ALPHA;
	bn.BlendFlags = 0;
	bn.BlendOp = AC_SRC_OVER;
	bn.SourceConstantAlpha = 255; //透明度设置,0为不透明;255为完全透明

	HDC hMemDCSrc = CreateCompatibleDC(dc);
	SelectObject(hMemDCSrc, hbmp);

	BitBlt(hMemDC, 0, 0, bmp.bmWidth, bmp.bmHeight, dc, 100, 100, SRCCOPY);
	AlphaBlend(hMemDC, 0, 0, bmp.bmWidth, bmp.bmHeight, hMemDCSrc, 0, 0, bmp.bmWidth, bmp.bmHeight, bn);
	BitBlt(dc, 100, 100, bmp.bmWidth, bmp.bmHeight, hMemDC, 0, 0, SRCCOPY);

	//AlphaBlend(dc, 100, 100, bmp.bmWidth, bmp.bmHeight, hMemDC, 0, 0, bmp.bmWidth, bmp.bmHeight, bn);

	DeleteObject(bitmap);
	DeleteObject(hbmp);
	DeleteDC(hMemDC);
	DeleteDC(hMemDCSrc);
}
Example #22
0
// We use this static factory function instead of the regular constructor so
// that we can create the pixel data before calling the constructor. This is
// required so that we can call the base class' constructor with the pixel
// data.
static bool Create(int width, int height, bool is_opaque, SkRasterHandleAllocator::Rec* rec) {
    BITMAPINFOHEADER hdr = { 0 };
    hdr.biSize = sizeof(BITMAPINFOHEADER);
    hdr.biWidth = width;
    hdr.biHeight = -height;  // Minus means top-down bitmap.
    hdr.biPlanes = 1;
    hdr.biBitCount = 32;
    hdr.biCompression = BI_RGB;  // No compression.
    hdr.biSizeImage = 0;
    hdr.biXPelsPerMeter = 1;
    hdr.biYPelsPerMeter = 1;
    void* pixels;
    HBITMAP hbitmap = CreateDIBSection(nullptr, (const BITMAPINFO*)&hdr, 0, &pixels, 0, 0);
    if (!hbitmap) {
        return false;
    }

    size_t row_bytes = width * sizeof(SkPMColor);
    sk_bzero(pixels, row_bytes * height);

    HDC hdc = CreateCompatibleDC(nullptr);
    if (!hdc) {
        DeleteObject(hbitmap);
        return false;
    }
    SetGraphicsMode(hdc, GM_ADVANCED);
    SelectObject(hdc, hbitmap);

    rec->fReleaseProc = DeleteHDCCallback;
    rec->fReleaseCtx = hdc;
    rec->fPixels = pixels;
    rec->fRowBytes = row_bytes;
    rec->fHandle = hdc;
    return true;
}
Example #23
0
static VOID
Bri_OnDrawItem(PIMAGEADJUST pImgAdj,
           LPARAM lParam)
{
    LPDRAWITEMSTRUCT lpDrawItem;
    HDC hdcMem;

    lpDrawItem = (LPDRAWITEMSTRUCT)lParam;

    hdcMem = CreateCompatibleDC(lpDrawItem->hDC);

    if(lpDrawItem->CtlID == IDC_PICPREVIEW)
    {
        SelectObject(hdcMem,
                     pImgAdj->hPreviewBitmap);

        BitBlt(lpDrawItem->hDC,
               pImgAdj->ImageRect.left,
               pImgAdj->ImageRect.top,
               pImgAdj->ImageRect.right,
               pImgAdj->ImageRect.bottom,
               hdcMem,
               0,
               0,
               SRCCOPY);

        DeleteDC(hdcMem);
    }
}
Example #24
0
bool Bitmap::create(int widthPixels, int heightPixels)
{
    destroy();

    width = widthPixels;
    height = heightPixels;
    pitch = ((width * 32 + 31) & ~31) >> 3;
    dc = CreateCompatibleDC(0);

    if (!dc)
        return false;

    memset(&info, 0, sizeof(info));

    info.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
    info.bmiHeader.biBitCount = 32;
    info.bmiHeader.biWidth = width;
    info.bmiHeader.biHeight = -height;
    info.bmiHeader.biCompression = BI_RGB;
    info.bmiHeader.biPlanes = 1;

    hBitmap = CreateDIBSection(dc, &info, DIB_RGB_COLORS,
                               reinterpret_cast<void**>(&m_pBits), 0, 0);

    if (!hBitmap)
    {
        destroy();
        return false;
    }

    GdiFlush();
    return true;
}
Example #25
0
void little::initGdiplus()
{
    GdiplusStartupInput gdiplusStartupInput;
    

    GdiplusStartup(&m_gdiplusToken, &gdiplusStartupInput, NULL);

    ShowWindow(m_hWnd, SW_NORMAL);
    //SetLayeredWindowAttributes(hWnd, 0, (255 * 70) / 100, LWA_ALPHA);
    
    m_screenDC = GetDC(NULL);
    HBITMAP bmp;
    BITMAPINFO bmi = {0};
    bmi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
    bmi.bmiHeader.biWidth = m_rect.width;
    bmi.bmiHeader.biHeight = m_rect.height;
    bmi.bmiHeader.biPlanes = 1;
    bmi.bmiHeader.biBitCount = 32;
    bmi.bmiHeader.biCompression = BI_RGB;

    bmp = CreateDIBSection(NULL, &bmi, DIB_RGB_COLORS, NULL, 0, 0);

    m_memDC = CreateCompatibleDC(m_screenDC);

    SelectObject(m_memDC, bmp);

    m_pGraphics = Graphics::FromHDC(m_memDC);
}
Example #26
0
void CCeXDib::Draw(HDC hDC, DWORD dwX, DWORD dwY)
{
	HBITMAP	hBitmap = NULL;
	HBITMAP	hOldBitmap = NULL;
	HDC		hMemDC = NULL;

	if (m_hBitmap == NULL)
	{
		m_hBitmap = CreateDIBSection(hDC, (BITMAPINFO*)m_hDib, DIB_RGB_COLORS, &m_lpBits, NULL, 0);
		if (m_hBitmap == NULL)	return;
		if (m_lpBits == NULL)
		{
			::DeleteObject(m_hBitmap);
			m_hBitmap = NULL;
			return;
		} // if
	} // if

    memcpy(m_lpBits, GetBits(), m_bi.biSizeImage);

	if (m_hMemDC == NULL)
	{
		m_hMemDC = CreateCompatibleDC(hDC);
		if (m_hMemDC == NULL)	return;
	} // if

	hOldBitmap = (HBITMAP)SelectObject(m_hMemDC, m_hBitmap);

	BitBlt(hDC, dwX, dwY, m_bi.biWidth, m_bi.biHeight, m_hMemDC, 0, 0, SRCCOPY);

	SelectObject(m_hMemDC, hOldBitmap);
} // End of Draw
void FlyoutPaint(HWND hwnd, HDC hdc)
{
    // Since this is a DPI aware application (see DeclareDPIAware.manifest), if the flyout window
    // were to show text we would need to increase the size. We could also have multiple sizes of
    // the bitmap image and show the appropriate image for each DPI, but that would complicate the
    // sample.
    static HBITMAP hbmp = NULL;
    if (hbmp == NULL)
    {
        hbmp = (HBITMAP)LoadImage(g_hInst, MAKEINTRESOURCE(IDB_PRINTER), IMAGE_BITMAP, 0, 0, 0);
    }
    if (hbmp)
    {
        RECT rcClient;
        GetClientRect(hwnd, &rcClient);
        HDC hdcMem = CreateCompatibleDC(hdc);
        if (hdcMem)
        {
            HGDIOBJ hBmpOld = SelectObject(hdcMem, hbmp);
            BitBlt(hdc, 0, 0, rcClient.right, rcClient.bottom, hdcMem, 0, 0, SRCCOPY);
            SelectObject(hdcMem, hBmpOld);
            DeleteDC(hdcMem);
        }
    }
}
Example #28
0
void PlayerPanel::Paint()
{
  if (Handle != NULL && GetUpdateRect(Handle, NULL, 0) != 0)
  {
    PAINTSTRUCT PS;
    HDC DC = BeginPaint(Handle, &PS);
    if (DC != NULL)
    {
      /* Create a buffer DC to draw on */
      HDC Buffer = CreateCompatibleDC(DC);
      HBITMAP Bitmap = CreateCompatibleBitmap(DC,Width,Height);
      SelectObject(Buffer, Bitmap);
      /* Paint the background */
      HBRUSH OldBrush = (HBRUSH)SelectObject(Buffer,CreateSolidBrush(GetSysColor(COLOR_BTNFACE)));
      HPEN OldPen = (HPEN)SelectObject(Buffer,CreatePen(PS_SOLID,1,GetSysColor(COLOR_BTNFACE)));
      Rectangle(Buffer,0,0,Width,Height);
      DeleteObject(SelectObject(Buffer,OldPen));
      DeleteObject(SelectObject(Buffer,OldBrush));
      /* Draw the chess piece */
      DrawChessPiece(Buffer,0,2);
      /* Draw the player's information */
      DrawPlayerInformation(Buffer,Height-2,1,Width-Height,Height-2);
      /* Draw the buffer into the destination DC */
      BitBlt(DC,0,0,Width,Height,Buffer,0,0,SRCCOPY);
      /* Cleanup */
      DeleteDC(Buffer);
      DeleteObject(Bitmap);
    }
    EndPaint(Handle, &PS);
  }
}
Example #29
0
// Evaluate default width for the font
int EvaluateDefaultFontWidth(int inSizeY, const wchar_t *asFontName)
{
    if (inSizeY <= 0)
        return 0;

    int nDefaultX = inSizeY * 10 / 16; // rough
    LOGFONT lf = {inSizeY};
    lstrcpyn(lf.lfFaceName, asFontName ? asFontName : L"Lucida Console", countof(lf.lfFaceName));
    HFONT hFont = CreateFontIndirect(&lf);
    if (hFont)
    {
        HDC hDC = CreateCompatibleDC(NULL);
        if (hDC)
        {
            HFONT hOldF = (HFONT)SelectObject(hDC, hFont);
            TEXTMETRIC tm = {};
            BOOL lbTM = GetTextMetrics(hDC, &tm);
            if (lbTM && (tm.tmAveCharWidth > 0))
            {
                nDefaultX = tm.tmAveCharWidth;
            }
            SelectObject(hDC, hOldF);
            DeleteDC(hDC);
        }
        DeleteObject(hFont);
    }

    return nDefaultX;
}
Example #30
0
//########################################################################
// Set a bitmap to a button window, stretching it to fit the size.
//
// @param hdc - [in] Device context handle
//
// @param hBtn - [in] handle to the window where to draw the button bitmap
//
// @param hBmp - [in] handle to a button bitmap
//
// @return value - n.a.
//########################################################################
void WINAPI SetBitmapToButton (/* [in] */ HDC hdc, /* [in] */ HWND hBtn, /* [in] */ HBITMAP hBmp)
{
	RECT rc = {0};
	HDC  hdcMem;
	BITMAP bm;
	GetObject(hBmp, sizeof(bm), &bm);

	GetWindowRect(hBtn, &rc);
	hdcMem = CreateCompatibleDC(hdc);

	SelectObject(hdcMem, hBmp);
	StretchBlt(hdc,
	           0,
	           0,
	           rc.right - rc.left,
	           rc.bottom - rc.top,
	           hdcMem,
	           0,
	           0,
	           bm.bmWidth,
	           bm.bmHeight,
	           SRCCOPY
	          );
	DeleteDC(hdcMem);
}