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

📄 apb.htm

📁 Visual C++ 6.0 21天自学教程 一本适合初学和对c++有一定基础的人学习的好书
💻 HTM
📖 第 1 页 / 共 5 页
字号:
    ///////////////////////    CFileDialog m_ldFile(TRUE);    // Show the File open dialog and capture the result    if (m_ldFile.DoModal() == IDOK)    {        // Get the filename selected        m_sResults = m_ldFile.GetPathName();        // Update the dialog        UpdateData(FALSE);    }    ///////////////////////    // MY CODE ENDS HERE    ///////////////////////</PRE><PRE>}</PRE><DL>	<DT></DT>	<DD>The GetPathName function returns the path and filename, so changing the function	call from GetFileName to GetPathName alters the display to include the path with	the filename.	<P>	<DT></DT>	<DD><B>2. </B>Add a button on the custom dialog that calls the MessageBox function	with a Yes or No selection. Pass the result back to the main application dialog.	<P>	<DT></DT>	<DD>Follow these steps:	<P>	<DT></DT>	<DD><B>1. </B>Using the Class View, add a member variable to the CMsgDlg class. Specify	the variable type as int, the name as m_iYesNo, and the access as Public.	<P>	<DT></DT>	<DD><B>2. </B>Using the Resource View, bring the custom dialog into the editor area.	Add a command button to the window, named IDC_YESNO with a caption &amp;Yes or No.	<P>	<DT></DT>	<DD><B>3. </B>Using the Class Wizard, add a function to the new button you just added	and edit the function. Include the following code:	<P></DL><PRE>void CMsgDlg::OnYesno() {    // TODO: Add your control notification handler code here    ///////////////////////    // MY CODE STARTS HERE    ///////////////////////    // Ask the user    m_iYesNo = MessageBox(&quot;Choose Yes or No&quot;, &quot;Yes or No&quot;, &Acirc;MB_YESNO);    ///////////////////////    // MY CODE ENDS HERE    ///////////////////////</PRE><PRE>}</PRE><DL>	<DT></DT>	<DD><B>4. </B>Add a button to the main dialog window named IDC_YESNO with the caption	Y&amp;es or No.	<P>	<DT></DT>	<DD><B>5. </B>Using the Class Wizard, add a function to the new button, including	the following code:	<P></DL><PRE>void CDialogsDlg::OnYesno() {    // TODO: Add your control notification handler code here    ///////////////////////    // MY CODE STARTS HERE    ///////////////////////    // What did the user answer    switch (m_dMsgDlg.m_iYesNo)    {    case IDYES:    // Did the user answer YES?        m_sResults = &quot;Yes!&quot;;        break;    case IDNO:     // Did the user answer NO?        m_sResults = &quot;No!&quot;;        break;</PRE><PRE><B>}</B></PRE><P><PRE>    // Update the dialog    UpdateData(FALSE);    ///////////////////////    // MY CODE ENDS HERE    ///////////////////////</PRE><PRE>}</PRE><H2><A NAME="Heading16"></A>Day 6</H2><H3>Quiz</H3><DL>	<DT></DT>	<DD><B>1. </B>What event message does a menu selection send to the window message	queue?	<P>	<DT></DT>	<DD>COMMAND.	<P>	<DT></DT>	<DD><B>2. </B>How do you attach a menu to a dialog window?	<P>	<DT></DT>	<DD>In the dialog designer, open the properties dialog for the window, and choose	the menu from the drop-down list of menus.	<P>	<DT></DT>	<DD><B>3. </B>Which existing class do you specify for handling event messages for	the menu?	<P>	<DT></DT>	<DD>The dialog class for the window on which the menu appears.	<P>	<DT></DT>	<DD><B>4. </B>What event message should a pop-up menu be triggered by?	<P>	<DT></DT>	<DD>The WM_CONTEXTMENU event.	<P></DL><H3>Exercises</H3><DL>	<DT></DT>	<DD><B>1. </B>Add a button to the main window and have it call the same function	as the Hello menu entry.	<P>	<DT></DT>	<DD>Follow these steps:	<P>	<DT></DT>	<DD><B>1. </B>Add a button to the dialog screen. Supply a button ID of IDC_HELLO	and a caption of &amp;Hello.	<P>	<DT></DT>	<DD><B>2. </B>Using the Class Wizard, add a function to the button. Name the function	OnHello.	<P>	<DT></DT>	<DD><B>2. </B>Add a pop-up menu to your application that uses the Help drop-down	menu as the pop-up menu.	<P>	<DT></DT>	<DD>Follow these steps:	<P>	<DT></DT>	<DD><B>1. </B>Using the Class Wizard, add a function for the WM_CONTEXTMENU event	message in your dialog window.	<P>	<DT></DT>	<DD><B>2. </B>Edit the function, adding the following code:	<P></DL><PRE>void CMenusDlg::OnContextMenu(CWnd* pWnd, CPoint point){    // TODO: Add your message handler code here and/or call &Acirc;default    ///////////////////////    // MY CODE STARTS HERE    ///////////////////////    // Declare local variables    CMenu *m_lMenu;    // A pointer to the menu    CPoint m_pPoint;    // A copy of the mouse position    // Copy the mouse position to a local variable    m_pPoint = point;    // Convert the position to a screen position    ClientToScreen(&amp;m_pPoint);    // Get a pointer to the window menu    m_lMenu - GetMenu();    // Get a pointer to the first submenu    m_lMenu = m_lMenu-&gt;GetSubMenu(1);    // Show the Pop-up Menu    m_lMenu-&gt;TrackPopupMenu(TPM_CENTERALIGN + TPM_LEFTBUTTON,        m_pPoint.x, m_pPoint.y, this, NULL);    ///////////////////////    // MY CODE ENDS HERE    ///////////////////////    CDialog::OnRButtonDown(nFlags, point);</PRE><PRE>}</PRE><H2><A NAME="Heading19"></A>Day 7</H2><H3>Quiz</H3><DL>	<DT></DT>	<DD><B>1. </B>How can you specify that the text is to be underlined?	<P>	<DT></DT>	<DD>Pass 1 as the value for the bUnderline argument to the CreateFont function.	<P>	<DT></DT>	<DD><B>2. </B>How can you print your text upside down?	<P>	<DT></DT>	<DD>Pass 1800 as the nEscapement argument to the CreateFont function.	<P>	<DT></DT>	<DD><B>3. </B>How many times is the EnumFontFamProc callback function called by the	operating system?	<P>	<DD>The function is called once for each font that is available in the system, unless	the callback function returns 0 and stops the listing of fonts.</DL><H3>Exercises</H3><DL>	<DT></DT>	<DD><B>1. </B>Add a check box to switch between using the entered text to display	the font and using the font name to display the font, as in Figure 7.4.	<P>	<DT></DT>	<DD>Add the check box to the dialog. Set its properties as follows:	<P>	<DT></DT>	<DD>ID: IDC_CBUSETEXT	<P>	<DT></DT>	<DD>Caption: &amp;Use Entered Text	<P>	<DT></DT>	<DD>Using the Class Wizard, attach a variable to this control. Specify the variable	type as a boolean with the name m_bUseText.	<P>	<DT></DT>	<DD>Using the Class Wizard, add a function for the BN_CLICKED event message for the	check box. Edit the function, adding the following code:	<P></DL><PRE>void CDay7Dlg::OnCbusetext(){    // TODO: Add your control notification handler code here    ///////////////////////    // MY CODE STARTS HERE    ///////////////////////    // Update the variables with the dialog controls    UpdateData(TRUE);    // Using the font name for the font sample?    if (!m_bUseText)        // Using the font name        m_strDisplayText = m_strFontName;    else        // Using the entered text        m_strDisplayText = m_strSampText;    // Update the dialog    UpdateData(FALSE);    ///////////////////////    // MY CODE ENDS HERE    ///////////////////////</PRE><PRE>}</PRE><DL>	<DT></DT>	<DD>Modify the OnInitDialog function to initialize the check box as follows:	<P></DL><PRE>BOOL CDay7Dlg::OnInitDialog(){    CDialog::OnInitDialog();...    // TODO: Add extra initialization here    ///////////////////////    // MY CODE STARTS HERE    ///////////////////////    // Fill the font list box    FillFontList();    // Initialize the text to be entered    m_strSampText = &quot;Testing&quot;;    // Copy the text to the font sample area    m_strDisplayText = m_strSampText;    // Initialize the check box    m_bUseText = TRUE;    // Update the dialog    UpdateData(FALSE);    ///////////////////////    // MY CODE ENDS HERE    ///////////////////////    return TRUE;  // return TRUE  unless you set the focus                   // to a control</PRE><PRE>}</PRE><DL>	<DT></DT>	<DD>Modify the OnSelchangeLfonts function as follows:	<P></DL><PRE>void CDay7Dlg::OnSelchangeLfonts(){    // TODO: Add your control notification handler code here    ///////////////////////    // MY CODE STARTS HERE    ///////////////////////    // Update the variables with the dialog controls    UpdateData(TRUE);    // Using the font name for the font sample?    if (!m_bUseText)    {        // Copy the font name to the font sample        m_strDisplayText = m_strFontName;        // Update the dialog with the variables        UpdateData(FALSE);    }    // Set the font for the sample    SetMyFont();    ///////////////////////    // MY CODE ENDS HERE    ///////////////////////</PRE><PRE>}</PRE><DL>	<DT></DT>	<DD>Finally, modify the OnChangeEsamptext function as follows:	<P></DL><PRE>void CDay7Dlg::OnChangeEsamptext(){    // TODO: If this is a RICHEDIT control, the control will not    // send this notification unless you override the     // CDialog::OnInitialUpdate()    // function and call CRichEditCrtl().SetEventMask()    // with the EN_CHANGE flag ORed into the mask.    // TODO: Add your control notification handler code here    ///////////////////////    // MY CODE STARTS HERE    ///////////////////////    // Update the variables with the dialog controls    UpdateData(TRUE);    // Using the text for the font sample?    if (m_bUseText)    {        // Copy the current text to the font sample        m_strDisplayText = m_strSampText;        // Update the dialog with the variables        UpdateData(FALSE);    }    ///////////////////////    // MY CODE ENDS HERE    ///////////////////////</PRE><PRE>}</PRE><DL>	<DT></DT>	<DD><B>2. </B>Add a check box to display the font sample in italics, as in Figure	7.5.	<P>	<DT></DT>	<DD>Add the check box to the dialog. Set its properties as follows:	<P>	<DT></DT>	<DD>ID: IDC_CBITALIC	<P>	<DT></DT>	<DD>Caption: &amp;Italic	<P>	<DT></DT>	<DD>Using the Class Wizard, attach a variable to this control. Specify the variable	type as a boolean with the name m_bItalic.	<P>	<DT></DT>	<DD>Using the Class Wizard, add a function for the BN_CLICKED event message for the	check box. Edit the function, adding the following code:	<P></DL><PRE>void CDay7Dlg::OnCbitalic(){    // TODO: Add your control notification handler code here    ///////////////////////    // MY CODE STARTS HERE    ///////////////////////    // Update the variables with the dialog controls    UpdateData(TRUE);    // Set the font for the sample    SetMyFont();    ///////////////////////    // MY CODE ENDS HERE    ///////////////////////</PRE><PRE>}</PRE><DL>	<DT></DT>	<DD>Modify the SetMyFont function as in the following code:	<P></DL><PRE>void CDay7Dlg::SetMyFont(){    CRect rRect;        // The rectangle of the display area    int iHeight;        // The height of the display area    int iItalic = 0;    // Italicize the font?    // Has a font been selected?    if (m_strFontName != &quot;&quot;)    {        // Get the dimensions of the font sample display area        m_ctlDisplayText.GetWindowRect(&amp;rRect);        // Calculate the area height        iHeight = rRect.top - rRect.bottom;        // Make sure the height is positive        if (iHeight &lt; 0)            iHeight = 0 - iHeight;        // Should the font be italicized?        If (m_bItalic)            iItalic = 1;        // Create the font to be used        m_fSampFont.CreateFont((iHeight - 5), 0, 0, 0,                 FW_NORMAL, iItalic, 0, 0, DEFAULT_CHARSET,                 OUT_CHARACTER_PRECIS, CLIP_CHARACTER_PRECIS,                 DEFAULT_QUALITY, DEFAULT_PITCH |                FF_DONTCARE, m_strFontName);        // Set the font for the sample display area        m_ctlDisplayText.SetFont(&amp;m_fSampFont);    }</PRE><PRE>}</PRE><H2><A NAME="Heading22"></A>Day 8</H2><H3>Quiz</H3><DL>	<DT></DT>	<DD><B>1. </B>What are the three values that are combined to specify a color?	<P>	<DT></DT>	<DD>Red, green, and blue.	<P>	<DT></DT>	<DD><B>2. </B>What do you use to draw on windows without needing to know what graphics	card the user has?	<P>	<DT></DT>

⌨️ 快捷键说明

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