📄 chap8_8.htm
字号:
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<meta name="GENERATOR" content="Microsoft FrontPage 3.0">
<title>8.8 防止应用程序运行时自动创建空白窗口</title>
<link rel="stylesheet" href="../../../cpcw.css"></head>
<body link="#3973DE" alink="#3973DE" background="../../bg.gif">
<div align="center"><center>
<table width="85%" border="0">
<tr bgcolor="#FFFFFF">
<td>
<div align="center">
<center>
</center>
</div>
<p align="CENTER"><b><font color="red" face="Times New Roman">8.8 </font><font color="red">防止应用程序运行时自动创建空白窗口</font></b></p>
<p> 在前面的MDI程序中,当应用程序启动时,都会自动创建一个空白窗口。但有时我们并不希望创建这样的空白窗口。比如,对于一个文件浏览器来说,空白窗口就没有什么意义。</p>
<p> 要防止空白窗口的创建,首先就要明白这个窗口是如何被创建的。在InitInstance()中,有一个命令行的执行过程,当命令行上没有参数时,函数ParseCommandLine(cmdInfo)会将CCommandLineInfo::m_nShellCommand成员置为CCommandLineInfo::FileNew,这将导致ProcessShellCommand调用CWinApp::OnFileNew成员函数。要想防止程序开始时就调用OnFileNew,解决方法之一是去掉与命令行有关的代码,但是这样就没有了命令行处理功能。另一种方法是在ProcessShellCommand调用之前加一句cmdInfo.m_nShellCommand
=CCommandLineInfo::FileNothing。具体代码见清单8.12。</p>
<p><b>清单8.12 不自动创建空白文档窗口的InitInstance成员函数定义</b></p>
<font face="Times New Roman" size="3">
<p>BOOL CDrawApp::InitInstance()</p>
</font>
<p><font face="Times New Roman" size="3">{</font></p>
<p><font face="Times New Roman" size="4"> <b></b></font><font face="Times New Roman" size="3">//
Enable DDE Execute open</font></p>
<font face="Times New Roman" size="3">
<p>EnableShellOpen();</p>
<p>RegisterShellFileTypes(TRUE);</p>
<p>// Parse command line for standard shell commands, DDE, file open</p>
<p>CCommandLineInfo cmdInfo;</p>
<p>// Alter behaviour to not open window immediately</p>
</font>
<p><font face="Times New Roman" size="3"></font><b> </b></p>
<b><font face="Times New Roman" size="3">
<p>cmdInfo.m_nShellCommand = CCommandLineInfo::FileNothing;</p>
</font></b><font face="Times New Roman" size="3">
<p>ParseCommandLine(cmdInfo);</p>
<p>// Dispatch commands specified on the command line</p>
<p>if (!ProcessShellCommand(cmdInfo))</p>
</font>
<p><font face="Times New Roman" size="3">return FALSE;</font></p>
<p><font face="Times New Roman" size="4"> <b>//</b></font><font face="Times New Roman" size="3">......</font></p>
<p> <font face="Times New Roman" size="3">}</font></p>
<div align="center">
<center>
<table border="0" cellpadding="0" cellspacing="0" width="615">
<tr>
<td><a href="chap8_7.htm">上一页</a></td>
<td>
<p align="right"><a href="chap8_9.htm">下一页</a>
</td>
</tr>
</table>
<p><a href="http://www.cpcw.com">电脑报首页</a> <a href="../../index.htm">网络学院首页</a></p>
</center>
</div>
<font size="5">
<hr noshade color="#3973DE" size="1">
</font>
<p align="center"><font size="5"></font><font size="2" color="#000000">本教程由<a href="http://vcdynasty.yeah.net">Visual
C++王朝(Where programmers come together)</a>协助制作<br>
未经许可,请勿以任何形式复制</font>
</td>
</tr>
</table>
</center>
</div>
</body>
</html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -