| 如何给基于对话框的应用加启动画面 下载源代码 CDialog::OnInitDialog() CWinApp::InitInstance() CWinApp::PreTranslateMessage(MSG* pMsg)如果你用应用程序向导(AppWizard)创建工程,那么它会自动在CWinApp.h和CWinApp.cpp文件中产生 OnInitDialog 和 InitInstance 的声明和实现的默认代码,但是与CWinApp::PreTranslateMessage(MSG* pMsg)有关的处理必须自己添加到CWinApp派生类中。 第一步: 在CDialog::OnInitDialog()方法末尾添加下列代码: // 创建并显示启动画面 CSplashWnd::ShowSplashScreen(3000, IDB_SPLASH24, this);ShowSplashScreen函数的第一个参数是超时时间,以毫秒计算,表示启动画面持续显示的时间;第二个参数是位图图像的资源标示符,表示启动画面显示的图像。最后一个参数是父窗口,此参数可以为NULL。 第二步: 在CWinApp::InitInstance()方法的开始处添加如下代码: // Enable the splash screen component based on the command line info. CCommandLineInfo cmdInfo; ParseCommandLine(cmdInfo); CSplashWnd::EnableSplashScreen(cmdInfo.m_bShowSplash);这几行代码的作用是让程序能解析和处理命令行信息。 第三步: 用类向导(ClassWizard)改写 CWinApp::PreTranslateMessage(MSG* pMsg)方法,并添加如下代码: BOOL CDialogsplApp::PreTranslateMessage(MSG* pMsg) { // Route messages to the splash screen while it is visible if (CSplashWnd::PreTranslateAppMessage(pMsg)) { return TRUE; } return CWinApp::PreTranslateMessage(pMsg); } 编译运行程序。 |
0
顶一下
如何给基于对话框的应用加启动画面
| 与 相关的 | 教程 |

发表评论
告诉好友