Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Something is Fishy in MFC Land

Status
Not open for further replies.

Zyrenthian

Programmer
Mar 30, 2001
1,440
US
Ok, this is a weird one. I do some image processing with our software. I load an image and blt it onto the screen. However, it seems that all my bits are 255 and i just get a white image. Well, that is not what my image looks like. I initially thought it was a problem opening the actual bmp file so i poped upt the path with an AfxMessageBox. Well here is the weird part

// pseudo code
DisplayImage(); // Shows a white image

but when i do this

// pseudo code
AfxMessageBox("HI");
DisplayImage(); // Show the image correctly

Can anyone tell me why when I pop up a message box all works well?

Matt
 
Does your DisplayImage() function call InvalidateRect()? It sounds like you might have a painting problem here. The message box that pops up may be forcing your window to get a WM_PAINT message it never would have otherwise received.

Just my thoughts...
 
Nope... thats not it. Great idea though. I forgot to mention in the above that this works perfectly fine in DEBUG. I know there is some hidden "FEATURE" of MFC i am missing but I just dont know what.

Matt
 
I've had some graphics-related problems of my own when switching from debug to release in the past. I just switched off compiler optimizations and kept rebuilding until the problem went away, and I knew I switched off the offending "optimization".

There are plenty of known bugs in Microsoft's compiler optimizations, maybe you're encountering one now?

Gotta love all these hidden "features".

:-D
 
I solved the problem. Dont ask me what is different though becasue as far as I can tell, this code does the same thing but only in a smaller block of code. Here is what I had to do to process my BMP file.

*********************************************************************************************************
Code:
#if !defined _DEBUG
		
		BITMAPFILEHEADER bfh;
		BITMAPINFO* bi;
		CStdioFile bmpFile;
		bmpFile.Open(smpteName,CFile::modeRead|CFile::shareDenyNone|CFile::typeBinary);
		bmpFile.Read(&bfh,sizeof(bfh));
		BYTE* info = new BYTE[bfh.bfOffBits];
		bmpFile.Read(info,bfh.bfOffBits);
		bi = (BITMAPINFO*)info;
		int sizeImg = bfh.bfSize-bfh.bfOffBits;
		m_pBitmapBits = new BYTE[sizeImg];
		bmpFile.SeekToBegin();
		bmpFile.Read(m_pBitmapBits,bfh.bfOffBits );
		bmpFile.Read(m_pBitmapBits,sizeImg);
		m_ctrlImageWindow.SetMaxFrameSize(CPoint(bi->bmiHeader.biWidth,bi->bmiHeader.biHeight), 8, 1, "BI_RGB" );
		m_ctrlImageWindow.DisplayFrame(m_pBitmapBits);
		bmpFile.Close();

		delete[] info;
#else
// do debug way
#endif

Hopefully, this will help someone else who runs into this bug. The bit encoding of the image is contained in m_pBitmapBits.

Matt
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top