• <ruby id="5koa6"></ruby>
    <ruby id="5koa6"><option id="5koa6"><thead id="5koa6"></thead></option></ruby>

    <progress id="5koa6"></progress>

  • <strong id="5koa6"></strong>
  • 用VC制作帶有滾動字幕的軟件封面

    發表于:2007-07-14來源:作者:點擊數: 標簽:
    軟件啟動時,常常需要自下而上循環滾動顯示一些諸如軟件名稱、功能、版本、用戶名、研制單位等信息的文字,在用戶按任意鍵或點擊鼠標鍵后,立即結束演示進入程序主界面。本文在vc中通過向工程中添加splash screen組件,然后擴展csplashwnd類方便地實現了這一
    軟件啟動時,常常需要自下而上循環滾動顯示一些諸如軟件名稱、功能、版本、用戶名、研制單位等信息的文字,在用戶按任意鍵或點擊鼠標鍵后,立即結束演示進入程序主界面。本文在vc中通過向工程中添加splash screen組件,然后擴展csplashwnd類方便地實現了這一功能。設計步驟如下:
    1.創建一個名為test的sdi工程;
    2.向工程中添加splash screen組件,即添加csplashwnd類;
    3.導入軟件封面的位圖資源,標識號為idb_splash;
    4.向csplashwnd類中添加函數drawtext,在軟件封面中顯示文字。代碼如下:
    void csplashwnd::drawtext(cdc *pdc, int x, int y, int nalign,
    cstring sfontname, int nfontsize0,colorref crtextcolor, cstring stext)
    { //pdc:內存dc,x,y:文字位置,nalign:對齊方式
    //sfont:字體,nfontsize0:字號,crtextcolor:文字顏色,stext:正文
    logfont lf;//字體
    lf.lfstrikeout=0;//刪除線
    lf.lfcharset = default_charset ;//字符集
    lf.lfescapement =0;//角度
    lf.lfitalic = 0 ;//傾斜
    lf.lfunderline = 0 ;//下劃線
    lf.lfheight = nfontsize0 ;//字號
    strcpy(lf.lffacename,sfacename.getbuffer(sfontname.getlength()));
    cfont font ;
    font.createfontindirect(&lf);
    cfont *poldfont = (cfont *)pdc->selectobject(&font);
    uint oldalign,ualign ;
    switch(nalign)
    {
    case 0: ualign = ta_left | ta_top ; break;
    case 1: ualign = ta_center | ta_top; break;
    case 2: ualign = ta_right | ta_top ; break;
    default: ualign = ta_left | 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, srclearcase/" target="_blank" >ccopy);
    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 ||message == wm_syskeydown ||
    message == wm_lbuttondown ||message == wm_rbuttondown ||
    message == wm_mbuttondown ||message == wm_nclbuttondown ||
    message == wm_ncrbuttondown ||message == wm_ncmbuttondown)
    { c_psplashwnd->hidesplashscreen();
    afxgetmainwnd()->showwindow(sw_maximize);
    return true;
    }
    }
    return cwnd::windowproc(message, wparam, lparam);
    }
    11.封面窗口銷毀后,釋放有關對象:
    void csplashwnd::postncdestroy()
    { m_dcimage.selectobject(m_poldbitmap);
    m_dctext.selectcliprgn(null);
    m_dctext.selectobject(m_poldbitmaptext);
    m_bitmap.deleteobject();
    m_rgn.deleteobject();
    delete this;
    }
    文中程序在windows9、visual c++ 6.0下運行通過。

    原文轉自:http://www.kjueaiud.com

    老湿亚洲永久精品ww47香蕉图片_日韩欧美中文字幕北美法律_国产AV永久无码天堂影院_久久婷婷综合色丁香五月

  • <ruby id="5koa6"></ruby>
    <ruby id="5koa6"><option id="5koa6"><thead id="5koa6"></thead></option></ruby>

    <progress id="5koa6"></progress>

  • <strong id="5koa6"></strong>