📄 vcg11.htm
字号:
<B> "load a specified string.");</B>
<B> break;</B>
<B> case CDERR_LOCKRESFAILURE :</B>
<B> AfxMessageBox("The common dialog box procedure failed to "</B>
<B> "lock a specified resource.");</B>
<B> break;</B>
<B> case CDERR_MEMALLOCFAILURE :</B>
<B> AfxMessageBox("The common dialog box procedure was unable "</B>
<B> "to allocate memory for internal ");</B>
<B> break;</B>
<B> case CDERR_MEMLOCKFAILURE :</B>
<B> AfxMessageBox("The common dialog box procedure was unable "</B>
<B> "to lock the memory associated");</B>
<B> break;</B>
<B> case CDERR_NOHINSTANCE :</B>
<B> AfxMessageBox("The ENABLETEMPLATE flag was specified in "</B>
<B> "the Flags member of a structure");</B>
<B> break;</B>
<B> case CDERR_NOHOOK :</B>
<B> AfxMessageBox("The ENABLEHOOK flag was specified in the "</B>
<B> "Flags member of a structure");</B>
<B> break;</B>
<B> case CDERR_NOTEMPLATE :</B>
<B> AfxMessageBox("The ENABLETEMPLATE flag was specified in "</B>
<B> "the Flags member of a structure ");</B>
<B> break;</B>
<B> case CDERR_REGISTERMSGFAIL :</B>
<B> AfxMessageBox("The RegisterWindowMessage function "</B>
<B> "returned an error code when it was called");</B>
<B> break;</B>
<B> case CDERR_STRUCTSIZE :</B>
<B> AfxMessageBox("The lStructSize member of a structure "</B>
<B> "for the corresponding common dialog box");</B>
<B> break;</B>
<B> case CFERR_CHOOSEFONTCODES :</B>
<B> AfxMessageBox("Error codes for the Font common dialog "</B>
<B> "box. These errors are in the range 0");</B>
<B> break;</B>
<B> case CFERR_MAXLESSTHANMIN :</B>
<B> AfxMessageBox("The size specified in the nSizeMax member "</B>
<B> "of the CHOOSEFONT structure is wrong");</B>
<B> break;</B>
<B> case CFERR_NOFONTS :</B>
<B> AfxMessageBox("No fonts exist.");</B>
<B> break;</B>
<B> case FNERR_BUFFERTOOSMALL :</B>
<B> AfxMessageBox("The buffer for a filename is too small.");</B>
<B> break;</B>
<B> case FNERR_FILENAMECODES :</B>
<B> AfxMessageBox("Error codes for the Open and Save As "</B>
<B> "common dialog boxes.");</B>
<B> break;</B>
<B> case FNERR_INVALIDFILENAME :</B>
<B> AfxMessageBox("A filename is invalid.");</B>
<B> break;</B>
<B> case FNERR_SUBCLASSFAILURE :</B>
<B> AfxMessageBox("An attempt to subclass a list box failed "</B>
<B> "because insufficient memory was available");</B>
<B> break;</B>
<B> case FRERR_BUFFERLENGTHZERO :</B>
<B> AfxMessageBox("A member in a structure for the "</B>
<B> "corresponding common dialog box points to a null buffer");</B>
<B> break;</B>
<B> case FRERR_FINDREPLACECODES :</B>
<B> AfxMessageBox("Error codes for the Find and Replace "</B>
<B> "common dialog boxes. ");</B>
<B> break;</B>
<B> case PDERR_CREATEICFAILURE :</B>
<B> AfxMessageBox("The PrintDlg function failed when it "</B>
<B> "attempted to create an information context");</B>
<B> break;</B>
<B> case PDERR_DEFAULTDIFFERENT :</B>
<B> AfxMessageBox("An application called the PrintDlg "</B>
<B> "function with the DN_DEFAULTPRN flag specified");</B>
<B> break;</B>
<B> case PDERR_DNDMMISMATCH :</B>
<B> AfxMessageBox("The data in the DEVMODE and DEVNAMES "</B>
<B> "structures describes two different priters");</B>
<B> break;</B>
<B> case PDERR_GETDEVMODEFAIL :</B>
<B> AfxMessageBox("The printer driver failed to initialize "</B>
<B> "a DEVMODE structure. ");</B>
<B> break;</B>
<B> case PDERR_INITFAILURE :</B>
<B> AfxMessageBox("The PrintDlg function failed during "</B>
<B> "initialization");</B>
<B> break;</B>
<B> case PDERR_LOADDRVFAILURE :</B>
<B> AfxMessageBox("The PrintDlg function failed to load "</B>
<B> "the device driver for the specified printer");</B>
<B> break;</B>
<B> case PDERR_NODEFAULTPRN :</B>
<B> AfxMessageBox("A default printer does not exist.");</B>
<B> break;</B>
<B> case PDERR_NODEVICES :</B>
<B> AfxMessageBox("No printer drivers were found.");</B>
<B> break;</B>
<B> case PDERR_PARSEFAILURE :</B>
<B> AfxMessageBox("The PrintDlg function failed to parse "</B>
<B> "the strings in the [devices] section ");</B>
<B> break;</B>
<B> case PDERR_PRINTERCODES :</B>
<B> AfxMessageBox("Error codes for the Print common dialog box. ");</B>
<B> break;</B>
<B> case PDERR_PRINTERNOTFOUND :</B>
<B> AfxMessageBox("The [devices] section of the WIN.INI file "</B>
<B> "did not contain an entry...");</B>
<B> break;</B>
<B> case PDERR_RETDEFFAILURE :</B>
<B> AfxMessageBox("The PD_RETURNDEFAULT flag was specified in "</B>
<B> "the Flags member of the PRINTDLG.");</B>
<B> break;</B>
<B> case PDERR_SETUPFAILURE :</B>
<B> AfxMessageBox("The PrintDlg function failed to load the "</B>
<B> "required resources.");</B>
<B> break;</B>
<B> default :</B>
<B> AfxMessageBox("default: the call must have worked!");</B>
<B> break;</B>
<B> }</B>
<B> }</B>
<B> return(nReturn);</B>
<B>}</B>
<B>DWORD CALLBACK OpenCallback</B>
<B> (DWORD dwCookie, LPBYTE pbBuff, LONG cb, LONG *pcb)</B>
<B>{</B>
<B>// Read as much data as allowed in the cb variable</B>
<B> *pcb = _lread((HFILE)dwCookie, pbBuff, cb);</B>
<B> if(*pcb < cb)</B>
<B> {// If done, say:</B>
<B> return (0); // All done!</B>
<B> }</B>
<B> return (unsigned long)*pcb; // Otherwise, say: There is more to read!</B>
<B>}</B></FONT></PRE>
<P>Of course, this sample program doesn't do much. A full implementation of a RichText control requires a full user interface (how else can the user set how the text is to look?) and support for input, output, and printing as applicable.
<BR>
<P>A classic example of what a RichText control can really do is the Windows 95 WordPad application. WordPad was written as a shell around the RichText control and is actually a rather simple program. The source for WordPad can be found in a number of places, including the Visual C++ 4 directory \MSDEV\SAMPLES\MFC\OLE\WORDPAD.
<BR>
<BLOCKQUOTE>
<BLOCKQUOTE>
<HR ALIGN=CENTER>
<BR>
<NOTE><B>NOTE</B>
<BR>
<BR>The WordPad sample program is an excellent example of the RichText control's implementation and of issues that must be addressed when you're creating an OLE application.</NOTE>
<BR>
<HR ALIGN=CENTER>
</BLOCKQUOTE></BLOCKQUOTE>
<BR>
<A NAME="E69E179"></A>
<H4 ALIGN=CENTER>
<CENTER>
<FONT SIZE=4 COLOR="#FF0000"><B>The Toolbar Control</B></FONT></CENTER></H4>
<BR>
<P>When you create an AppWizard application, you can specify that a toolbar be included. This stock toolbar is implemented with the CToolBar class and will be located in the main frame window of the application.
<BR>
<P>You can add a toolbar to any other window (including the frame window) by using the CToolBarCtrl class. A toolbar created using CToolBarCtrl will offer some additional functionality (such as more configurability) that the CToolBar class toolbars don't offer. The standard CToolBar toolbar in the sample application's main frame window is shown in Figure 11.5.
<BR>
<P><B><A HREF="11vcg05.gif" tppabs="http://202.113.16.101/%7eeb%7e/Database%20Developer's%20Guide%20with%20Visual%20C++%204,%20Second%20Edition/11vcg05.gif">Figure 11.5. A CToolBar-created toolbar in the application's main frame window.</A></B>
<BR>
<P>Figure 11.6 shows a dialog box that has a toolbar added to it. I gave this toolbar large buttons in order to show you how to implement a nonstandard-size toolbar button.
<BR>
<P><B><A HREF="11vcg06.gif" tppabs="http://202.113.16.101/%7eeb%7e/Database%20Developer's%20Guide%20with%20Visual%20C++%204,%20Second%20Edition/11vcg06.gif">Figure 11.6. A CToolBarCtrl-created toolbar in a dialog box.</A></B>
<BR>
<P>Creating a toolbar is simple. In the class header for the parent window, create a CToolBarCtrl object, as shown in Listing 11.5. Lines that were added to the original AppWizard shell appear in bold. Note that you must create an array of TBBUTTON objects to hold the toolbar button information. This array is then passed to your CToolBarCtrl object when the toolbar is created.
<BR>
<P>
<FONT COLOR="#000080"><B>Listing 11.5. Creating a CToolBarCtrl object.</B></FONT>
<BR>
<PRE>
<FONT COLOR="#000080">// toolbar.h : header file
//
/////////////////////////////////////////////////////////////////////////////
// Toolbar dialog
class Toolbar : public CDialog
{
// Construction
public:
Toolbar(CWnd* pParent = NULL); // Standard constructor
<B> TBBUTTON m_Buttons[5];</B>
<B> CToolBarCtrl m_ToolBar;</B>
// Dialog data
//{{AFX_DATA(Toolbar)
enum { IDD = IDD_TOOLBAR };
// NOTE: ClassWizard will add data members here
//}}AFX_DATA
// Overrides
// ClassWizard-generated virtual function overrides
//{{AFX_VIRTUAL(Toolbar)
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
//}}AFX_VIRTUAL
// Implementation
protected:
// Generated message map functions
//{{AFX_MSG(Toolbar)
virtual BOOL OnInitDialog();
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};</FONT></PRE>
<P>Listing 11.6 shows the actual code that displays the status bar and places some text in the status bar's output area. Lines that were added to the original AppWizard shell appear in bold. In most applications, the placing of text in the status bar's output area will be done by using a message handler.
<BR>
<P>
<FONT COLOR="#000080"><B>Listing 11.6. The CStatusBarCtrl initialization code.</B></FONT>
<BR>
<PRE>
<FONT COLOR="#000080">// toolbar.cpp : implementation file
//
#include "stdafx.h"
#include "Win32CC.h"
#include "toolbar.h"
#ifdef _DEBUG
#undef THIS_FILE
static char BASED_CODE THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// Toolbar dialog
Toolbar::Toolbar(CWnd* pParent /*=NULL*/)
: CDialog(Toolbar::IDD, pParent)
{
//{{AFX_DATA_INIT(Toolbar)
// NOTE: ClassWizard will add member initialization here
//}}AFX_DATA_INIT
}
void Toolbar::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(Toolbar)
// NOTE: ClassWizard will add DDX and DDV calls here
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(Toolbar, CDialog)
//{{AFX_MSG_MAP(Toolbar)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// Toolbar message handlers
BOOL Toolbar::OnInitDialog()
{
CDialog::OnInitDialog();
// TODO: Add extra initialization here
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -