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

📄 ch13.htm

📁 VC 21天 学习VC 的好东西
💻 HTM
📖 第 1 页 / 共 5 页
字号:
be a database application, you'll find it easiest to use CFormView as the base class
from which your view class will be inherited. This enables you to use the dialog
designer for your application view.</P>
<P>Once you finish making your way through the AppWizard and let the AppWizard create
your application shell, you will see a large window canvas in the dialog designer
as if you had created a dialog-style application, only without the OK and Cancel
buttons, as shown in Figure 13.2.</P>
<P><A HREF="javascript:popUp('13fig02tif.gif')"><B>FIGURE 13.2.</B></A><B> </B><I>The
window designer for an SDI appli-cation.</I></P>

<P><I></I>
<H4>Designing Your Application Window</H4>
<P>After you create an SDI or MDI application where the view class is based on the
CFormView class, you need to design your application view. Designing the view is
much like designing the window layout for a dialog window, but you don't need to
worry about including any buttons to close the window while either saving or canceling
the work done by the user. With an SDI or MDI application, the functionality to save
and exit the window is traditionally located on the application menus or on the toolbar.
As a result, you need to include only the controls for the function that your application
window will perform.</P>


<BLOCKQUOTE>
	<P>
<HR>
<STRONG>NOTE:</STRONG> If you are building dialog-style applications, the AppWizard doesn't
	provide any serialization code in your application shell. If you need to serialize
	a dialog-style application, you'll need to add all this code yourself.
<HR>


</BLOCKQUOTE>

<P>For the sample application that you are building today, lay out controls on the
window canvas as shown in Figure 13.3 using the control properties listed in Table
13.1.</P>
<P><A HREF="javascript:popUp('13fig03tif.gif')"><B>FIGURE 13.3.</B></A><B> </B><I>The
sample application window layout.</I></P>

<P><I></I>
<H4>TABLE 13.1. CONTROL PROPERTY SETTINGS.</H4>
<P>
<TABLE BORDER="1">
	<TR ALIGN="LEFT" VALIGN="TOP">
		<TD ALIGN="LEFT"><I>Object</I></TD>
		<TD ALIGN="LEFT"><I>Property</I></TD>
		<TD ALIGN="LEFT"><I>Setting</I></TD>
	</TR>
	<TR ALIGN="LEFT" VALIGN="TOP">
		<TD ALIGN="LEFT">
			<H4>Static Text
		</TD>
		<TD ALIGN="LEFT">
			<H4>ID
		</TD>
		<TD ALIGN="LEFT">
			<H4>IDC_STATIC
		</TD>
	</TR>
	<TR ALIGN="LEFT" VALIGN="TOP">
		<TD ALIGN="LEFT">			<P>
		</TD>
		<TD ALIGN="LEFT">Caption		</TD>
		<TD ALIGN="LEFT">&amp;Name:		</TD>
	</TR>
	<TR ALIGN="LEFT" VALIGN="TOP">
		<TD ALIGN="LEFT">Edit Box		</TD>
		<TD ALIGN="LEFT">ID		</TD>
		<TD ALIGN="LEFT">IDC_ENAME		</TD>
	</TR>
	<TR ALIGN="LEFT" VALIGN="TOP">
		<TD ALIGN="LEFT">Static Text		</TD>
		<TD ALIGN="LEFT">ID		</TD>
		<TD ALIGN="LEFT">IDC_STATIC		</TD>
	</TR>
	<TR ALIGN="LEFT" VALIGN="TOP">
		<TD ALIGN="LEFT">			<P>
		</TD>
		<TD ALIGN="LEFT">Caption		</TD>
		<TD ALIGN="LEFT">&amp;Age		</TD>
	</TR>
	<TR ALIGN="LEFT" VALIGN="TOP">
		<TD ALIGN="LEFT">Edit Box		</TD>
		<TD ALIGN="LEFT">ID		</TD>
		<TD ALIGN="LEFT">IDC_EAGE		</TD>
	</TR>
	<TR ALIGN="LEFT" VALIGN="TOP">
		<TD ALIGN="LEFT">Static Text		</TD>
		<TD ALIGN="LEFT">ID		</TD>
		<TD ALIGN="LEFT">IDC_STATIC		</TD>
	</TR>
	<TR ALIGN="LEFT" VALIGN="TOP">
		<TD ALIGN="LEFT">			<P>
		</TD>
		<TD ALIGN="LEFT">Caption		</TD>
		<TD ALIGN="LEFT">Marital Status:		</TD>
	</TR>
	<TR ALIGN="LEFT" VALIGN="TOP">
		<TD ALIGN="LEFT">Radio Button		</TD>
		<TD ALIGN="LEFT">ID		</TD>
		<TD ALIGN="LEFT">IDC_RSINGLE		</TD>
	</TR>
	<TR ALIGN="LEFT" VALIGN="TOP">
		<TD ALIGN="LEFT">			<P>
		</TD>
		<TD ALIGN="LEFT">Caption		</TD>
		<TD ALIGN="LEFT">&amp;Single		</TD>
	</TR>
	<TR ALIGN="LEFT" VALIGN="TOP">
		<TD ALIGN="LEFT">			<P>
		</TD>
		<TD ALIGN="LEFT">Group		</TD>
		<TD ALIGN="LEFT">Checked		</TD>
	</TR>
	<TR ALIGN="LEFT" VALIGN="TOP">
		<TD ALIGN="LEFT">Radio Button		</TD>
		<TD ALIGN="LEFT">ID		</TD>
		<TD ALIGN="LEFT">IDC_RMARRIED		</TD>
	</TR>
	<TR ALIGN="LEFT" VALIGN="TOP">
		<TD ALIGN="LEFT">			<P>
		</TD>
		<TD ALIGN="LEFT">Caption		</TD>
		<TD ALIGN="LEFT">&amp;Married		</TD>
	</TR>
	<TR ALIGN="LEFT" VALIGN="TOP">
		<TD ALIGN="LEFT">Radio Button		</TD>
		<TD ALIGN="LEFT">ID		</TD>
		<TD ALIGN="LEFT">IDC_RDIVORCED		</TD>
	</TR>
	<TR ALIGN="LEFT" VALIGN="TOP">
		<TD ALIGN="LEFT">			<P>
		</TD>
		<TD ALIGN="LEFT">Caption		</TD>
		<TD ALIGN="LEFT">&amp;Divorced		</TD>
	</TR>
	<TR ALIGN="LEFT" VALIGN="TOP">
		<TD ALIGN="LEFT">Radio Button		</TD>
		<TD ALIGN="LEFT">ID		</TD>
		<TD ALIGN="LEFT">IDC_RWIDOW		</TD>
	</TR>
	<TR ALIGN="LEFT" VALIGN="TOP">
		<TD ALIGN="LEFT">			<P>
		</TD>
		<TD ALIGN="LEFT">Caption		</TD>
		<TD ALIGN="LEFT">&amp;Widowed		</TD>
	</TR>
	<TR ALIGN="LEFT" VALIGN="TOP">
		<TD ALIGN="LEFT">Check Box		</TD>
		<TD ALIGN="LEFT">ID		</TD>
		<TD ALIGN="LEFT">IDC_CBEMPLOYED		</TD>
	</TR>
	<TR ALIGN="LEFT" VALIGN="TOP">
		<TD ALIGN="LEFT">			<P>
		</TD>
		<TD ALIGN="LEFT">Caption		</TD>
		<TD ALIGN="LEFT">&amp;Employed		</TD>
	</TR>
	<TR ALIGN="LEFT" VALIGN="TOP">
		<TD ALIGN="LEFT">Button		</TD>
		<TD ALIGN="LEFT">ID		</TD>
		<TD ALIGN="LEFT">IDC_BFIRST		</TD>
	</TR>
	<TR ALIGN="LEFT" VALIGN="TOP">
		<TD ALIGN="LEFT">			<P>
		</TD>
		<TD ALIGN="LEFT">Caption		</TD>
		<TD ALIGN="LEFT">&amp;First		</TD>
	</TR>
	<TR ALIGN="LEFT" VALIGN="TOP">
		<TD ALIGN="LEFT">Button		</TD>
		<TD ALIGN="LEFT">ID		</TD>
		<TD ALIGN="LEFT">IDC_BPREV		</TD>
	</TR>
	<TR ALIGN="LEFT" VALIGN="TOP">
		<TD ALIGN="LEFT">			<P>
		</TD>
		<TD ALIGN="LEFT">Caption		</TD>
		<TD ALIGN="LEFT">&amp;Previous		</TD>
	</TR>
	<TR ALIGN="LEFT" VALIGN="TOP">
		<TD ALIGN="LEFT">Button		</TD>
		<TD ALIGN="LEFT">ID		</TD>
		<TD ALIGN="LEFT">IDC_BNEXT		</TD>
	</TR>
	<TR ALIGN="LEFT" VALIGN="TOP">
		<TD ALIGN="LEFT">			<P>
		</TD>
		<TD ALIGN="LEFT">Caption		</TD>
		<TD ALIGN="LEFT">Nex&amp;t		</TD>
	</TR>
	<TR ALIGN="LEFT" VALIGN="TOP">
		<TD ALIGN="LEFT">Button		</TD>
		<TD ALIGN="LEFT">ID		</TD>
		<TD ALIGN="LEFT">IDC_BLAST		</TD>
	</TR>
	<TR ALIGN="LEFT" VALIGN="TOP">
		<TD ALIGN="LEFT">			<P>
		</TD>
		<TD ALIGN="LEFT">Caption		</TD>
		<TD ALIGN="LEFT">&amp;Last		</TD>
	</TR>
	<TR ALIGN="LEFT" VALIGN="TOP">
		<TD ALIGN="LEFT">Static Text		</TD>
		<TD ALIGN="LEFT">ID		</TD>
		<TD ALIGN="LEFT">IDC_SPOSITION		</TD>
	</TR>
	<TR ALIGN="LEFT" VALIGN="TOP">
		<TD ALIGN="LEFT">			<P>
		</TD>
		<TD ALIGN="LEFT">Caption		</TD>
		<TD ALIGN="LEFT">Record 0 of 0		</TD>
	</TR>
</TABLE>
</P>
<P>When you were developing dialog-style applications or windows, you attached variables
to the controls on the window in the dialog class. However, with an SDI or MDI application,
which class do you create the variables in? Because the UpdateData function is a
member of the CWnd class, and the view class is descended from the CWnd class, although
the document is not, then the view class is the most logical place to add the variables
that you will attach to the controls you placed on the window.</P>
<P>To attach variables to the controls in your sample application, open the Class
Wizard and add variables to the controls, specifying that the place to add them is
the view class (in this case, CSerializeView). For the sample application, add the
variables in Table 13.2 to the controls specified.</P>
<P>
<H4>TABLE 13.2. CONTROL VARIABLES.</H4>
<P>
<TABLE BORDER="1">
	<TR ALIGN="LEFT" VALIGN="TOP">
		<TD ALIGN="LEFT"><I>Object</I></TD>
		<TD ALIGN="LEFT"><I>Name</I></TD>
		<TD ALIGN="LEFT"><I>Category</I></TD>
		<TD ALIGN="LEFT"><I>Type</I></TD>
	</TR>
	<TR ALIGN="LEFT" VALIGN="TOP">
		<TD ALIGN="LEFT">IDC_CBEMPLOYED		</TD>
		<TD ALIGN="LEFT">m_bEmployed		</TD>
		<TD ALIGN="LEFT">Value		</TD>
		<TD ALIGN="LEFT">BOOL		</TD>
	</TR>
	<TR ALIGN="LEFT" VALIGN="TOP">
		<TD ALIGN="LEFT">IDC_EAGE		</TD>
		<TD ALIGN="LEFT">m_iAge		</TD>
		<TD ALIGN="LEFT">Value		</TD>
		<TD ALIGN="LEFT">int		</TD>
	</TR>
	<TR ALIGN="LEFT" VALIGN="TOP">
		<TD ALIGN="LEFT">IDC_ENAME		</TD>
		<TD ALIGN="LEFT">m_sName		</TD>
		<TD ALIGN="LEFT">Value		</TD>
		<TD ALIGN="LEFT">CString		</TD>
	</TR>
	<TR ALIGN="LEFT" VALIGN="TOP">
		<TD ALIGN="LEFT">IDC_RSINGLE		</TD>
		<TD ALIGN="LEFT">m_iMaritalStatus		</TD>
		<TD ALIGN="LEFT">Value		</TD>
		<TD ALIGN="LEFT">int		</TD>
	</TR>
	<TR ALIGN="LEFT" VALIGN="TOP">
		<TD ALIGN="LEFT">IDC_SPOSITION		</TD>
		<TD ALIGN="LEFT">m_sPosition		</TD>
		<TD ALIGN="LEFT">Value		</TD>
		<TD ALIGN="LEFT">CString		</TD>
	</TR>
</TABLE>
</P>
<P>If you examine the source code for the view class, you will notice that there
is no OnDraw function. If you are using the CFormView ancestor class for your SDI
or MDI application, you don't need to worry about the OnDraw function. Instead, you
treat the view class very much as you would the dialog class in a dialog window or
dialog-style application. The primary difference is that the data that you need to
use to populate the controls on the window are not in the view class, but in the
document class. As a result, you need to build the interaction between these two
classes to pass the data for the controls back and forth.</P>
<P>
<H3><A NAME="Heading8"></A>Creating a Serializable Class</H3>
<P>When you create a form-based application, it is assumed that your application
will hold multiple records in the form and that the user will be able to scroll through
the records to make changes. The user will be able to add additional records or even
remove records from the record set. The challenge at this point in building this
application is how you represent this set of records, supporting all the necessary
functionality.</P>
<P>One approach is to create a class that would encapsulate each record, and then
hold these records in an array, much as you did with the drawing application that
you created and enhanced over the past few days. This class would need to descend
from the CObject class and would need to contain variables for all the control variables
that you added to the view class, along with methods to read and write all of these

⌨️ 快捷键说明

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