When using the software cover software with scrolling subtitles, it is often necessary to simply press and loop scroll to display some texts such as software name, function, version, user name, development unit and other information, and click on the user or click the mouse. After the key, the presentation will end the demo to enter the program main interface. This article is conveniently implemented by adding a Splash Screen component to the project in VC, and then expands the CSPlashWnd class. The design steps are as follows: 1. Create a SPI project called TEST; 2. Add a splash screen component to the project, add a csplashwnd class; 3. Bitmap resources for importing software cover, identification number IDB_SPLASH; 4. 4. To csplashwnd classes Add a function DrawText to display text in the software cover.
The code is as follows: void csplashWnd :: DrawText (CDC * PDC, INT X, INT Y, INT NALIGN, CSTRINTNAME, INT NFONTSIGN, CSTRINTNAME, INT NFONTSIZE0, CSTRING CRTEXTCOLOR, CSTRING Stext) {// PDC: Memory DC, X, Y: Text location, nalign : Aligned // sfont: font, nfontsize0: font size, crtextColor: text color, Stext: body LogFont LF; // font LF.LFSTRIKEOUT = 0; // Delete line lf.lfcharset = default_charset; // character set lf.lfescape = 0; // angle lf.lfitalic = 0; // Tilt lf.LfunderLine = 0; // Underline LF.Lfheight = nfontsize0; // font number Strcpy (lf.lffacename, sfAname.getBuffer (sfontname.getlength ())) ; Cfont.createfontIndirect (& lf); cfont * PoldFont = (cfont *) PDC-> selectObject (& font); uint Oldalign, UALIGN; Switch (nalign) {case 0: ualign = ta_left | ta_top; break; cas 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; PDC-> TextOut (x, y, step); PDC-> setTextColor (OldColor); PDC-> setTextAlign (Oldalign); PDC-> setBkmode (OldMode); PDC -> SELE CTObject (PoldFont); font.deleteObject ();} 5. Add the following variables to the CSPLashWnd class and add initialization code in the constructor; Class CsplashWnd: public cwnd {public: CDC m_dctext, m_dcimage; // Display DC compatibility Memory DCCBITMAP * m_pbitmap; // bitmap object pointer cBitmap * m_poldbitmaptext, * m_poldbitmap; // Track the original graph CRGN M_RGN in memory DC; // is used to generate rectangular area CRECT M_TEXTRECT; // Display text Rectangular area INT M_NCURPOS ; // Text Current Position} CSPLashWnd :: CSplashWnd () {m_ncurpos = 50;} 6. Setting the rectangular area of the display text. Bool csplashwnd :: create (cwnd * pparentWnd / * = null * /) {m_textRect.copyRect (& CRECT (50, 100, 500, 300));} 7. Add a WM_PAINT message processing function, call csplashwnd :: DrawText Display text.
Void csplashWnd :: onpaint () {cpaintdc DC (this); Bitmap BM; m_bitmap.getbitmap (& BM); static bool bfirst = true; // Indicates whether the first draw window IF (bfirst) {if (! m_dcimage.createcompati) (& 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.Lidt m_textRect.Width () / 2; DrawText (& M_DCText, NMIDX, NBasey, 1, "体 _GB2312", 20, RGB (0, 0, 255), "Development Unit"); DrawText & m_dctext, nmidx, nbasey 30, 1, "体 _GB2312", 15, RGB (0,255,255), "Armed Police Command Institute Simulation Center"); DC.Bitblt (0, 0, BM.BMWIDTH, BM.BMHEIGHT, & M_DCTEXT, 0, 0, SRCCOPY;} 8. Change the text vertical position, cycle scrolling effect: void csplashWnd :: Ontimer (uint nidEvent) {m_ncurpos ; if (m_ncurpos> 300) // cycle {m_ncurpos = 0;} invalidate (true);} 9. Demonstration software cover , Hide the main frame window: BOOL ctestapp :: InitInstance () {m_pmainwnd-> showwindow (sw_hide); m_pmainwnd-> updateWindow ();} 10. Press any key or click the mouse button to end the cover Demo: 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 ==