Click here to Skip to main content
15,914,014 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: Include files Pin
toxcct27-Jul-06 4:43
toxcct27-Jul-06 4:43 
GeneralRe: Include files [modified] Pin
Jay0327-Jul-06 4:47
Jay0327-Jul-06 4:47 
Generaloff topic but, Pin
toxcct27-Jul-06 4:56
toxcct27-Jul-06 4:56 
GeneralRe: off topic but, Pin
Jay0327-Jul-06 5:04
Jay0327-Jul-06 5:04 
QuestionEnd other application instance gracefully Pin
peterchen27-Jul-06 4:09
peterchen27-Jul-06 4:09 
AnswerRe: End other application instance gracefully Pin
PJ Arends27-Jul-06 9:38
professionalPJ Arends27-Jul-06 9:38 
AnswerRe: End other application instance gracefully Pin
Ryan Binns27-Jul-06 18:31
Ryan Binns27-Jul-06 18:31 
QuestionCombining Bitmaps (version 2) [modified] Pin
#realJSOP27-Jul-06 3:52
professional#realJSOP27-Jul-06 3:52 
I have two bitmaps (loaded from resources).

I want to combine thse two bitmaps side-by-side into a 3rd bitmap.

I want to put the 3rd (combined) bitmap into an image list.

The snippet below shows the two functions associated with the image list. The InitImageList() function works fine - each row in the grid shows a white bitmap image in the appropriate column. However, the BuildImageList function doesn't appear to work as intended. Essentially here's the process I'm using:

- Load all bitmaps
- Create two DC - a sourceDC and a targetDC
- select the target bitmap into the target DC,
- select the first source bitmap into the source dc
- BitBlt the source dc onto the target dc
- select the second source bitmap into the source dc
- BitBlt the source dc onto the target dc
- retrieve the bitmap from the target dc
- replace the first imagelist image with the new bitmap

For the raster operation, I've tried both SRCCOPY and SRCPAINT.

What am I doing wrong?

void CMyGridCtrl::InitImageList()
{
	// this code works fine (the default image being displayed is the all-white bitmap)
	if (m_ResultsImages.Create(34, 21, ILC_COLOR4, 0, 1))
	{
		CBitmap bmp;
		CBitmap* pBmpMask = NULL;
		// bitmap loaded below is an all-white bitmap
		bmp.LoadBitmap(IDB_RESULTS_BOTH_CLEAR);
		m_ResultsImages.Add(&bmp, pBmpMask);
		SetImageList(&m_ResultsImages);
	}
}

//------------------------------------------------------------------------------
// Takes the current imagelist and applies new bitmaps according to consult/labs 
// results status.
//------------------------------------------------------------------------------
void CMyGridCtrl::BuildImageList(int nConsultID, int nLabsID)
{
	// this code words fine (I get the bitmap ID's that I expect)
	UINT nImgConsult = 0;
	UINT nImgLabs    = 0;
	switch(nConsultID) // consult
	{
		case 1  : // ordered
			nImgConsult = IDB_CONSULT_ORDERED;
			break;
		case 3  : // ordered
			nImgConsult = IDB_CONSULT_RETURNED;
			break;
		default : // cleared
			nImgConsult = IDB_NORESULTS;
			break;
	}
	switch(nLabsID) // consult
	{
		case 2  : // ordered
			nImgLabs = IDB_LABS_ORDERED;
			break;
		case 4  : // ordered
			nImgLabs = IDB_LABS_RETURNED;
			break;
		default : // cleared
			nImgLabs = IDB_NORESULTS;
			break;
	}

	// LOOK HERE
	// this is the part that doesn't seem to work.
	int      nTargetWidth  = 34;
	int      nTargetHeight = 21;
	int      nSrcWidth     = 17;
	int      nSrcHeight    = 21;
	CBitmap  bmpConsult;
	CBitmap  bmpLabs;
	CBitmap  bmpTarget;

	bmpConsult.LoadBitmap(nImgConsult);
	bmpLabs.LoadBitmap(nImgLabs);
	bmpTarget.LoadBitmap(IDB_RESULTS_BOTH_CLEAR);

	COLORREF crBackground  = RGB(0,0,0);
	CBitmap* pOldTargetBmp = NULL;
	CBitmap* pOldSourceBmp = NULL;
	CBitmap* pNewTargetBmp = NULL;
	CDC      targetDC;
	CDC      sourceDC;

	targetDC.CreateCompatibleDC(this->GetDC());
	sourceDC.CreateCompatibleDC(this->GetDC());

	pOldTargetBmp = targetDC.SelectObject(&bmpTarget);
	pOldSourceBmp = sourceDC.SelectObject(&bmpConsult);

	targetDC.BitBlt(0, 0, nTargetWidth, nTargetHeight, &sourceDC, 0, 0, SRCPAINT);
	pOldSourceBmp = sourceDC.SelectObject(&bmpLabs);
	targetDC.BitBlt(nSrcWidth, 0, nTargetWidth, nTargetHeight, &sourceDC, 0, 0, SRCPAINT);
	pNewTargetBmp = targetDC.SelectObject(pOldTargetBmp);
	m_ResultsImages.Replace(0, pNewTargetBmp, NULL);

}



I also tried doing this:

targetDC.BitBlt(nSrcWidth, 0, nTargetWidth, nTargetHeight, &sourceDC, 0, 0, SRCPAINT);
pNewTargetBmp = targetDC.SelectObject(pOldTargetBmp);

// new code here
CBitmap newBmp;
BYTE bmpBits[4096];
memset(&bmpBits, 0, sizeof(bmpBits));
DWORD nSize = pNewTargetBmp->GetBitmapBits(sizeof(bmpBits), &bmpBits);
newBmp.CreateBitmap(nTargetWidth, nTargetHeight, 1, nSize, (void*)bmpBits);
// new code stops

m_ResultsImages.Replace(0, pNewTargetBmp, NULL);





One last note - Whoever is voting my messages a "1" is acting real f***in' mature. Act like a f***in' grownup or leave.




-- modified at 13:06 Thursday 27th July, 2006
AnswerRe: Combining Bitmaps (version 2) Pin
PJ Arends27-Jul-06 5:23
professionalPJ Arends27-Jul-06 5:23 
GeneralRe: Combining Bitmaps (version 2) [modified] Pin
#realJSOP27-Jul-06 5:46
professional#realJSOP27-Jul-06 5:46 
GeneralRe: Combining Bitmaps (version 2) Pin
#realJSOP27-Jul-06 6:52
professional#realJSOP27-Jul-06 6:52 
GeneralRe: Combining Bitmaps (version 2) Pin
#realJSOP27-Jul-06 7:04
professional#realJSOP27-Jul-06 7:04 
GeneralRe: Combining Bitmaps (version 2) Pin
PJ Arends27-Jul-06 8:45
professionalPJ Arends27-Jul-06 8:45 
GeneralRe: Combining Bitmaps (version 2) Pin
PJ Arends27-Jul-06 9:00
professionalPJ Arends27-Jul-06 9:00 
GeneralRe: Combining Bitmaps (version 2) Pin
PJ Arends27-Jul-06 9:06
professionalPJ Arends27-Jul-06 9:06 
Questionredirecting output from console? Pin
9ine27-Jul-06 3:43
9ine27-Jul-06 3:43 
AnswerRe: redirecting output from console? Pin
Gary R. Wheeler29-Jul-06 4:01
Gary R. Wheeler29-Jul-06 4:01 
Questionconvert string to byte [modified] Pin
_tasleem27-Jul-06 3:34
_tasleem27-Jul-06 3:34 
AnswerRe: convert string to byte Pin
toxcct27-Jul-06 3:54
toxcct27-Jul-06 3:54 
GeneralRe: convert string to byte Pin
_tasleem27-Jul-06 4:24
_tasleem27-Jul-06 4:24 
GeneralRe: convert string to byte Pin
PJ Arends27-Jul-06 9:42
professionalPJ Arends27-Jul-06 9:42 
Questionmake the mouse pointer to hourglass Pin
Max++27-Jul-06 3:18
Max++27-Jul-06 3:18 
AnswerRe: make the mouse pointer to hourglass Pin
Chris Losinger27-Jul-06 3:26
professionalChris Losinger27-Jul-06 3:26 
AnswerRe: make the mouse pointer to hourglass Pin
David Crow27-Jul-06 3:33
David Crow27-Jul-06 3:33 
AnswerRe: make the mouse pointer to hourglass Pin
Hamid_RT27-Jul-06 3:45
Hamid_RT27-Jul-06 3:45 

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.