Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

148 lines
3.0 KiB

  1. /*++
  2. Copyright (c) 1995 Microsoft Corporation
  3. Module Name:
  4. browse.c
  5. Abstract:
  6. This file implements the functions that make use of the common
  7. file _open dialogs for browsing for files/directories.
  8. Author:
  9. Wesley Witt (wesw) 20-June-1995
  10. Environment:
  11. User Mode
  12. --*/
  13. #include <windows.h>
  14. #include <commdlg.h>
  15. #include <stdio.h>
  16. #include <stdlib.h>
  17. #include <tchar.h>
  18. UINT APIENTRY
  19. BrowseHookProc(
  20. HWND hwnd,
  21. UINT message,
  22. WPARAM wParam,
  23. LPARAM lParam
  24. )
  25. /*++
  26. Routine Description:
  27. Hook procedure to cause the window to be the foreground
  28. window and centered.
  29. Arguments:
  30. hwnd - window handle to the dialog box
  31. message - message number
  32. wParam - first message parameter
  33. lParam - second message parameter
  34. Return Value:
  35. TRUE - did not process the message
  36. FALSE - did process the message
  37. --*/
  38. {
  39. if (message == WM_INITDIALOG) {
  40. SetForegroundWindow( hwnd );
  41. // CenterWindow( hwnd, hwndFrame );
  42. }
  43. return FALSE;
  44. }
  45. BOOL
  46. BrowseForFileName(
  47. HWND hwnd,
  48. LPWSTR FileName,
  49. LPWSTR Extension,
  50. LPWSTR FileDesc,
  51. LPWSTR Dir
  52. )
  53. /*++
  54. Routine Description:
  55. Presents a common file open dialog for the purpose of selecting a
  56. file name;
  57. Arguments:
  58. FileName - name of the selected file
  59. Return Value:
  60. TRUE - got a good wave file name (user pressed the OK button)
  61. FALSE - got nothing (user pressed the CANCEL button)
  62. the FileName is changed to have the selected file name.
  63. --*/
  64. {
  65. OPENFILENAME of;
  66. WCHAR ftitle[MAX_PATH];
  67. WCHAR title[MAX_PATH];
  68. WCHAR fname[MAX_PATH];
  69. WCHAR filter[1024];
  70. LPWSTR s;
  71. ftitle[0] = 0;
  72. swprintf( fname, L"*.%s", Extension );
  73. ZeroMemory( filter, sizeof(filter) );
  74. s = filter;
  75. s += 1 + swprintf( s, L"%s(*.%s)", FileDesc, Extension );
  76. s += 1 + swprintf( s, L"*.%s", Extension );
  77. s += 1 + swprintf( s, L"All Files(*.*)" );
  78. s += 1 + swprintf( s, L"*.*" );
  79. wcscpy( title, L"File Selection" );
  80. of.lStructSize = sizeof( OPENFILENAME );
  81. of.hwndOwner = hwnd;
  82. of.hInstance = GetModuleHandle( NULL );
  83. of.lpstrFilter = filter;
  84. of.lpstrCustomFilter = NULL;
  85. of.nMaxCustFilter = 0;
  86. of.nFilterIndex = 1;
  87. of.lpstrFile = fname;
  88. of.nMaxFile = MAX_PATH;
  89. of.lpstrFileTitle = ftitle;
  90. of.nMaxFileTitle = MAX_PATH;
  91. of.lpstrInitialDir = Dir;
  92. of.lpstrTitle = title;
  93. of.Flags = OFN_ENABLEHOOK | OFN_EXPLORER | OFN_HIDEREADONLY | OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST;
  94. of.nFileOffset = 0;
  95. of.nFileExtension = 0;
  96. of.lpstrDefExt = Extension;
  97. of.lCustData = 0;
  98. of.lpfnHook = BrowseHookProc;
  99. of.lpTemplateName = NULL;
  100. if (GetOpenFileName( &of )) {
  101. wcscpy( FileName, fname );
  102. return TRUE;
  103. }
  104. return FALSE;
  105. }