Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Changing the bitmap
Message
From
02/07/2002 05:13:19
 
General information
Forum:
Visual C++
Category:
Microsoft Foundation Classes
Miscellaneous
Thread ID:
00674201
Message ID:
00674344
Views:
20
I think the problem is the DeleteObject removing the bitmap resource [the doc states "! WARNING Before you delete the object, make sure it is not selected into a device context." & also points out that this is done by the CBitmap destructor).

The CBitmap must remain in scope for the duration of the display of the bitmap & must not be changed, so your use of m_bmp to set the display of multiple bitmaps would not work, unless they all are to disply the same bitmap.

One solution would be to have multiple CBitmap member variables, which are initialised with the appropriate bitmaps & remain valid until the app is closed.

eg
have CBitmap member variables m_bmpbright & m_bmpdim
in the initialisation routine
  VERIFY(m_bmpbright.LoadBitmap(IDB_LGBRIGHT));	
  VERIFY(m_bmpdim.LoadBitmap(IDB_LGDIM));	
your code could then be along the lines :
	for (int i = 0; i < 4; i++)
	{							
		if (m_Ports[i].InitPort(this, i + 1, i == 0 ? 9600 : 19200))
		{
			m_Ports[i].StartMonitoring();									
			m_led1.SetBitmap(m_bmpbright);
		}
		else
		{
			// port not found
			m_led1.SetBitmap(m_bmpdim);
		}		
	}	
>Hello people, i try to dev an aplication for change the bitmap (in this case for reflex an status: on or off)
>
>i have 2 bitmaps . and depend of state i change the bitmap
>
>i use the follow code:
>
> // init the ports
> for (int i = 0; i < 4; i++)
> {
> if (m_Ports[i].InitPort(this, i + 1, i == 0 ? 9600 : 19200))
> {
> m_Ports[i].StartMonitoring();
> VERIFY(m_bmp.LoadBitmap(IDB_LGBRIGHT));
> m_led1.SetBitmap(m_bmp);
> }
> else
> {
> // port not found
> VERIFY(m_bmp.LoadBitmap(IDB_LGDIM));
> m_led1.SetBitmap(m_bmp);
> /*m_Edit[i].SetWindowText("NOT FOUND");
> m_Edit[i].EnableWindow(FALSE);
> m_ListBox[i].EnableWindow(FALSE);*/
> }
> /*switch(i)
> {
> case 0:
> {this->m_led1.SetBitmap(m_bmp);break;}
> case 1:
> {m_led2.SetBitmap(m_bmp);break;}
> case 2:
> {m_led3.SetBitmap(m_bmp);break;}
> case 3:
> {m_led4.SetBitmap(m_bmp);break;}
> }*/
>
> m_bmp.DeleteObject();
> }
>
>i put m_led1 for test, and dont work. the m_led1 is a cstatic variable link to the bitmap object.
>
>and the m_bmp is a variable type CBitmap
>
>thanks for any help
>
>Regards
>
>Francisco Morosini
Len Speed
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform