473,320 Members | 2,088 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

No Display in VC++ MFC Windows

I tried to show the memory image passed from unsigned char * in VC++ MFC Windows but I couldn't manage to see until now. Actually, it is working in the other SDK and functions for verification's purpose except display.

My code are as below and I hope some one will advise me to close the case as soon as possible.

Expand|Select|Wrap|Line Numbers
  1. bool Dlg::Start()
  2. {
  3.     LPCWSTR fileName = _T("C:\\test.bmp"); 
  4.     greyMemImage = LoadBMPFromFile(fileName);
  5.  
  6. // Display Image or Pattern here for Passing Data is correct
  7.        VECTOR_BYTE vecByte;
  8.         FILE*        fpr = _wfopen(lpszFileName, L"rb");
  9.  
  10.     if (fpr == NULL)
  11.     {
  12.         return false;
  13.     }
  14.  
  15.     long        lFileLength = _filelength(_fileno(fpr));
  16.     vecByte.resize(lFileLength, 0);
  17.  
  18.     fread((void*)&(vecByte[0]), sizeof(unsigned char), lFileLength, fpr);
  19.     fclose(fpr);
  20.     fpr = NULL;
  21.  
  22.        CDC*    pDC = GetDC();
  23.         LPBYTE    lpDIBBits = NULL;
  24.         LPBYTE    pBWImageData = &(greyMemImage [0]);        
  25.                 int    iColors = 0;
  26.         PBITMAPINFO        pbitmapinfo = NULL;
  27.         PBITMAPINFOHEADER    pbitmapinfoheader = NULL;
  28.         DWORD            cbdwColorTable = 0;
  29.         int            iMapMode = 0;        
  30.         if (m_hbmImage != NULL)
  31.         {
  32.         DeleteObject (m_hbmImage);
  33.         m_hbmImage = NULL;
  34.         }
  35.  
  36.     if (m_hdcImage != NULL)
  37.     {
  38.         DeleteDC (m_hdcImage);
  39.         m_hdcImage = NULL;
  40.     }
  41.  
  42.     pbitmapinfo = (PBITMAPINFO)(pBWImageData + sizeof(BITMAPFILEHEADER));
  43.     pbitmapinfoheader = (PBITMAPINFOHEADER)(pBWImageData + sizeof(BITMAPFILEHEADER));
  44.  
  45.     iColors = 1 << (pbitmapinfoheader -> biBitCount);
  46.     if (pbitmapinfoheader -> biBitCount >= 24)
  47.         cbdwColorTable = 0;
  48.     else
  49.         cbdwColorTable = (1 << (pbitmapinfoheader -> biBitCount)) * sizeof(RGBQUAD);
  50.  
  51.     lpDIBBits = (LPBYTE)(pBWImageData + sizeof(BITMAPFILEHEADER) + sizeof(BITMAPINFOHEADER) + cbdwColorTable);
  52.     m_lImageWidth = (int)(pbitmapinfoheader -> biWidth);
  53.     m_lImageHeight = (int)(pbitmapinfoheader -> biHeight);
  54.  
  55.     if (m_hdcImage == NULL)
  56.         m_hdcImage = CreateCompatibleDC(pDC -> m_hDC);
  57.  
  58.     iMapMode = GetMapMode (pDC -> m_hDC);             // Obtain mapping mode
  59.     SetMapMode (m_hdcImage, iMapMode);         // Set memory DC mapping mode
  60.  
  61.     if (m_hbmImage == NULL)
  62.     {
  63.         m_hbmImage = MyCreateBitmap(pDC -> m_hDC, pBWImageData, m_lImageWidth, m_lImageHeight, iColors);
  64.  
  65.     }
  66.  
  67.     SelectObject(m_hdcImage, m_hbmImage);
  68.  
  69.     SetStretchBltMode((HDC)m_hdcImage, (int)HALFTONE);
  70.     StretchDIBits
  71.     (
  72.         (HDC)m_hdcImage, // handle of device context 
  73.         (int)0, // x-coordinate of upper-left corner of dest. rect. 
  74.         (int)0, // y-coordinate of upper-left corner of dest. rect. 
  75.         (int)m_lImageWidth, // width of destination rectangle 
  76.         (int)m_lImageHeight, // height of destination rectangle 
  77.         (int)0, // x-coordinate of upper-left corner of source rect. 
  78.         (int)0, // y-coordinate of upper-left corner of source rect. 
  79.         (int)m_lImageWidth, // width of source rectangle 
  80.         (int)m_lImageHeight, // height of source rectangle 
  81.         (CONST VOID*)lpDIBBits, // address of bitmap bits 
  82.         (CONST BITMAPINFO *)pbitmapinfo, // address of bitmap data 
  83.         (UINT)DIB_RGB_COLORS, // usage 
  84.         (DWORD)SRCCOPY // raster operation code 
  85.     );
  86.  
  87.     ReleaseDC(pDC);
  88.  
  89.     InvalidateRect (NULL, TRUE);
  90.     return true;
  91. }
  92.  

Thanks in advance
Mar 8 '10 #1
0 1455

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Jethro | last post by:
This may be an easy question for you experienced guys, but not for me. I have written lots of code in C, but not C++ and not in windows (old fart). I'm working on a simple program to learn the...
1
by: Niranjan podduturi | last post by:
Hello Friends Iam niranjan Developing MDI Application in vc++6.0 when iam displaying text in windows iam using OnDraw and OnChar functions. in OnChar function iam incrementing the x,y...
1
by: Marek Kurowski | last post by:
Yo! I design web browser in VC++. I need a web browser, in which I can display html in a litle changed form. The best control is CHtmlView with IWebBorwser2 (do you know other way?). But in...
0
by: nandha | last post by:
H I have a doubt in VC++ regarding file reading and displaying in the GUI (Dialog I have a binary file, which contains several piece of information , i have to read the information continuously...
2
by: | last post by:
Everything seems to be moving to .NET and VC++ seems to be adding a lot of managed code support every new release. The questions: is unmanaged code in VC++ beeing phased out in favour of managed...
10
by: Sarah Smith | last post by:
Hello, I am a bit of a newbie to VB.NET, but not totally new. I took the plunge recently and decided (along with my colleagues), to try to convert/port a VB6 client/server app to .Net. (I'm...
9
by: S Wheeler | last post by:
Hi all - I am trying to create an instance of a vb .net class containing a form from unmanaged vc++. The vb.net is a dll. How to do this ? I am trying #import by can't seem to get it quite...
8
by: ramu | last post by:
Hi, I want to call a vc++ function from a c program on linux. So when I do this dosen't the VC++ datatypes differ with c datatypes. Because we don't have some vc++ data types in c. I have to...
6
by: meyzhong | last post by:
Hi, I am new to Visual C++ (6.0). I want to put all the print information in different lines into a box. I create a EDIT dialogue box, and then add a CString variable (m_MSG) to the dialogue...
7
by: Norman Diamond | last post by:
A project depends on VC runtime from Visual Studio 2005 SP1, and DotNet Framework 2. Options are set in the setup project properties, so if these two dependencies are not already installed then...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.