void UIPicButton::SetBitmapResources (bool bSingleBitmap, unsigned int wResbase, unsigned int wReshighlight, unsigned int wResdown)
{
	// Load the bitmap resources. Three resources are required, one for the base button image, one for the
	// highlighted button image, and one for the mouse down button image.
	g_hbmBase = LoadBitmapResource (wResbase);
	g_hbmHighlight = LoadBitmapResource (wReshighlight);
	g_hbmDown = LoadBitmapResource (wResdown);

	// The single bitmap flag tells this class how to draw the button bitmap. A single image is where the entire button
	// image is provided in it's entirity within the provided resources. Therefore the width and height of the button
	// is restricted to that in the resource. If singlebitmap is false then a 3 column tiled bitmap is assumed where the
	// columns 1 and 3 of the provided bitmap are the first and last segments and column 2 is the middle segment which
	// is repeated as many times as the requested width.
	g_bSinglebitmap = bSingleBitmap;
}
Esempio n. 2
0
BOOL CBitmapControl::SetBitmapResource(void)
{
	FreeBitmapResource();
	
	if (LoadBitmapResource())
	{
		if (!(m_dwStyle & SBS_NOSIZECONTROL))
		{
			int nWidth = m_nBitmapWidth;
			int nHeight = m_nBitmapHeight;

			CRect crClient;
			GetClientRect(&crClient);

			int nDeltaX = nWidth - crClient.Width();
			int nDeltaY = nHeight - crClient.Height();
			int nDeltaLeft = nDeltaX/2;
			int nDeltaRight = (nDeltaX+1)/2;
			int nDeltaTop = nDeltaY/2;
			int nDeltaBottom = (nDeltaY+1)/2;

			CRect crWindow; 
			GetWindowRect(&crWindow);
			GetParent()->ScreenToClient(crWindow);

			crWindow.left -= nDeltaLeft;
			crWindow.top -= nDeltaTop;
			crWindow.right += nDeltaRight;
			crWindow.bottom += nDeltaBottom;

			SetWindowPos(NULL,
							 crWindow.left,
							 crWindow.top,
							 crWindow.Width(),
							 crWindow.Height(),
							 SWP_NOZORDER);
		}
		return TRUE;
	}
	return FALSE;
}
Esempio n. 3
0
void CBitmapControl::OnPaint()
{
	CPaintDC dc(this); // device context for painting

	CRect crUpdate(&dc.m_ps.rcPaint);

	if (!crUpdate.IsRectEmpty())
	{
		if (LoadBitmapResource())
		{
			CRect crClient;
			GetClientRect(&crClient);
		
			CRect crBitmap(0, 0, (int)m_nBitmapWidth, (int)m_nBitmapHeight);
			CRect crDraw;
	
			if (m_dwStyle & SBS_SIZEBITMAP)
			{
				crDraw = crClient;
			}
			else
			{
				crDraw = crBitmap;
				crDraw.OffsetRect(crClient.left, crClient.top);
			}

			int nOldMapMode = dc.SetMapMode(MM_TEXT);

			CPalette* pOldPalette;
			CPalette* pCurrentPalette = CPalette::FromHandle(m_pDDB->GetPalette());

			if ((pOldPalette = dc.SelectPalette(pCurrentPalette, FALSE)) != NULL)
			{
				dc.RealizePalette();

				CDC cdcBitmap;

				if ((cdcBitmap.CreateCompatibleDC(&dc)) != NULL)
				{
					CPalette *pOldBitmapPalette;

					if ((pOldBitmapPalette = cdcBitmap.SelectPalette(pCurrentPalette, FALSE)) != NULL)
					{
						cdcBitmap.RealizePalette();
						cdcBitmap.SetMapMode(MM_TEXT);

						CBitmap *pOldBitmap;

						if ((pOldBitmap = cdcBitmap.SelectObject(CBitmap::FromHandle(m_pDDB->GetBitmap()))) != NULL)
						{
							int nOldStretchMode = dc.SetStretchBltMode(STRETCH_DELETESCANS);

							dc.StretchBlt(
								crDraw.left,
								crDraw.top,
								crDraw.Width(),
								crDraw.Height(),
								&cdcBitmap,
								0,
								0,
								m_nBitmapWidth,
								m_nBitmapHeight,
								SRCCOPY);
							
							dc.SetStretchBltMode(nOldStretchMode);
							cdcBitmap.SelectObject(pOldBitmap);
						}
						
						cdcBitmap.SelectPalette(pOldBitmapPalette, FALSE);
					}
				}

				dc.SelectPalette(pOldPalette, FALSE);
			}

			dc.SetMapMode(nOldMapMode);
		}
	}
}