Customizing the FileOpen Common Dialog in Windows 95

Last reviewed: January 21, 1997
Article ID: Q125706
The information in this article applies to:
  • Microsoft Win32 Application Programming Interface (API) included with:

        - Microsoft Windows 95 version 4.0
    

SUMMARY

In Windows version 3.x, customizing the FileOpen common dialog meant providing a special hook function, and in most cases, a custom dialog box template. This custom dialog box template is created by modifying the standard FileOpen dialog box template used by COMMDLG that was made available as part of the Windows version 3.1 SDK.

In Windows 95, the new dialog box templates will no longer be made available for modification. Instead, an application should provide a dialog template that includes only the items to be added to the standard dialog box. COMMDLG will then create this dialog as a child of the standard dialog box. Because it is a child, it must have the WS_CHILD style set.

Note that the Windows version 3.1 method of customizing common dialogs by modifying the dialog templates will still work for 16-bit applications.

MORE INFORMATION

Follow these steps to customize the FileOpen common dialog in Windows 95:

  1. Create a dialog box template that will have all the controls you want to add to the FileOpen common dialog. Be sure to specify the styles:

          WS_CHILD | WS_VISIBLE | DS_3DLOOK | DS_CONTROL | WS_CLIPSIBLINGS
    

    WS_CHILD is specified because without it, the call to GetOpenFileName() fails. COMMDLG creates the dialog specified as a child of the standard FileOpen common dialog box. As a result, the hDlg passed to the application's hook function will be the child of the standard FileOpen dialog box. To get a handle to the standard dialog box from the hook function, call GetParent (hDlg).

    WS_CLIPSIBLINGS is specified so that overlapping controls paint properly.

    DS_3DLOOK is a new style for Windows 95 that gives the dialog box a non-bold font, and gives all the controls the 3D look.

    DS_CONTROL is another new style that among other things allows the user to tab between the controls of a dialog box to the controls of a child dialog box. As mentioned above, the dialog template will be created as a child of the standard FileOpen common dialog box, so specifying this style will allow tabbing from the application-defined controls to the standard controls.

  2. Include a static control in your dialog template, specifying a control ID of stc32. This control will serve as a place holder for the standard controls. Be sure to use the #include directive to include DLGS.H in your .RC file through the Read-Only Symbol Directives, as stc32 is defined in <dlgs>.

    NOTE: Do not type in the ID name. Rather, select it from the list of IDs in the dropdown combo box. Doing so otherwise may result in warning messages on stc32 redefinition (It will still work). If the stc32 symbol does not appear in the combo box, the resource editor needs to be reloaded. This can be done by opening the .rc file as a text, and then closing the text file and opening the resource view again.

    If there is no stc32 control specified, COMMDLG places all the new controls defined in your dialog template below the standard controls and looks at the size of the static control to attempt to fit all the standard controls in it. If it is not big enough, COMMDLG resizes this stc32 control to make room for the standard controls, and then repositions the new controls with respect to the resized stc32 control.

  3. Initialize the Flags member of the OPENFILENAME structure to include

        the following flags:
    

          OFN_EXPLORER | OFN_ENABLETEMPLATE | OFN_ENABLEHOOK
    

    OFN_ENABLETEMPLATEHANDLE may be used instead of OFN_ENABLETEMPLATE if you want to specify a handle to a memory block containing a preloaded dialog box template.

  4. If the OFN_ENABLETEMPLATE flag is set, specify the name of your application-defined template in the lpTemplateName field of the OPENFILENAME structure, and specify your application's instance handle in the hInstance field.

    If the OFN_ENABLETEMPLATEHANDLE flag is set, specify the handle to the memory block containing your dialog box template in the hInstance field of the OPENFILENAME structure.

  5. Specify the address of a dialog box procedure associated with your dialog box in the lpfnHook field of the OPENFILENAME structure.

  6. Process appropriate notifications and messages as a result of adding new controls.

REFERENCES

Much of the information contained in this article is derived from the MSDN Technical Article entitled "Using the Common Dialogs Under Windows 95." Please refer to that article for more information.


KBCategory: kbui kbhowto
KBSubcategory: UsrCmnDlg
Additional reference words: 4.00



THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: January 21, 1997
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.