Microsoft KB Archive/99097

= How to customize common dialog box parameter blocks by using Visual C++ =

Article ID: 99097

Article Last Modified on 1/5/2006

-

APPLIES TO

 Microsoft Foundation Class Library 4.2, when used with:  Microsoft C/C++ Professional Development System 7.0

 Microsoft Visual C++ 1.0 Professional Edition

 Microsoft Visual C++ 1.5 Professional Edition

 Microsoft Visual C++ 1.51</li></ul>

 Microsoft Visual C++ 1.52 Professional Edition</li></ul>

 Microsoft Visual C++ 2.0 Professional Edition</li></ul>

 Microsoft Visual C++ 2.1</li></ul>

 Microsoft Visual C++ 4.0 Standard Edition</li></ul>

 Microsoft Visual C++ 4.1 Subscription</li></ul>

 Microsoft Visual C++ 4.2 Professional Edition</li></ul>

 Microsoft Visual C++ 5.0 Standard Edition</li></ul>

 Microsoft Visual C++ .NET 2003 Standard Edition</li></ul>

<ul> <li>Microsoft Visual C++ .NET 2002 Standard Edition</li></ul>

<ul> <li>Microsoft Visual C++ 2005 Express Edition</li></ul> </li></ul>

-

<div class="notice_section">

This article was previously published under Q99097

<div class="idea_section">

Note Microsoft Visual C++ .NET (2002) supports both the managed code model that is provided by the Microsoft .NET Framework and the unmanaged native Microsoft Windows code model. The information in this article applies only to unmanaged Visual C++ code.

Note Microsoft Visual C++ 2005 supports both the managed code model that is provided by the Microsoft .NET Framework and the unmanaged native Microsoft Windows code model.

<div class="summary_section">

SUMMARY
The Microsoft Foundation Classes (MFC) Standard Dialog Classes provide convenient C++ wrappers for the Microsoft Windows Common Dialog Boxes dynamic-link library (DLL), COMMDLG.DLL. To customize one of these classes, you may need to modify some of the default parameter block members. The wrapper functions use the same parameter blocks as the corresponding common dialog functions because, ultimately, the code calls the Windows functions. <pre class="fixed_text">  Microsoft Foundation Classes  Windows Common Dialog   Parameter Block ---  CFileDialog          GetOpenFileName and     OPENFILENAME GetSaveFileName CFontDialog         ChooseFont              CHOOSEFONT CColorDialog        ChooseColor             CHOOSECOLOR CPrintDialog        PrintDlg                PRINTDLG CFindReplaceDialog  FindText and            FINDREPLACE ReplaceText For Microsoft Foundation Classes version 1.0, distributed with Microsoft C/C++ version 7.0, Technical Note #13 provides additional information about these classes and how to use them. Technical Note #13 is in the TN013.TXT file in the MFC\DOC directory (by default, C:\C700\MFC\DOC). For Microsoft Foundation Classes library versions 2.x, 3.x, and 4.x, each of these functions is listed in the online documentation and in the &quot;Class Library Reference&quot; manual by its class name.

Even though the parameter block defaults that the Microsoft Foundation Classes library provides are generally adequate, there are times it may be necessary to customize a dialog box. For example, it may be helpful to specify the OFN_ALLOWMULTISELECT flag with the CFileDialog to allow the user to select more than one file in the GetOpenFileName dialog box.

If you add a flag, however, you must be careful to provide any additional information as appropriate. For example, CFileDialog provides a default buffer m_szFileName that is _MAX_PATH characters in length. If you allow the user to select more than one file, this buffer capacity can be exhausted quickly.

Even though the CFileDialog class was designed with a buffer to support only one file, it is an easy matter to provide your own buffer by setting the m_ofn.lpstrFile and m_ofn.nMax members of the OPENFILENAME parameter block yourself after constructing your CFileDialog, but before calling DoModal.

The text below demonstrates this method of replacing the default CFileDialog buffer. However, similar techniques apply to any of the standard dialog box classes. In general, when you change any of the default flags, you should examine the Microsoft Foundation Classes library source code to determine the effects of the change, if any, and to take appropriate action.

<div class="moreinformation_section">

MORE INFORMATION
The following code fragment demonstrates using CFileDialog to select multiple files by adding the OFN_ALLOWMULTISELECT flag and using an application-supplied buffer:
 * 1) include <afxdlgs.h>

char bigBuff[2048] = &quot;&quot;; // maximum common dialog buffer size char szFilter[] = &quot;All Files (*.*)|*.*|Text Files (*.txt)|*.txt||&quot;; CFileDialog dlg(TRUE, NULL, NULL,     OFN_HIDEREADONLY | OFN_ALLOWMULTISELECT, szFilter);

// Modify OPENFILENAME members directly to point to bigBuff dlg.m_ofn.lpstrFile = bigBuff; dlg.m_ofn.nMaxFile = sizeof(bigBuff);

dlg.DoModal; There are a number of circumstances in which it is desirable to add a custom template and/or a hook function to the Windows common dialog boxes. To do so, modify fields in the appropriate common dialog box parameter block. When the application uses the Microsoft Foundation Classes library, modify these fields after creating the dialog object but before calling DoModal, as illustrated above.

For more information on using a custom template or a hook function with one of the common dialog boxes, please query in the Microsoft Knowledge Base on the following words:

steps add hook function

steps add custom template

Keywords: kbhowto kbuidesign kbcmndlg kbdlg KB99097

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.