I have a MFC Dialog based application. I have placed a Picture Control (of type Bitmap) to display an initial/default resource bitmap. That displays just fine when the app starts.
When a user selects an item in a CListbox, I want to change the bitmap resource displayed. A CStatic control variable m_Bitmap was created and I change it based on the users' listbox selection. Then I update the controls.
Upon execution, the original bitmap simply disappears and the control fails to display the new bitmap. I have used the same technique with static text control variables and CStrings and it works fine.
Why are my bitmaps failing to change? Tried calling the picture controls' RedrawWindow() function with a CWnd pointer which does nothing either.
This should be an easy thing to do in MFC...
//Code Snippet
//
//Picture Control (IDC_BitmapCntl), control variable is m_Bitmap
// DDX_Control(pDX, IDC_BitmapCntl, m_Bitmap);
//
//Code from CList Control, OnLbnSelchange() function, CListbox variable is m_Selection
//
switch (m_Selection) { //Select a coresponding bitmap to display
case (0):
m_Bitmap.SetBitmap((HBITMAP)IDB_Bitmap1);
break;
case (1):
m_Bitmap.SetBitmap((HBITMAP)IDB_Bitmap2);
break;
//additional cases ommited for brevity
default:
break;
}
UpdateData(FALSE); //this should update the control but does not display new bitmap
//Failed attempt to then redraw control
CWnd* pDlg;
pDlg = GetDlgItem(IDC_BitmapCntl);
pDlg->RedrawWindow(); //cannot access OnPaint() via a pointer
//end snippet
No errors on compilation. Initial bitmap image displays OK but disappears when user selects an item in listbox. New bitmap is not displayed.