本人以VC6.0 为例来讲解了:
VC6.0 新建一个MFC工程,SDI或者MDI,Dlg都可以。。
1.工程建立一个后,Project--Add to project --components and controls
在这个Dlg中打开 Visual C++ Components 文件夹,找到 Splash screen 插入即可!!
这个时候就可以显示出来有封面的 程序了!!!
下面开始添加能滚动的代码:
Splash.h
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 ;//文字当前位置
void DrawText(CDC *pDC, int x, int y, int nAlign, CString sFontName, int nFONTSIZE0,
COLORREF crTextColor, CString sText);
virtual LRESULT WindowProc(UINT message, WPARAM wParam, LPARAM lParam);
Splash.cpp
#define TITLECOLOR RGB(0,0,255)//默认标题颜色
#define CONTENTCOLOR RGB(0,255,255)//默认说明文字颜色
#define FONTSIZE0 15 //默认字号
CSplashWnd::CSplashWnd()
{
m_nCurPos = 50 ;
}
BOOL CSplashWnd::Create(CWnd* pParentWnd /*= NULL*/)
{
...........................
m_TextRect.CopyRect
(&CRect(50,100,500,300)); 这样代表 插入代码
...........................
}
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", FONTSIZE0+5,TITLECOLOR,"开发");
DrawText(&m_dcText,nMidx,nBasey+30, 1,
"楷体_GB2312", FONTSIZE0,CONTENTCOLOR,
"深圳市福田区");
DrawText(&m_dcText,nMidx,nBasey+50, 1,
"楷体_GB2312", FONTSIZE0,TITLECOLOR,"QQ");
DrawText(&m_dcText,nMidx,nBasey+70, 1,
"楷体_GB2312", FONTSIZE0,CONTENTCOLOR,"383156647");
dc.BitBlt(0, 0, bm.bmWidth,
bm.bmHeight,&m_dcText, 0,0, SRCCOPY);
}
void CSplashWnd::DrawText(CDC *pDC,
int x, int y, int nAlign,
CString sFontName, int nFONTSIZE0,
COLORREF crTextColor, CString 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,sFontName.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();
}
void CSplashWnd::OnTimer(UINT nIDEvent)
{
m_nCurPos+=5;
if( m_nCurPos>300 )
{
m_nCurPos = 0 ;
}
Invalidate(TRUE);
}
LRESULT CSplashWnd::WindowProc(UINT message, WPARAM wParam, LPARAM lParam)
{
if (c_pSplashWnd == NULL)
return FALSE;
// If we get a keyboard or mouse message, hide the splash screen.
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();
return TRUE; // message handled here
}
return CWnd::WindowProc(message, wParam, lParam);
}
添加完了,编译就可以实现了!!!你还不快试试。。
VS2005 中把VC6.0中的 CSplashWnd类,cpoy到VS2005的工程中编译就行了!
SDI MDI 文档添加下面代码 :
CMainFrame.cpp
int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
。。。。。。。。。。。。。。。。
CSplashWnd::ShowSplashScreen(this);
return 0;
}
C****App.cpp
BOOL CCSplashApp::InitInstance()
{
// CG: The following block was added by the Splash Screen component.
{
CCommandLineInfo cmdInfo;
ParseCommandLine(cmdInfo);
CSplashWnd::EnableSplashScreen(cmdInfo.m_bShowSplash);
}
.........................
}
添加完了 编译就可以了!!
Dlg
C****App.cpp
BOOL CCSplashApp::InitInstance()
{
// CG: The following block was added by the Splash Screen component.
{
CCommandLineInfo cmdInfo;
ParseCommandLine(cmdInfo);
CSplashWnd::EnableSplashScreen(cmdInfo.m_bShowSplash);
}
.........................
}
响应这个函数。。。。
int C**********Dlg::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CDialog::OnCreate(lpCreateStruct) == -1)
return -1;
s
CSplashWnd::ShowSplashScreen(this);
//Sleep(5000);
return 0;
}
这样就可以实现了!!!
Dlg 工程里面也可以添加。。
把VC6.0中的 CSplashWnd类 拷贝到Dlg工程中
BOOL CCFileCopyApp::InitInstance()
{
。。。。
{
CCommandLineInfo cmdinfo;
ProcessShellCommand(cmdinfo);
CSplashWnd::EnableSplashScreen(cmdinfo.m_bShowSplash);
}。。。。。
}
BOOL CCFileCopyApp::PreTranslateMessage(MSG* pMsg)
{
if (CSplashWnd::PreTranslateAppMessage(pMsg))
{
return TRUE;
}
return CWinApp::PreTranslateMessage(pMsg);
}
int CCFileCopyDlg::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CDialog::OnCreate(lpCreateStruct) == -1)
return -1;
CSplashWnd::ShowSplashScreen(this);
// TODO: 在此添加您专用的创建代码
return 0;
}
红色为添加的代码。。。