⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ch01.htm

📁 VC使用大全。里面集合了VC使用的各种使用技巧。非常有用。
💻 HTM
📖 第 1 页 / 共 5 页
字号:
<TD>

<P>Start app and await DDE command.</P>

<TR>

<TD>

<pre><font color="#008000">/Automation</font></pre>

<TD>

<P>Start app as an OLE automation server.</P>

<TR>

<TD>

<pre><font color="#008000">/Embedding</font></pre>

<TD>

<P>Start app to edit an embedded OLE item.</P></TABLE>

<P>If you would like to implement other behavior, make a class that inherits from <font color="#008000">CCommandLineInfo</font> to hold the parsed command line, then override <font color="#008000">CWinApp:: ParseCommandLine()</font> and <font 
color="#008000">CWinApp::ProcessShellCommand()</font> in your own App class.</P>

<blockquote><p><img src="tip.gif" tppabs="http://www.mcp.com/814147200/0-7897/0-7897-1145-1/tip.gif">

<P>You may have already known that you could invoke many Windows programs from the command line; for example, typing <B>Notepad blah.txt</B> at a DOS prompt will open blah.txt in Notepad. Other command line options work too, so typing <B>Notepad /p 
blah.txt</B> will open blah.txt in Notepad and print it.</P>

<p><img src="bottom.gif" tppabs="http://www.mcp.com/814147200/0-7897/0-7897-1145-1/bottom.gif"></blockquote>

<P>That's the end of <font color="#008000">InitInstance()</font>. It returns <font color="#008000">TRUE</font> to indicate that the rest of the application should now run.</P>

<P>The message map in the header file indicated that the function <font color="#008000">OnAppAbout()</font> handles a message. Which one? Here's the message map from the source file:</P>

<pre><font color="#008000">BEGIN_MESSAGE_MAP(CFirstSDIApp, CWinApp)</font></pre>

<pre><font color="#008000">     //{{AFX_MSG_MAP(CFirstSDIApp)</font></pre>

<pre><font color="#008000">     ON_COMMAND(ID_APP_ABOUT, OnAppAbout)</font></pre>

<pre><font color="#008000">          // NOTE - the ClassWizard will add and remove mapping macros here.</font></pre>

<pre><font color="#008000">          //    DO NOT EDIT what you see in these blocks of generated code!</font></pre>

<pre><font color="#008000">     //}}AFX_MSG_MAP</font></pre>

<pre><font color="#008000">     // Standard file based document commands</font></pre>

<pre><font color="#008000">     ON_COMMAND(ID_FILE_NEW, CWinApp::OnFileNew)</font></pre>

<pre><font color="#008000">     ON_COMMAND(ID_FILE_OPEN, CWinApp::OnFileOpen)</font></pre>

<pre><font color="#008000">     // Standard print setup command</font></pre>

<pre><font color="#008000">     ON_COMMAND(ID_FILE_PRINT_SETUP, CWinApp::OnFilePrintSetup)</font></pre>

<pre><font color="#008000">END_MESSAGE_MAP()</font></pre>

<P>This message map catches commands from menus, as discussed in <A HREF="index04.htm" tppabs="http://www.mcp.com/814147200/0-7897/0-7897-1145-1/index04.htm" target="text">Chapter 4</A>, &quot;Messages and Commands.&quot; When the user chooses <U>H</U>elp <U>A</U>bout, <font color="#008000">CFirstSDIApp::OnAppAbout()</font> 
will be called. When the user chooses <U>F</U>ile <U>N</U>ew, <U>F</U>ile <U>O</U>pen, or <U>F</U>ile Print Set<U>u</U>p, functions from <font color="#008000">CWinApp</font> will handle that work for you. (You would override those functions if you wanted 
to do something special for those menu choices.) <font color="#008000">OnAppAbout()</font> looks like this:</P>

<pre><font color="#008000">void CFirstSDIApp::OnAppAbout()</font></pre>

<pre><font color="#008000">{</font></pre>

<pre><font color="#008000">     CAboutDlg aboutDlg;</font></pre>

<pre><font color="#008000">     aboutDlg.DoModal();</font></pre>

<pre><font color="#008000">}</font></pre>

<P>This code declares an object that is an instance of <font color="#008000">CAboutDlg</font> and calls its <font color="#008000">DoModal()</font> function to display the dialog on the screen. (Dialog classes and the DoModal() function are both covered in 
<A HREF="index02.htm" tppabs="http://www.mcp.com/814147200/0-7897/0-7897-1145-1/index02.htm" target="text">Chapter 2</A>, &quot;Dialogs and Controls.&quot; There's no need to handle OK or Cancel in any special way&#151;this is just an About box.</P>

<P><B>Other files</B></P>

<P>If you selected Context Sensitive Help, AppWizard generates a .HPJ file and a number of .RTF files to give some context-sensitive help. These files are discussed in <A HREF="index11.htm" tppabs="http://www.mcp.com/814147200/0-7897/0-7897-1145-1/index11.htm" target="text">Chapter 11</A>, &quot;Help,&quot; in the 
&quot;Components of the Help System&quot; section.</P>

<P>AppWizard also generates a README.TXT file that explains what all the other files are and what classes have been created. Read this file if all the similar file names start to get confusing.</P>

<H3><B>Understanding A Multiple Document Interface Application</B></H3>

<P>A Multiple Document Interface application also has menus, and enables the user to have more than one document open at once. This section presents the code that is generated when you choose an MDI application with no database or compound document 
support, but instead with a toolbar, a status bar, Help, 3-D controls, source file comments, and the MFC library as a shared DLL. As with the SDI application, these are the defaults after Step 1. The focus here is on what is different from the SDI 
application in the previous section.</P>

<P>Five classes have been created for you: for the application called <font color="#008000">FirstMDI,</font> they are:</P>

<ul>

<li> <font color="#008000">CAboutDlg</font>, a dialog class for the About dialog box</P>

<li> <font color="#008000">CFirstMDIApp</font>, a CWinApp class for the entire application</P>

<li> <font color="#008000">CFirstMDIDoc</font>, a document class</P>

<li> <font color="#008000">CFirstMDIView</font>, a view class</P>

<li> <font color="#008000">CMainFrame</font>, a frame class</P>

</ul>

<P>The App class header is shown in Listing 1.3.</P>

<P><I>Listing 1.3&#151;FirstMDI.h&#151;main header file for the FirstMDI </I><I>application</I></P>

<pre><font color="#008000">// FirstMDI.h : main header file for the FIRSTMDI application</font></pre>

<pre><font color="#008000">//</font></pre>

<pre><font color="#008000">#if !defined(AFX_FIRSTMDI_H__CDF38D9E_8718_11D0_B02C_0080C81A3AA2__INCLUDED_)</font></pre>

<pre><font color="#008000">#define AFX_FIRSTMDI_H__CDF38D9E_8718_11D0_B02C_0080C81A3AA2__INCLUDED_</font></pre>

<pre><font color="#008000">#if _MSC_VER &gt;= 1000</font></pre>

<pre><font color="#008000">#pragma once</font></pre>

<pre><font color="#008000">#endif // _MSC_VER &gt;= 1000</font></pre>

<pre><font color="#008000">#ifndef __AFXWIN_H__</font></pre>

<pre><font color="#008000">     #error include 'stdafx.h' before including this file for PCH</font></pre>

<pre><font color="#008000">#endif</font></pre>

<pre><font color="#008000">#include &quot;resource.h&quot;       // main symbols</font></pre>

<pre><font color="#008000">/////////////////////////////////////////////////////////////////////////////</font></pre>

<pre><font color="#008000">// CFirstMDIApp:</font></pre>

<pre><font color="#008000">// See FirstMDI.cpp for the implementation of this class</font></pre>

<pre><font color="#008000">//</font></pre>

<pre><font color="#008000">class CFirstMDIApp : public CWinApp</font></pre>

<pre><font color="#008000">{</font></pre>

<pre><font color="#008000">public:</font></pre>

<pre><font color="#008000">     CFirstMDIApp();</font></pre>

<pre><font color="#008000">// Overrides</font></pre>

<pre><font color="#008000">     // ClassWizard generated virtual function overrides</font></pre>

<pre><font color="#008000">     //{{AFX_VIRTUAL(CFirstMDIApp)</font></pre>

<pre><font color="#008000">     public:</font></pre>

<pre><font color="#008000">     virtual BOOL InitInstance();</font></pre>

<pre><font color="#008000">     //}}AFX_VIRTUAL</font></pre>

<pre><font color="#008000">// Implementation</font></pre>

<pre><font color="#008000">     //{{AFX_MSG(CFirstMDIApp)</font></pre>

<pre><font color="#008000">     afx_msg void OnAppAbout();</font></pre>

<pre><font color="#008000">          // NOTE - the ClassWizard will add and remove member functions here.</font></pre>

<pre><font color="#008000">          //    DO NOT EDIT what you see in these blocks of generated code !</font></pre>

<pre><font color="#008000">     //}}AFX_MSG</font></pre>

<pre><font color="#008000">     DECLARE_MESSAGE_MAP()</font></pre>

<pre><font color="#008000">};</font></pre>

<pre><font color="#008000">/////////////////////////////////////////////////////////////////////////////</font></pre>

<pre><font color="#008000">//{{AFX_INSERT_LOCATION}}</font></pre>

<pre><font color="#008000">// Microsoft Developer Studio will insert additional declarations immediately before the </font><font color="#008000">previous line.</font></pre>

<pre><font color="#008000">#endif // !defined(AFX_FIRSTMDI_H__CDF38D9E_8718_11D0_B02C_0080C81A3AA2__INCLUDED_)</font></pre>

<P>How does this differ from FirstSDI.h? Only in the class names. The constructor is also the same as before. And <font color="#008000">OnAppAbout()</font> is just like the SDI version. How about <font color="#008000">InitInstance()</font>? It is in 
Listing 1.4.</P>

<P><I>Listing</I><I><font color="#008000"> 1</font></I><I>.4&#151;CFirstMDIApp::InitInstance()</I></P>

<pre><font color="#008000">BOOL CFirstMDIApp::InitInstance()</font></pre>

<pre><font color="#008000">{</font></pre>

<pre><font color="#008000">     AfxEnableControlContainer();</font></pre>

<pre><font color="#008000">     // Standard initialization</font></pre>

<pre><font color="#008000">   

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -