第九章

Visual C++ .NET / 2005 /2008 添加创建启动画面——中英

How to insert a splash screen in a dialog-based application by using Visual C++ .NET or Visual C++ 2005  如何使用Visual C++ .NET或Visual C++ 2005在一个基于对话框应用程序中插入启动画面

On This Page 本页内容

Ø  SUMMARY概要

Ø  Create and Insert a Splash Screen in a Dialog-based Application创建并插入基于对话框的应用程序中的启动画面

Ø  Create a Dialog Box in the Resource Editor 在资源编辑器中创建一个对话框

Ø  Add Text to Your Splash Screen添加文本到您的开机画面

Ø  Create a New CDialog Derived Class创建一个新CDialog派生类

Ø  Add Functions to Your Project将函数添加到您的项目

Ø  Display the Splash Screen显示启动画面

Ø  Compile the Solution 编译该解决方案

Ø  Applies To 适用于

Ø  REFERENCES参考文献

Expand all全部展开 | Collapse all 全部折叠

 

SUMMARY 概要

       In Microsoft Visual Studio 6.0, you can insert a splash screen in an MFC Single-Document Interface(SDI) application or a Multiple-Document Interface(MDI) application by using the Visual C++ Component Gallery

    在Microsoft Visual Studio 6.0中,你可以使用Visual C++组件库在MFC单文档界面(SDI)或多文档界面中插入启动画面。

       However, you cannot insert a splash screen in a dialog-based application in the Visual C++Component Gallery.

    然而,你不能在Visual C++组件库中基于对话框的应用程序中插入启动画面。

       For additional information about how to add a splash screen to an MFC dialog-based application in Microsoft Visual Studio 6.0, click the following article number to view the article in the Microsoft Knowledge Base:

    关于如何使用Visual Studio 6.0为一个MFC基于对话框的应用程序添加一个启动画面,单击下面的文章编号以查看Microsoft知识库中相应的文章:

       190684 HOWTO: Insert a Splash Screen into a Dialog-Based Application

       190684 HOWTO:在基于对话框的应用程序里插入启动画面

       Because there is no direct way to create a splash screen in Visual C++.NET or in Visual C++ 2005, you must build a dialog-based application by using the AppWizard, and the add a class that derives from CDialog(for example, CSplashDlg).

    因为没有直接方法在Visual C++.NET或Visual C++2005中创建启动画面,你必须使用应用程序向导建立一个基于对话框的应用程序,然后添加一个派生于CDialog的类(例如,CSplashDlg)。

       Modify the code to be a splash screen.

    修改代码成为启动画面。

 

Create and Insert a Splash Screen in a Dialog-based Application创建并插入基于对话框的应用程序中的启动画面

       To Create and insert a splash screen in dialog-based application, follow thes steps:

    要在一个基于对话框的应用程序中创建并插入启动画面,请按下列步骤:

1.       Start Visual Studio.NET or Microsoft Visual Studio 2005.

       启动Visual Studio.NET 或Microsoft Visual Studio 2005。

2.       On the File menu, point to New, and then click Project.

       在文件工资单上,指向新建,然后单击项目。

3.       Click Visual C++ Projects under Project Types, and then click MFC Application under Templets.

       单击项目类型下的Visual C++项目,然后单击模板下的MFC应用程序。

                     Note In Visual Studio 2005, click Visual C++ under Project Types, and then click MFC Application                   under Templetes.

           注意在Visual Studio2005中,单击项目类型下的Visual C++,然后单击模板下的MFC应用程序。

4.       Name the project MyApp, and then click OK.

       将该项目命名为MyApp,然后单击确定。

5.       The MFC Application Wizard dialog box appears.

       出现MFC应用程序向导对话框。

6.       Click Application Type, click Dialog based, and then click Finish.

       单击应用程序类型,单基于对话框,然后单击完成。

 

Create a Dialog Box in the Resource Editor在资源编辑器中创建一个对话框

      To create a dialog box in the resource editor that is both visible and entered, with a thin border and no caption, follow these steps:

    要在资源编辑器创建一个可见的,居中的,细边框的,没有标题的对话框,请按下列步骤:

1.       In Resource View, expand MyApp.rc, right-click the Dialog folder, and then click Insert Dialog. By default IDD_DIALOG is created.

       在资源管理器视图中,展开MyApp.rc,右击对话框文件夹,然后单击插入对话框。默认创建                     IDD_DIALOG1。

2.       Remove the OK button and the Cancel button from IDD_DIALOG1. To do this, right-click each button, and then click Delete.

       从IDD_DIALOG1中移除确定按钮和取消按钮。要做到这一点,右键单击每个按钮,然后单删除。

3.       Right-click in IDD_DIALOG1, and then click Properties.

       右击IDD_DIALOG1,然后单击属性。

4.       Under Misc, double-click ID.

       在杂项下,双击标识。

                     Note In Visual Studio 2005, double-click ID under Horizontal Scrollbar.

           注意在Visual Studio 2005中,双击在Horizontal Scrollbar下的ID。

5.       In the ID property, click IDD_DIALOG1, and then type IDD_SPLASH.

       在ID属性里,单击IDD_DIALOG1,然后键入IDD_SPLASH。

6.       Under Appearance, set the Title Bar property to False, and then set the Border property to Thin.

       在外观下,设置Title bar属性为False,然后设置边框属性为Thin。

 

Add Text to Your Splash Screen添加文本到您的启动画面

1.       Add a Static Text control to IDD_SPLASH.

       将静态文本控件添加到IDD_SPLASH。

2.       Edit the text in Caption property.

       在标题属性中编辑文本。

 

Create a New CDialog Derived Class创建一个新的CDialog派生类

1.       Double-click the dialog box. The MFC Class Wizard dialog box appears.

       双击对话框,出现MFC类向导对话框。

2.       Type CSplashDlg in the Class name text box, and then click CDialog in the Base class list.

       在类名文本框中键入CSplashDlg,然后在基类列表中单击CDialog。

3.       Click Finish. SplashDlg.cpp and SplashDlg.h are added to your project.

       单击完成。SplashDlg.cpp和SplashDlg.h被添加到项目中。

 

Add Function to Your Project添加函数到项目

1.       Declared the c_pSplashDlg static variable by adding the following line to the SplashDlg.h file:

       声明静态变量c_pSplashDlg,添加下列行到SplashDlg.h文件中:

                            static CSplashDlg* c_pSplashDlg;

2.       In Class View, right-click CSplashDlg, point to Add, and then click Add Function to add the following functions:

       在类视图中,右击CSplashDlg,指向添加,然后单击添加函数以添加以下函数:

              ShowSplashScreen(CWnd* pParentWnd): Static method that is used to display the splash dialog.

                                                                         静态方法,用于显示启动对话框。

a.       In the Return Type list, click void.

           在返回类型列表中,单击void。

b.       In the Function Name text box, type ShowSplashScreen.

           在函数名文本框中,键入ShowSplashScreen。

c.       In the Parameter Type list, click CWnd*.

           在参数类型列表中,单击CWnd*。

d.       In the Parameter Name text box, type pParentWnd.

           在参数名文本框中,键入pParentWnd。

e.       Click to select the Static check box.

           单击以选择静态复选框。

              HideSplashScreen(): Method that is used to destroy the splash dialog.

                                           该方法用于销毁启动画面。

a.       In the Return Type list, click void.

           在返回类型列表中,单击void。

b.       In the Function Name text box, type HideSplashScreen.

           在函数名称文本框中,键入HideSplashScreen。

              PreTranslateAppMessage(MSG* pMsg): Method that is use to hide the splash screen whenever        

                                         keyboard or mouse message are received.

                                                                       无论何时接收到键盘或鼠标消息,该方法用于隐藏启动画面。

a.       In the Return Type list, click BOOL.

           在返回类型列表中,单击BOOL。

b.       In the Function Name text box, type PreTranslateAppMessage.

           在函数名称文本框中,键入PreTranslateAppMessage。

c.       In the Parameter Type list, click MSG*.

           在参数类型列表中,单击MSG*。

d.       In the Parameter Name text box, type pMsg.

           在参数名称文本框中,键入pMsg。

e.       Click to select the Static check box.

           单击以选择静态复选框。

3.       Modify the three methods that you just created as follows:

       修改您刚刚创建,如下所示的三种方法:

void CSplashDlg::ShowSplashScreen(CWnd* pParentWnd /*= NULL*/)

{

              // Allocate a new splash screen, and create the window.

       c_pSplashDlg = new CSplashDlg;

       if (!c_pSplashDlg->Create(CSplashDlg::IDD, pParentWnd))

              delete c_pSplashDlg;

       else

              c_pSplashDlg->ShowWindow(SW_SHOW);

       c_pSplashDlg->UpdateWindow();

 

       c_pSplashDlg->SetTimer(1,2000, NULL);

}

 

void CSplashDlg::HideSplashScreen()

{

              // Destroy the window, and update the mainframe.

       c_pSplashDlg->KillTimer(1);

       DestroyWindow();

       AfxGetMainWnd()->UpdateWindow();

       delete c_pSplashDlg;

       c_pSplashDlg = NULL;

}

 

BOOL CSplashDlg::PreTranslateAppMessage(MSG* pMsg)

{

       if (c_pSplashDlg == NULL)

              return FALSE;

 

              // If you receive a keyboard or mouse message, hide the splash screen.

       if (c_pSplashDlg->m_hWnd != NULL && pMsg->message == WM_KEYDOWN ||

              pMsg->message == WM_SYSKEYDOWN ||

              pMsg->message == WM_LBUTTONDOWN ||

              pMsg->message == WM_RBUTTONDOWN ||

              pMsg->message == WM_MBUTTONDOWN ||

              pMsg->message == WM_NCLBUTTONDOWN ||

              pMsg->message == WM_NCRBUTTONDOWN ||

              pMsg->message == WM_NCMBUTTONDOWN)

       {

              c_pSplashDlg->HideSplashScreen();

              return TRUE;                                                                // message handled here

       }

       return FALSE;                                                                      // message not handled

}

              Note You must add the common language runtime support compliler option(/clr:oldSyntax)in Visual C++        2005 to successfully compile this code sample. To do this, follow these steps:

       注意您必须添加公共语言运行库支持的编译器选项(/clr:oldSyntax)在Visual C++ 2005中成功编译    此代码示例。若要这样做,请按下列步骤:

1.       Click Project, and then click ProjectName Properties.

       单击项目,然后单击项目名属性。

              Note ProjectName represents the name of the project.

       注意项目名代表项目的名称。

2.       Expand Configuration Properties, and the click General.

       展开配置属性,然后单击常规。

3.       Click to select Common language Runtime Support, Old Syntax(/clr:oldSyntax)in the Common Language Runtime support project setting on the right pane, click Apply, and then click OK.

       单击以选择公共语言运行库支持,$旧语法(/clr:oldSyntax)在右窗格的公共语言运行库支持中,         单击应用,然后单击确定。

                     For more information about the common language runtime support compiler options, visit the                     following Microsoft Web site:

           有关公共语言运行库支持编译选项的更多信息,浏览下面Microsoft网页站点:

                     /clr(Common Language Runtime Compilation)

           http://msdn2.microsoft.com/en-us/library/k811d4s.aspx

4.       Add the OnTimer event. To do this, follow these steps:

       添加OnTimer事件。做到这点,请按照下列步骤:

a.       In Class View, right-click CSplashDlg, and then click Properties.

           在类视图中右击CSplashDlg,然后单击属性。

b.       In the Properties pane, click the Message icon to view the message.

           在属性空格中单击消息图标以查看消息。

c.       In the WM_TIMER field, click OnTimer.

           在WM_TIMER字段中单击OnTimer。

d.       Modify the mothed as follow:

           按如下修改方法

                     void CSplashDlg::OnTimer(UINT nIDEvent)

                     {

                                   // Destroy the splash screen window.

                            HideSplashScreen();

                     }

5.       Override the OnInitDialog method of the CSplashDlg class, To do this, follow these steps:

       重写CSplashDlg类的方法OnInitDialog。要做到这点,请按下列步骤:

a.       In Class View, right-click CSplashDlg, and then click Properties.

           在类视图中右击CSplashDlg,然后单击属性。

b.       In the Properties pane, click the Overrides icon to display the list of overridable methods. In the OnInitDialog field, click <Add> OnInitDialog.

           在属性窗格中单击重写图标以显示

c.       Modify the OnInitDialog override method that you created in step b. To do this, follow these steps:

                     修改你在步骤b中创建的重载方法OnInitDialog。要做到这点,请按下列步骤:

                     BOOL CSplashDlg::OnInitDialog()

                     {

                            CDialog::OnInitDialog();

                            CenterWindow();

                           

                            SetWindowPos(&CWnd::wndTopMost, 0, 0, 0, 0,

                            SWP_NOMOVE|SWP_NOSIZE);

                           

                            return TRUE;  // return TRUE  unless you set the focus to a control

                     }

 

Display the Splash Screen显示启动屏幕

       To view the splash screen, open your application source file, MyAppDlg.cpp, and then follow these steps:

    要查看启动画面,打开你的应用程序源文件MyAppDlg.cpp,然后按下列步骤:

1.       Add the following lines of code at the beginning of the file:

       在文件开头添加下列代码行:

         #include "SplashDlg.h"

              //This is required ( in one of the files ) because the static variable 'c_pSplashDlg' is declared outside           //this file

       CSplashDlg* CSplashDlg::c_pSplashDlg;

2.       In the OnInitDialog() method, add the following code after the line CDialog::OnInitDialog():

       在OnInitDialog()方法中,在CDialog::OnInitDialog()行之后添加下列代码:

                            CSplashDlg::ShowSplashScreen(NULL);

3.       Override the PreTranslateMessage method of CMyAppDlg class. To do this, follow these steps:

       重写CMyAppDlg类的PreTranslateMessage方法。要做到这点,请按下列步骤:

a.       In Class View, right-click CMyAppDlg, and then click Properties.

           在类视图中右击CMyAppDlg,然后单击属性

b.       In the Properties pane, click the Override icon to display the list of overridable methods.

           在属性窗格中,单击重写图标以显示可重写的方法列表。

c.       In the PreTranslateMessage field, click <Add> PreTranslateMessage.

           在PreTranslateMessage字段中,单击<添加>PreTranslateMessage。

4.       Modify the PreTranslateMessage override method that you created in step c as follows:

       按如下修改您在步骤c中创建的PreTranslateMessage重写方法:

              BOOL CMyAppDlg::PreTranslateMessage(MSG* pMsg)

              {

                            // TODO: Add your specialized code here and call the base class, or both.

                     if (CSplashDlg::PreTranslateAppMessage(pMsg))

                            return TRUE;

                     return CDialog::PreTranslateMessage(pMsg);

              }

 

Compile the Solution 编译该解决方案

       Press F5 to compile the solution and to run the application. You may see that the splash screen is displayed.

    按F5键以编译该解决方案并运行该应用程序。你可能看到启动画面显示出来。

 

 

How to insert a splash screen in a dialog-based application by using Visual C++ .NET or Visual C++ 2005  如何使用Visual C++ .NET或Visual C++ 2005在一个基于对话框应用程序中插入启动画面

On This Page 本页内容

Ø  SUMMARY概要

Ø  Create and Insert a Splash Screen in a Dialog-based Application创建并插入基于对话框的应用程序中的启动画面

Ø  Create a Dialog Box in the Resource Editor 在资源编辑器中创建一个对话框

Ø  Add Text to Your Splash Screen添加文本到您的开机画面

Ø  Create a New CDialog Derived Class创建一个新CDialog派生类

Ø  Add Functions to Your Project将函数添加到您的项目

Ø  Display the Splash Screen显示启动画面

Ø  Compile the Solution 编译该解决方案

Ø  Applies To 适用于

Ø  REFERENCES参考文献

Expand all全部展开 | Collapse all 全部折叠

 

SUMMARY 概要

       In Microsoft Visual Studio 6.0, you can insert a splash screen in an MFC Single-Document Interface(SDI) application or a Multiple-Document Interface(MDI) application by using the Visual C++ Component Gallery

    在Microsoft Visual Studio 6.0中,你可以使用Visual C++组件库在MFC单文档界面(SDI)或多文档界面中插入启动画面。

       However, you cannot insert a splash screen in a dialog-based application in the Visual C++Component Gallery.

    然而,你不能在Visual C++组件库中基于对话框的应用程序中插入启动画面。

       For additional information about how to add a splash screen to an MFC dialog-based application in Microsoft Visual Studio 6.0, click the following article number to view the article in the Microsoft Knowledge Base:

    关于如何使用Visual Studio 6.0为一个MFC基于对话框的应用程序添加一个启动画面,单击下面的文章编号以查看Microsoft知识库中相应的文章:

       190684 HOWTO: Insert a Splash Screen into a Dialog-Based Application

       190684 HOWTO:在基于对话框的应用程序里插入启动画面

       Because there is no direct way to create a splash screen in Visual C++.NET or in Visual C++ 2005, you must build a dialog-based application by using the AppWizard, and the add a class that derives from CDialog(for example, CSplashDlg).

    因为没有直接方法在Visual C++.NET或Visual C++2005中创建启动画面,你必须使用应用程序向导建立一个基于对话框的应用程序,然后添加一个派生于CDialog的类(例如,CSplashDlg)。

       Modify the code to be a splash screen.

    修改代码成为启动画面。

 

Create and Insert a Splash Screen in a Dialog-based Application创建并插入基于对话框的应用程序中的启动画面

       To Create and insert a splash screen in dialog-based application, follow thes steps:

    要在一个基于对话框的应用程序中创建并插入启动画面,请按下列步骤:

1.       Start Visual Studio.NET or Microsoft Visual Studio 2005.

       启动Visual Studio.NET 或Microsoft Visual Studio 2005。

2.       On the File menu, point to New, and then click Project.

       在文件工资单上,指向新建,然后单击项目。

3.       Click Visual C++ Projects under Project Types, and then click MFC Application under Templets.

       单击项目类型下的Visual C++项目,然后单击模板下的MFC应用程序。

                     Note In Visual Studio 2005, click Visual C++ under Project Types, and then click MFC Application                   under Templetes.

           注意在Visual Studio2005中,单击项目类型下的Visual C++,然后单击模板下的MFC应用程序。

4.       Name the project MyApp, and then click OK.

       将该项目命名为MyApp,然后单击确定。

5.       The MFC Application Wizard dialog box appears.

       出现MFC应用程序向导对话框。

6.       Click Application Type, click Dialog based, and then click Finish.

       单击应用程序类型,单基于对话框,然后单击完成。

 

Create a Dialog Box in the Resource Editor在资源编辑器中创建一个对话框

      To create a dialog box in the resource editor that is both visible and entered, with a thin border and no caption, follow these steps:

    要在资源编辑器创建一个可见的,居中的,细边框的,没有标题的对话框,请按下列步骤:

1.       In Resource View, expand MyApp.rc, right-click the Dialog folder, and then click Insert Dialog. By default IDD_DIALOG is created.

       在资源管理器视图中,展开MyApp.rc,右击对话框文件夹,然后单击插入对话框。默认创建                     IDD_DIALOG1。

2.       Remove the OK button and the Cancel button from IDD_DIALOG1. To do this, right-click each button, and then click Delete.

       从IDD_DIALOG1中移除确定按钮和取消按钮。要做到这一点,右键单击每个按钮,然后单删除。

3.       Right-click in IDD_DIALOG1, and then click Properties.

       右击IDD_DIALOG1,然后单击属性。

4.       Under Misc, double-click ID.

       在杂项下,双击标识。

                     Note In Visual Studio 2005, double-click ID under Horizontal Scrollbar.

           注意在Visual Studio 2005中,双击在Horizontal Scrollbar下的ID。

5.       In the ID property, click IDD_DIALOG1, and then type IDD_SPLASH.

       在ID属性里,单击IDD_DIALOG1,然后键入IDD_SPLASH。

6.       Under Appearance, set the Title Bar property to False, and then set the Border property to Thin.

       在外观下,设置Title bar属性为False,然后设置边框属性为Thin。

 

Add Text to Your Splash Screen添加文本到您的启动画面

1.       Add a Static Text control to IDD_SPLASH.

       将静态文本控件添加到IDD_SPLASH。

2.       Edit the text in Caption property.

       在标题属性中编辑文本。

 

Create a New CDialog Derived Class创建一个新的CDialog派生类

1.       Double-click the dialog box. The MFC Class Wizard dialog box appears.

       双击对话框,出现MFC类向导对话框。

2.       Type CSplashDlg in the Class name text box, and then click CDialog in the Base class list.

       在类名文本框中键入CSplashDlg,然后在基类列表中单击CDialog。

3.       Click Finish. SplashDlg.cpp and SplashDlg.h are added to your project.

       单击完成。SplashDlg.cpp和SplashDlg.h被添加到项目中。

 

Add Function to Your Project添加函数到项目

1.       Declared the c_pSplashDlg static variable by adding the following line to the SplashDlg.h file:

       声明静态变量c_pSplashDlg,添加下列行到SplashDlg.h文件中:

                            static CSplashDlg* c_pSplashDlg;

2.       In Class View, right-click CSplashDlg, point to Add, and then click Add Function to add the following functions:

       在类视图中,右击CSplashDlg,指向添加,然后单击添加函数以添加以下函数:

              ShowSplashScreen(CWnd* pParentWnd): Static method that is used to display the splash dialog.

                                                                         静态方法,用于显示启动对话框。

a.       In the Return Type list, click void.

           在返回类型列表中,单击void。

b.       In the Function Name text box, type ShowSplashScreen.

           在函数名文本框中,键入ShowSplashScreen。

c.       In the Parameter Type list, click CWnd*.

           在参数类型列表中,单击CWnd*。

d.       In the Parameter Name text box, type pParentWnd.

           在参数名文本框中,键入pParentWnd。

e.       Click to select the Static check box.

           单击以选择静态复选框。

              HideSplashScreen(): Method that is used to destroy the splash dialog.

                                           该方法用于销毁启动画面。

a.       In the Return Type list, click void.

           在返回类型列表中,单击void。

b.       In the Function Name text box, type HideSplashScreen.

           在函数名称文本框中,键入HideSplashScreen。

              PreTranslateAppMessage(MSG* pMsg): Method that is use to hide the splash screen whenever        

                                         keyboard or mouse message are received.

                                                                       无论何时接收到键盘或鼠标消息,该方法用于隐藏启动画面。

a.       In the Return Type list, click BOOL.

           在返回类型列表中,单击BOOL。

b.       In the Function Name text box, type PreTranslateAppMessage.

           在函数名称文本框中,键入PreTranslateAppMessage。

c.       In the Parameter Type list, click MSG*.

           在参数类型列表中,单击MSG*。

d.       In the Parameter Name text box, type pMsg.

           在参数名称文本框中,键入pMsg。

e.       Click to select the Static check box.

           单击以选择静态复选框。

3.       Modify the three methods that you just created as follows:

       修改您刚刚创建,如下所示的三种方法:

void CSplashDlg::ShowSplashScreen(CWnd* pParentWnd /*= NULL*/)

{

              // Allocate a new splash screen, and create the window.

       c_pSplashDlg = new CSplashDlg;

       if (!c_pSplashDlg->Create(CSplashDlg::IDD, pParentWnd))

              delete c_pSplashDlg;

       else

              c_pSplashDlg->ShowWindow(SW_SHOW);

       c_pSplashDlg->UpdateWindow();

 

       c_pSplashDlg->SetTimer(1,2000, NULL);

}

 

void CSplashDlg::HideSplashScreen()

{

              // Destroy the window, and update the mainframe.

       c_pSplashDlg->KillTimer(1);

       DestroyWindow();

       AfxGetMainWnd()->UpdateWindow();

       delete c_pSplashDlg;

       c_pSplashDlg = NULL;

}

 

BOOL CSplashDlg::PreTranslateAppMessage(MSG* pMsg)

{

       if (c_pSplashDlg == NULL)

              return FALSE;

 

              // If you receive a keyboard or mouse message, hide the splash screen.

       if (c_pSplashDlg->m_hWnd != NULL && pMsg->message == WM_KEYDOWN ||

              pMsg->message == WM_SYSKEYDOWN ||

              pMsg->message == WM_LBUTTONDOWN ||

              pMsg->message == WM_RBUTTONDOWN ||

              pMsg->message == WM_MBUTTONDOWN ||

              pMsg->message == WM_NCLBUTTONDOWN ||

              pMsg->message == WM_NCRBUTTONDOWN ||

              pMsg->message == WM_NCMBUTTONDOWN)

       {

              c_pSplashDlg->HideSplashScreen();

              return TRUE;                                                                // message handled here

       }

       return FALSE;                                                                      // message not handled

}

              Note You must add the common language runtime support compliler option(/clr:oldSyntax)in Visual C++        2005 to successfully compile this code sample. To do this, follow these steps:

       注意您必须添加公共语言运行库支持的编译器选项(/clr:oldSyntax)在Visual C++ 2005中成功编译    此代码示例。若要这样做,请按下列步骤:

1.       Click Project, and then click ProjectName Properties.

       单击项目,然后单击项目名属性。

              Note ProjectName represents the name of the project.

       注意项目名代表项目的名称。

2.       Expand Configuration Properties, and the click General.

       展开配置属性,然后单击常规。

3.       Click to select Common language Runtime Support, Old Syntax(/clr:oldSyntax)in the Common Language Runtime support project setting on the right pane, click Apply, and then click OK.

       单击以选择公共语言运行库支持,$旧语法(/clr:oldSyntax)在右窗格的公共语言运行库支持中,         单击应用,然后单击确定。

                     For more information about the common language runtime support compiler options, visit the                     following Microsoft Web site:

           有关公共语言运行库支持编译选项的更多信息,浏览下面Microsoft网页站点:

                     /clr(Common Language Runtime Compilation)

           http://msdn2.microsoft.com/en-us/library/k811d4s.aspx

4.       Add the OnTimer event. To do this, follow these steps:

       添加OnTimer事件。做到这点,请按照下列步骤:

a.       In Class View, right-click CSplashDlg, and then click Properties.

           在类视图中右击CSplashDlg,然后单击属性。

b.       In the Properties pane, click the Message icon to view the message.

           在属性空格中单击消息图标以查看消息。

c.       In the WM_TIMER field, click OnTimer.

           在WM_TIMER字段中单击OnTimer。

d.       Modify the mothed as follow:

           按如下修改方法

                     void CSplashDlg::OnTimer(UINT nIDEvent)

                     {

                                   // Destroy the splash screen window.

                            HideSplashScreen();

                     }

5.       Override the OnInitDialog method of the CSplashDlg class, To do this, follow these steps:

       重写CSplashDlg类的方法OnInitDialog。要做到这点,请按下列步骤:

a.       In Class View, right-click CSplashDlg, and then click Properties.

           在类视图中右击CSplashDlg,然后单击属性。

b.       In the Properties pane, click the Overrides icon to display the list of overridable methods. In the OnInitDialog field, click <Add> OnInitDialog.

           在属性窗格中单击重写图标以显示

c.       Modify the OnInitDialog override method that you created in step b. To do this, follow these steps:

                     修改你在步骤b中创建的重载方法OnInitDialog。要做到这点,请按下列步骤:

                     BOOL CSplashDlg::OnInitDialog()

                     {

                            CDialog::OnInitDialog();

                            CenterWindow();

                           

                            SetWindowPos(&CWnd::wndTopMost, 0, 0, 0, 0,

                            SWP_NOMOVE|SWP_NOSIZE);

                           

                            return TRUE;  // return TRUE  unless you set the focus to a control

                     }

 

Display the Splash Screen显示启动屏幕

       To view the splash screen, open your application source file, MyAppDlg.cpp, and then follow these steps:

    要查看启动画面,打开你的应用程序源文件MyAppDlg.cpp,然后按下列步骤:

1.       Add the following lines of code at the beginning of the file:

       在文件开头添加下列代码行:

         #include "SplashDlg.h"

              //This is required ( in one of the files ) because the static variable 'c_pSplashDlg' is declared outside           //this file

       CSplashDlg* CSplashDlg::c_pSplashDlg;

2.       In the OnInitDialog() method, add the following code after the line CDialog::OnInitDialog():

       在OnInitDialog()方法中,在CDialog::OnInitDialog()行之后添加下列代码:

                            CSplashDlg::ShowSplashScreen(NULL);

3.       Override the PreTranslateMessage method of CMyAppDlg class. To do this, follow these steps:

       重写CMyAppDlg类的PreTranslateMessage方法。要做到这点,请按下列步骤:

a.       In Class View, right-click CMyAppDlg, and then click Properties.

           在类视图中右击CMyAppDlg,然后单击属性

b.       In the Properties pane, click the Override icon to display the list of overridable methods.

           在属性窗格中,单击重写图标以显示可重写的方法列表。

c.       In the PreTranslateMessage field, click <Add> PreTranslateMessage.

           在PreTranslateMessage字段中,单击<添加>PreTranslateMessage。

4.       Modify the PreTranslateMessage override method that you created in step c as follows:

       按如下修改您在步骤c中创建的PreTranslateMessage重写方法:

              BOOL CMyAppDlg::PreTranslateMessage(MSG* pMsg)

              {

                            // TODO: Add your specialized code here and call the base class, or both.

                     if (CSplashDlg::PreTranslateAppMessage(pMsg))

                            return TRUE;

                     return CDialog::PreTranslateMessage(pMsg);

              }

 

Compile the Solution 编译该解决方案

       Press F5 to compile the solution and to run the application. You may see that the splash screen is displayed.

    按F5键以编译该解决方案并运行该应用程序。你可能看到启动画面显示出来。

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值