How to Update the List of Files in the Common Dialogs

Last reviewed: November 2, 1995
Article ID: Q109696
The information in this article applies to:
  • Microsoft Windows Software Development Kit (SDK) versions 3.1
  • Microsoft Win32 Application Programming Interface (API) included with:

        - Microsoft Windows NT version 3.5
    

SUMMARY

Sometimes it is necessary to update the list of files, without terminating the dialog box, when using the File Open or Save As common dialog box. This can be done by simulating a double-click on the list box of directories. Although the message can be posted from any application, a hook procedure should be used to post the message to the dialog box window.

MORE INFORMATION

The common dialog box functions that update the list of files and directories are internal to the common dialog boxes and are not accessible by applications using the common dialog box routines. The functions are invoked and the list boxes are updated only when the user double-clicks a list box.

Sample Code

The following code uses the Cancel button of the common dialog boxes to update the list boxes:

BOOL CALLBACK __export FileOpenHook (HWND hDlg, UINT message,

                         WPARAM wParam, LPARAM lParam)
{
   switch (message)
   {
      case WM_COMMAND:
         switch(wParam)
         {
         // This simulates a double-click on the list of directories,
         // effectively forcing the common dialogs to re-read the current
         // directory of files and to refresh the list of files.
            case IDCANCEL :
               PostMessage( hDlg, WM_COMMAND, lst2,
                            MAKELPARAM(GetDlgItem(hDlg, lst2), LBN_DBLCLK);
               return TRUE;
         }
      break;
   }
   return FALSE;
}

If the application targets Win32, the notification message to the list box is sent differently; here is the PostMessage for Win32 applications:

PostMessage (hDlg, WM_COMMAND, MAKEWPARAM (lst2,LBN_DBLCLK),

          (LPARAM)GetDlgItem (hDlg, lst2));

Applications using the IDs of the common dialog box's controls must include the DLGS.H file.

The templates for the common dialog boxes are in the \SAMPLES\COMMDLG directory or in the \INCLUDE directory of the Windows SDK installation.


Additional reference words: 3.10 3.50 refresh redraw
KBCategory: kbui
KBSubcategory: UsrCmnDlg


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: November 2, 1995
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.