界面开发套包Xtreme Toolkit Pro:如何运用CSplashWnd类生成带有启动动画的对话框
Xtreme Toolkit Pro是MFC开发中最全面界面控件套包,它提供了Windows开发所需要的11种主流的Visual C++ MFC控件,包括Command Bars、Controls、Chart Pro、Calendar、Docking Pane、Property Grid、Report Control、Shortcut Bar、Syntax Edit、Skin Framework 和Task Panel。
【同类产品】
- BCGControlBar Professional Edition for MFC: 是一个MFC扩展库,使您可以创建具有完全自定义的选项以及一组专业设计的丰富Microsoft Office和Microsoft Visual Studio的应用程序 GUI控件,例如图表、日历、网格、编辑器、甘特图和许多其他控件。
- BCGControlBar for .NET :包含有大量高度自定义、完全可设计的.NET界面控件,用户可以使用这些来创建精致美观的图形用户界面。
带有启动画面的对话框
如果您曾经创建过对话框应用程序,然后尝试使用初始屏幕组件添加初始屏幕,则可能会发现无法成功实现此操作。本文是使用CSplashWnd类将闪屏添加到对话框应用程序的快速提示 。此类是通常由初始组件为文档视图项目生成的类的增强版本。
为了在基于对话框的应用程序中使用CSplashWnd,我们将必须重写三个函数CDialog :: OnInitDialog(),CWinApp :: InitInstance()和CWinApp :: PreTranslateMessage(MSG * pMsg)。如果使用AppWizard,则在创建项目时应该已经将OnInitDialog和InitInstance添加到了项目中,但是可能必须将PreTranslateMessage添加到CWinApp派生类中。
步骤1:
在失去作用域之前,将以下代码行添加到CDialog :: OnInitDialog()方法中。ShowSplashScreen的第一个参数是超时值(以毫秒为单位)。这是启动屏幕将在关闭前显示多长时间。第二个参数是我们将用作初始屏幕的位图图像的资源标识符。最后一个参数是父窗口。此参数可以为NULL。
// Create and show the splash screen. CSplashWnd::ShowSplashScreen(3000, IDB_SPLASH24, this); return TRUE; // return TRUE unless you set the focus to // a control }
步骤2:
在调用ParseCommandLine(...)之后,将以下代码行添加到CWinApp :: InitInstance()的开头。如果尚未包含ParseCommandLine,则需要添加它。
BOOL CDialogsplApp::InitInstance() { // Enable the splash screen component based on the command // line info. CCommandLineInfo cmdInfo; ParseCommandLine(cmdInfo); CSplashWnd::EnableSplashScreen(cmdInfo.m_bShowSplash);
步骤3:
使用类向导覆盖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); }
今天的内容就是这些了,下载最新版Xtreme ToolKit Pro并在下方评论区分享您对该产品的想法。