实现代码:
在窗体的初始化过程(OnInitDialog)中添加如下代码:
CComboBox *pCmbStyle=(CComboBox*)GetDlgItem(IDC_CMB_STYLE);
pCmbStyle->AddString(_T("水平向右扫描"));
pCmbStyle->AddString(_T("水平向左扫描"));
pCmbStyle->AddString(_T("水平百叶窗"));
pCmbStyle->AddString(_T("垂直百叶窗"));
为下拉列表框添加项目变换事件(CBN_SELCHANGE),该项目变化事件函数如下:
void CSpeciallyEffectDlg::OnCbnSelchangeCmbStyle()
{
// TODO: 在此添加控件通知处理程序代码
CDC memdc;
CBitmap m_bitmap;
//位图宽,高
int width;
int height;
CBitmap *pOldBmp=NULL;
CComboBox *pCmbStyle=(CComboBox*)GetDlgItem(IDC_CMB_STYLE);
//得到位图
m_bitmap.LoadBitmapW(IDB_BITMAP1);
//获得绘图环境资源
CDC *pDC=new CClientDC(this);
memdc.CreateCompatibleDC(pDC);
pOldBmp=memdc.SelectObject(&m_bitmap);
BITMAP bm;
m_bitmap.GetBitmap(&bm);
width=bm.bmWidth;
height=bm.bmHeight;
pDC->FillSolidRect(0,0,width,height,RGB(255,255,255));
int nIndex=pCmbStyle->GetCurSel();
switch(nIndex)
{
case 0:
{
for(int i=0;i<width;i++)
{
pDC->BitBlt(i,0,1,height,&memdc,i,0,SRCCOPY);
Sleep(50);
}
break;
}
case 1:
{
for(int i=width-1;i>=0;i--)
{
pDC->BitBlt(i,0,1,height,&memdc,i,0,SRCCOPY);
Sleep(50);
}
break;
}
case 2:
{
int num=width/20;
for(int i=0;i<20;i++)
{
for(int j=0;j<num+1;j++)
{
pDC->BitBlt(j*20+i,0,1,height,&memdc,j*20+i,0,SRCCOPY);
Sleep(1);
}
Sleep(50);
}
break;
}
case 3:
{
int num=height/20;
for(int i=0;i<20;i++)
{
for(int j=0;j<num+1;j++)
{
pDC->BitBlt(0,j*20+i,width,1,&memdc,0,j*20+i,SRCCOPY);
Sleep(1);
}
Sleep(50);
}
break;
}
default:
break;
}
memdc.SelectObject(pOldBmp);
m_bitmap.DeleteObject();
memdc.DeleteDC();
delete pDC;
pDC=NULL;
}