Picture control question
-
-------------------------------------------------------------------------------- Hi, I want to change the BMP from the picture control once I press a button. It seemed like I have to press twice on the button to change first time and then it never changes. Here is the code: BOOL CSdsdDlg::OnInitDialog() { CDialog::OnInitDialog(); HBITMAP hBmp1 = (HBITMAP ) ::LoadImage(NULL, _T("c:\\1.bmp"), IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE); m_pic.SetBitmap(hBmp1); ............... } void CSdsdDlg::OnButton1() { HBITMAP hBmp2 = (HBITMAP ) ::LoadImage(NULL, _T("c:\\cool.bmp"), IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE); if (m_pic.GetBitmap()== hBmp1) m_pic.SetBitmap(hBmp2); else m_pic.SetBitmap(hBmp1); return; }
-
-------------------------------------------------------------------------------- Hi, I want to change the BMP from the picture control once I press a button. It seemed like I have to press twice on the button to change first time and then it never changes. Here is the code: BOOL CSdsdDlg::OnInitDialog() { CDialog::OnInitDialog(); HBITMAP hBmp1 = (HBITMAP ) ::LoadImage(NULL, _T("c:\\1.bmp"), IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE); m_pic.SetBitmap(hBmp1); ............... } void CSdsdDlg::OnButton1() { HBITMAP hBmp2 = (HBITMAP ) ::LoadImage(NULL, _T("c:\\cool.bmp"), IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE); if (m_pic.GetBitmap()== hBmp1) m_pic.SetBitmap(hBmp2); else m_pic.SetBitmap(hBmp1); return; }
-
-------------------------------------------------------------------------------- Hi, I want to change the BMP from the picture control once I press a button. It seemed like I have to press twice on the button to change first time and then it never changes. Here is the code: BOOL CSdsdDlg::OnInitDialog() { CDialog::OnInitDialog(); HBITMAP hBmp1 = (HBITMAP ) ::LoadImage(NULL, _T("c:\\1.bmp"), IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE); m_pic.SetBitmap(hBmp1); ............... } void CSdsdDlg::OnButton1() { HBITMAP hBmp2 = (HBITMAP ) ::LoadImage(NULL, _T("c:\\cool.bmp"), IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE); if (m_pic.GetBitmap()== hBmp1) m_pic.SetBitmap(hBmp2); else m_pic.SetBitmap(hBmp1); return; }
You're better off keeping a class member variable specifying which bitmap is currently displayed, as
GetBitmap()
may not necessarily return the same handle that you give it, although it probably will. Also, you're comparing againsthBmp1
inOnButton1()
, but inOnInitDialog()
,hBmp1
is a local variable. There must be another definition somewhere that is causing the code to work unexpectedly.Ryan
"Punctuality is only a virtue for those who aren't smart enough to think of good excuses for being late" John Nichol "Point Of Impact"