CreateDIBSection in MFC and rendering using picture control

1.5k views Asked by At

I'm creating a DIB Section in MFC using the call CreateDIBSection. I get a HBITMAP from the call which I pass onto another dialog in my MFC Project. In the other dialog I'm using CStatic::SetBitmap(HBITMAP) call to render the bitmap. But for some reason I'm not able to see anything. This works perfectly fine if this is done in same dialog, but I want to create bitmap in one dialog and display in another.

The code for creating the DIBSection is

//-----------------BEGINNING OF FIRST DIALOG--------------------------------------------------

 LPVOID pViewBitmapBits = NULL;

   BITMAPINFOHEADER BMHeaderInfo;
   memset(&BMHeaderInfo, 0, sizeof(BITMAPINFOHEADER));
   BMHeaderInfo.biSize        = sizeof(BITMAPINFOHEADER);
   BMHeaderInfo.biWidth       = 800;
   BMHeaderInfo.biHeight      = 400;
   BMHeaderInfo.biPlanes      = 1;
   BMHeaderInfo.biBitCount    = 8;
   BMHeaderInfo.biCompression = BI_RGB;
   BMHeaderInfo.biSizeImage   = 0;
   BMHeaderInfo.biClrUsed     = 0;
   BMHeaderInfo.biClrImportant= 0;



   BITMAPINFO BMInfo;
   memset(&BMInfo, 0, sizeof(BMInfo));
   BMInfo.bmiHeader = BMHeaderInfo;
   BMInfo.bmiColors[0].rgbBlue=255;




  HBITMAP hGlobalBitMap = CreateDIBSection(m_pParentSheet->test.m_hDC, &BMInfo, DIB_RGB_COLORS, &pViewBitmapBits, NULL, NULL);
   SelectObject(m_pParentSheet->test.m_hDC, hGlobalBitMap);

//--------------------------END OF FIRST DIALOG----------------------------------


//-----------------------------BEGINNING OF SECOND DIALOG----------------------------------------

void CreateViewDlg::OnBnClickedButton2()

{

   m_pic.SetBitmap(hGlobalBitMap );

}

//------------------------------------END OF SECOND DIALOG---------------------------------

Please help me with this. Is there any limitation to the usage of HBITMAP Handles?

1

There are 1 answers

1
Alex F On
HBITMAP hGlobalBitMap = ...

Looks like local variable hiding the global variable.