Click here to Skip to main content
15,902,938 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: Problem Putting Dialog on top Pin
DLChambers23-Mar-07 16:04
DLChambers23-Mar-07 16:04 
QuestionFinding Duplicate attribute values in a XML doc Pin
sujanaz22-Mar-07 15:35
sujanaz22-Mar-07 15:35 
QuestionAny thing wrong in this peace of code? Pin
G Haranadh22-Mar-07 14:17
G Haranadh22-Mar-07 14:17 
AnswerRe: Any thing wrong in this peace of code? Pin
PJ Arends22-Mar-07 16:03
professionalPJ Arends22-Mar-07 16:03 
QuestionRe: Any thing wrong in this peace of code? Pin
prasad_som22-Mar-07 18:31
prasad_som22-Mar-07 18:31 
AnswerRe: Any thing wrong in this peace of code? Pin
G Haranadh23-Mar-07 6:33
G Haranadh23-Mar-07 6:33 
AnswerRe: Any thing wrong in this peace of code? Pin
John R. Shaw22-Mar-07 21:40
John R. Shaw22-Mar-07 21:40 
AnswerRe: Any thing wrong in this peace of code? Pin
G Haranadh23-Mar-07 6:25
G Haranadh23-Mar-07 6:25 
///////////////////////////////////////////////////////////////////////////////
// Name:		SetLed
// Description:	This method will draw the LED to the specified DC.
//
// Entry:
//				CDC *pDC - DC to draw to
//
//				int iLedColor - Where color is defined by:
//			 		LED_COLOR_RED
//					LED_COLOR_GREEN
//					LED_COLOR_YELLOW
//					LED_COLOR_BLUE
//
//				int iMode - where mode is defined by:
//					LED_ON
//					LED_OFF
//					LED_DISABLED
//
//				int iShape - where shape is defined by:
//					LED_ROUND
//					LED_SQUARE
///////////////////////////////////////////////////////////////////////////////
void CLed::DrawLed(CDC *pDC,int nLEDColor, int nMode, int nShape)
{
	CRect rect;
	GetClientRect(&rect);

	// Center led within an oversized window
	if(rect.Width() >= LED_SIZE && rect.Height() >= LED_SIZE)
	{
		int nWidth = rect.Width();
		int nHeight = rect.Height();
		rect.left += (nWidth - LED_SIZE)/2;
		rect.right -= (nWidth - LED_SIZE)/2;
		rect.top += (nHeight - LED_SIZE)/2;
		rect.bottom -= (nHeight - LED_SIZE)/2;
	}

	// Prepare temporary DCs and bitmaps
	CBitmap TransBitmap;
	TransBitmap.CreateBitmap(LED_SIZE,LED_SIZE,1,1,NULL);
	CBitmap bitmapTemp;
	CBitmap* pBitmap = &m_LedBitmap;
	CDC srcDC;
	CDC dcMask;
	CDC TempDC;
	TempDC.CreateCompatibleDC(pDC);
	srcDC.CreateCompatibleDC(pDC);
	dcMask.CreateCompatibleDC(pDC);

	CBitmap* pOldBitmap = srcDC.SelectObject(pBitmap);
	CBitmap* pOldMaskbitmap = dcMask.SelectObject(&TransBitmap);
	bitmapTemp.CreateCompatibleBitmap(pDC,LED_SIZE,LED_SIZE);

	// Work with tempDC and bitmapTemp to reduce flickering
	CBitmap *pOldBitmapTemp = TempDC.SelectObject(&bitmapTemp);
	TempDC.BitBlt(0, 0, LED_SIZE, LED_SIZE, pDC, rect.left, rect.top, SRCCOPY); 

	// Create mask
	COLORREF OldBkColor = srcDC.SetBkColor(RGB(255,0,255));
	dcMask.BitBlt(0, 0, LED_SIZE, LED_SIZE,&srcDC, nMode*LED_SIZE, nLEDColor+nShape, SRCCOPY); 
	TempDC.SetBkColor(OldBkColor);

	// Using the IDB_LEDS bitmap, index into the bitmap for the appropriate
	// LED. By using the mask color (RGB(255,0,255)) a mask has been created
	// so the bitmap will appear transparent.
	TempDC.BitBlt(0, 0, LED_SIZE, LED_SIZE, &srcDC, nMode*LED_SIZE, nLEDColor+nShape, SRCINVERT); 
	TempDC.BitBlt(0, 0, LED_SIZE, LED_SIZE,&dcMask, 0, 0, SRCAND); 
	TempDC.BitBlt(0, 0, LED_SIZE, LED_SIZE, &srcDC, nMode*LED_SIZE, nLEDColor+nShape, SRCINVERT); 

	// Since the actual minipulation is done to tempDC so there is minimal
	// flicker, it is now time to draw the result to the screen.
	pDC->BitBlt(rect.left, rect.top, LED_SIZE, LED_SIZE, &TempDC, 0, 0, SRCCOPY); 
	
	// House cleaning
	srcDC.SelectObject(pOldBitmap);
	dcMask.SelectObject(pOldMaskbitmap);
	TempDC.SelectObject(pOldBitmapTemp);
	VERIFY(srcDC.DeleteDC());
	VERIFY(dcMask.DeleteDC());
	VERIFY(TempDC.DeleteDC());
	VERIFY(TransBitmap.DeleteObject());
	VERIFY(bitmapTemp.DeleteObject());
}

SORRY for the late friends..


Nice talking to you. Blush | :O
If you judge people, you have no time to love them. -- Mother Teresa

QuestionRuns in VS 2005, not in command window Pin
rmw25622-Mar-07 13:48
rmw25622-Mar-07 13:48 
AnswerRe: Runs in VS 2005, not in command window Pin
cp987622-Mar-07 15:55
cp987622-Mar-07 15:55 
GeneralRe: Runs in VS 2005, not in command window Pin
rmw25622-Mar-07 16:09
rmw25622-Mar-07 16:09 
GeneralRe: Runs in VS 2005, not in command window Pin
cp987622-Mar-07 16:21
cp987622-Mar-07 16:21 
QuestionHow to disable check box in CTreeCtrl control sub item? Pin
Yanshof22-Mar-07 12:13
Yanshof22-Mar-07 12:13 
AnswerRe: How to disable check box in CTreeCtrl control sub item? Pin
toxcct22-Mar-07 12:27
toxcct22-Mar-07 12:27 
Questionmsscript.ocx probelm? Pin
falsevapor22-Mar-07 11:31
falsevapor22-Mar-07 11:31 
QuestionDigitizing w/ DirectShow in Visual C++ Pin
BlackWilson22-Mar-07 10:50
BlackWilson22-Mar-07 10:50 
AnswerRe: Digitizing w/ DirectShow in Visual C++ Pin
Mark Salsbery22-Mar-07 11:23
Mark Salsbery22-Mar-07 11:23 
AnswerRe: font problem with CreateWindow Pin
Michael Dunn22-Mar-07 10:33
sitebuilderMichael Dunn22-Mar-07 10:33 
GeneralRe: font problem with CreateWindow [modified] Pin
shaderx22-Mar-07 10:41
shaderx22-Mar-07 10:41 
GeneralRe: font problem with CreateWindow Pin
John R. Shaw22-Mar-07 21:53
John R. Shaw22-Mar-07 21:53 
GeneralRe: font problem with CreateWindow Pin
Michael Dunn27-Mar-07 20:49
sitebuilderMichael Dunn27-Mar-07 20:49 
QuestionMenus overlapping each other Pin
Alex Cutovoi22-Mar-07 10:09
Alex Cutovoi22-Mar-07 10:09 
AnswerRe: Menus overlapping each other Pin
Michael Dunn22-Mar-07 10:27
sitebuilderMichael Dunn22-Mar-07 10:27 
Questiondynamic linking with DirectX Pin
shaderx22-Mar-07 8:43
shaderx22-Mar-07 8:43 
AnswerRe: dynamic linking with DirectX Pin
Cedric Moonen22-Mar-07 9:25
Cedric Moonen22-Mar-07 9:25 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.