MFC在定时器函数中刷新位图按钮为什么不能成功呢?

C++语言 码拜 9年前 (2015-05-11) 1458次浏览 0个评论
void CtimerTestDlg::OnTimer(UINT nIDEvent)
{
	CDialogEx::OnTimer(nIDEvent);
	on=!on;
	if (on==0)
	{
		bitmapbtn1.LoadBitmaps(IDB_BITMAP1);
	}
	else
		bitmapbtn1.LoadBitmaps(IDB_BITMAP2);
        messagebox("ok");     //这句是用来测试定时器的,测试说明定时器是正确执行的
//on?bitmapbtn1.LoadBitmaps(IDB_BITMAP1):bitmapbtn1.LoadBitmaps(IDB_BITMAP2);
}

这是一个小测试程序,当定时器启动后,on反转,然后根据on的值载入不同的位图,可是程序并不像我想的那样实现位图按钮的反复变化,请问是为什么呢?

如果定时器可以工作,在if和else里面都加入打印测试测试,有可能位图没有load进来.
void CtimerTestDlg::OnBnClickedButton1()
{
	// TODO: Add your control notification handler code here
	on=!on;
	on?bitmapbtn1.LoadBitmaps(IDB_BITMAP1):bitmapbtn1.LoadBitmaps(IDB_BITMAP2);
}      //这段代码实现的功能是单击位图按钮后改变载入的位图,测试可以实现
void CtimerTestDlg::OnTimer(UINT nIDEvent)
{
	CDialogEx::OnTimer(nIDEvent);
	on=!on;
	if (on==0)
	{
		bitmapbtn1.LoadBitmaps(IDB_BITMAP1);
		MessageBox(L"on==0");   //测试是否进入该语句
	}
	else
		{
			bitmapbtn1.LoadBitmaps(IDB_BITMAP2);
			MessageBox(L"on==1");   //测试是否进入该语句
	}   //测试结果:反复弹出on==0和on==1

但是我不明白位图为什么不能正确载入,用同样的方法放在单击事件响应函数中位图就可以正确载入了,定时器刷新怎么就不行呢?

在线等回复!谢谢各位了!
CButton::SetBitmap
HBITMAP SetBitmap( HBITMAP hBitmap );

Return Value

The handle of a bitmap previously associated with the button.

Parameters

hBitmap

The handle of a bitmap.

Remarks

Call this member function to associate a new bitmap with the button. 

The bitmap will be automatically placed on the face of the button, centered by default.  If the bitmap is too large for the button, it will be clipped on either side. You can choose other alignment options, including the following: 

BS_TOP

BS_LEFT

BS_RIGHT

BS_CENTER

BS_BOTTOM

BS_VCENTER 
Unlike CBitmapButton, which uses four bitmaps per button, SetBitmap uses only one bitmap per the button. When the button is pressed, the bitmap appears to shift down and to the right.

CButton Overview |  Class Members |  Hierarchy Chart

See Also   CButton::GetBitmap, CBitmapButton, CBitmapButton::LoadBitmaps,Bitmaps

40分
参考MSDN98\SAMPLES\VC98\MFC\GENERAL\CTRLTEST\BBUTTON.CPP ?
参考Microsoft SDK\src\mfc\winbtn.cpp ?
没刷新?试试 bitmapbtn1.InvalidateRect(NULL)
m_bt13.InvalidateRect(NULL);果然好用

CodeBye 版权所有丨如未注明 , 均为原创丨本网站采用BY-NC-SA协议进行授权 , 转载请注明MFC在定时器函数中刷新位图按钮为什么不能成功呢?
喜欢 (0)
[1034331897@qq.com]
分享 (0)

文章评论已关闭!