ta_top ; break;
}
oldalign = pdc->settextalign(ualign);
int oldmode = pdc->setbkmode(transparent);
int oldcolor = pdc->settextcolor(crtextcolor) ;
pdc->textout(x,y,stext);pdc->settextcolor(oldcolor) ;
pdc->settextalign(oldalign);
pdc->setbkmode(oldmode);
pdc->selectobject(poldfont);
font.deleteobject();
}
5. 给csplashwnd类中添加以下变量,并在构造函数中加入初始化代码;
class csplashwnd : public cwnd
{public: cdc m_dctext,m_dcimage;//显示dc的兼容内存dc
cbitmap* m_pbitmap;//位图对象指针
cbitmap* m_poldbitmaptext,*m_poldbitmap;//跟踪内存dc中的原位图
crgn m_rgn;//用于生成矩形区域
crect m_textrect ;//显示文字的矩形区域
int m_ncurpos ;//文字当前位置
}
csplashwnd::csplashwnd()
{ m_ncurpos = 50 ;
}
6.设置显示文字的矩形区域。
bool csplashwnd::create(cwnd* pparentwnd /*= null*/)
{ m_textrect.copyrect(&crect(50,100,500,300));
}
7.添加 wm_paint消息处理函数,调用csplashwnd::drawtext显示文字。
void csplashwnd::onpaint()
{ cpaintdc dc(this);
bitmap bm;
m_bitmap.getbitmap(&bm);
static bool bfirst = true;//指示是否第一次绘制窗口
if(bfirst)
{ if (!m_dcimage.createcompatibledc(&dc)) return;
m_poldbitmap = m_dcimage.selectobject(&m_bitmap);
if (!m_dctext.createcompatibledc(&dc)) return;
m_pbitmap = new cbitmap ;
int nbitcount = m_dctext.getdevicecaps(bitspixel);
m_pbitmap->createbitmap(bm.bmwidth,bm.bmheight,1,nbitcount,null);
m_poldbitmaptext = m_dctext.selectobject(m_pbitmap);
m_rgn.createrectrgn(m_textrect.left,m_textrect.top,
m_textrect.right,m_textrect.bottom);
bfirst = false;
}
m_dctext.selectcliprgn(null);
m_dctext.bitblt(0, 0, bm.bmwidth, bm.bmheight,&m_dcimage, 0, 0, srccopy);
m_dctext.selectcliprgn(&m_rgn);
int nbasex = m_textrect.left ;
int nbasey = m_textrect.bottom-m_ncurpos;
int nmidx = m_textrect.left + m_textrect.width()/2 ;
drawtext(&m_dctext,nmidx,nbasey, 1,
"楷体_gb2312",20, rgb(0,0,255) ,"研制单位");
drawtext(&m_dctext,nmidx,nbasey+30, 1,
"楷体_gb2312",15, rgb(0,255,255) ,"武警指挥学院模拟中心");
dc.bitblt(0, 0, bm.bmwidth, bm.bmheight,&m_dctext, 0,0, srccopy);
}
8.改变文字垂向位置,出现循环滚动效果:
void csplashwnd::ontimer(uint nidevent)
{ m_ncurpos++;
if( m_ncurpos>300 ) //循环
{ m_ncurpos = 0 ;
}
invalidate(true);
}
9. 演示软件封面时,隐藏主框架窗口:
bool ctestapp::initinstance()
{ m_pmainwnd->showwindow(sw_hide);
m_pmainwnd->updatewindow();
}
10.按任意键或点击鼠标键结束封面演示:
lresult csplashwnd::windowproc(uint message, wparam wparam, lparam lparam)
{ if (c_psplashwnd)
{
if (message == wm_keydown
关键词:用VC制作带有滚动字幕的软件封面