No Display in VC++ MFC Windows

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine
Dear All,
<br/>I tried to show the memory image passed from unsigned char * in VC++ MFC Windows but I couldnt manage to see until now. Actually, it is working in the other SDK and functions for verifications purpose except display.
My code are as below and I hope some one will advise me to close the case as soon as possible.
bool Dlg::Start()<br/>{<br/> LPCWSTR fileName = _T("C:\test.bmp"); <br/> greyMemImage = LoadBMPFromFile(fileName);
// Display Image or Pattern here for Passing Data is correct<br/> VECTOR_BYTE vecByte;<br/> FILE* fpr = _wfopen(lpszFileName, L"rb");
if (fpr == NULL)<br/> {<br/> return false;<br/> }
long lFileLength = _filelength(_fileno(fpr));<br/> vecByte.resize(lFileLength, 0);
fread((void*)&(vecByte[0]), sizeof(unsigned char), lFileLength, fpr);<br/> fclose(fpr);<br/> fpr = NULL;
CDC* pDC = GetDC();<br/> LPBYTE lpDIBBits = NULL;<br/> LPBYTE pBWImageData = &(greyMemImage [0]); <br/> int iColors = 0;<br/> PBITMAPINFO pbitmapinfo = NULL;<br/> PBITMAPINFOHEADER pbitmapinfoheader = NULL;<br/> DWORD cbdwColorTable = 0;<br/> int iMapMode = 0; <br/> if (m_hbmImage != NULL)<br/> {<br/> DeleteObject (m_hbmImage);<br/> m_hbmImage = NULL;<br/> }
if (m_hdcImage != NULL)<br/> {<br/> DeleteDC (m_hdcImage);<br/> m_hdcImage = NULL;<br/> }
pbitmapinfo = (PBITMAPINFO)(pBWImageData + sizeof(BITMAPFILEHEADER));<br/> pbitmapinfoheader = (PBITMAPINFOHEADER)(pBWImageData + sizeof(BITMAPFILEHEADER));<br/> <br/> iColors = 1 << (pbitmapinfoheader -> biBitCount);<br/> if (pbitmapinfoheader -> biBitCount >= 24)<br/> cbdwColorTable = 0;<br/> else<br/> cbdwColorTable = (1 << (pbitmapinfoheader -> biBitCount)) * sizeof(RGBQUAD);
lpDIBBits = (LPBYTE)(pBWImageData + sizeof(BITMAPFILEHEADER) + sizeof(BITMAPINFOHEADER) + cbdwColorTable);<br/> m_lImageWidth = (int)(pbitmapinfoheader -> biWidth);<br/> m_lImageHeight = (int)(pbitmapinfoheader -> biHeight);
if (m_hdcImage == NULL)<br/> m_hdcImage = CreateCompatibleDC(pDC -> m_hDC);
iMapMode = GetMapMode (pDC -> m_hDC); // Obtain mapping mode<br/> SetMapMode (m_hdcImage, iMapMode); // Set memory DC mapping mode
if (m_hbmImage == NULL)<br/> {<br/> m_hbmImage = MyCreateBitmap(pDC -> m_hDC, pBWImageData, m_lImageWidth, m_lImageHeight, iColors);<br/> <br/> }
SelectObject(m_hdcImage, m_hbmImage);
SetStretchBltMode((HDC)m_hdcImage, (int)HALFTONE);<br/> StretchDIBits<br/> (<br/> (HDC)m_hdcImage, // handle of device context <br/> (int)0, // x-coordinate of upper-left corner of dest. rect. <br/> (int)0, // y-coordinate of upper-left corner of dest. rect. <br/> (int)m_lImageWidth, // width of destination rectangle <br/> (int)m_lImageHeight, // height of destination rectangle <br/> (int)0, // x-coordinate of upper-left corner of source rect. <br/> (int)0, // y-coordinate of upper-left corner of source rect. <br/> (int)m_lImageWidth, // width of source rectangle <br/> (int)m_lImageHeight, // height of source rectangle <br/> (CONST VOID*)lpDIBBits, // address of bitmap bits <br/> (CONST BITMAPINFO *)pbitmapinfo, // address of bitmap data <br/> (UINT)DIB_RGB_COLORS, // usage <br/> (DWORD)SRCCOPY // raster operation code <br/> );
ReleaseDC(pDC);
InvalidateRect (NULL, TRUE);<br/> return true;<br/>}

Thanks in advance

View the full article
 
Back
Top