Leaked source code of windows server 2003
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.

162 lines
4.0 KiB

  1. #include <windows.h>
  2. #include <commdlg.h>
  3. #include <dlgs.h>
  4. #include "common.h"
  5. #ifndef DBCS
  6. #define AnsiNext(x) ((x)+1)
  7. #endif
  8. #define MYMAXPATH 255
  9. extern HANDLE hInstance;
  10. extern HWND hWndHelp;
  11. extern WORD wHelpId;
  12. static VOID NEAR PASCAL ReplaceChar(LPSTR lpStr, char cOld, char cNew)
  13. {
  14. for( ; *lpStr; lpStr=AnsiNext(lpStr))
  15. if(*lpStr == cOld)
  16. *lpStr = cNew;
  17. }
  18. int FAR PASCAL MyOpenDlgProc(HWND hWnd, WORD message, WORD wParam, DWORD lParam)
  19. {
  20. switch(message) {
  21. case WM_ACTIVATE:
  22. if(wParam)
  23. hWndHelp = hWnd;
  24. return(FALSE);
  25. case WM_INITDIALOG:
  26. return(TRUE);
  27. case WM_COMMAND:
  28. switch(wParam) {
  29. case ID_HELP:
  30. if(GetParent(LOWORD(lParam)) != hWnd)
  31. break;
  32. case psh15:
  33. MyHelp(hWnd, HELP_CONTEXT, wHelpId);
  34. break;
  35. }
  36. break;
  37. }
  38. return(FALSE);
  39. }
  40. HANDLE NEAR PASCAL MyLoadGlobalString(HANDLE wString, WORD *wSize)
  41. {
  42. HANDLE hlString, hString;
  43. if(!(hlString=MyLoadString(wString, wSize, LMEM_MOVEABLE)))
  44. goto Error1;
  45. hString = StringToHandle(LocalLock(hlString));
  46. LocalUnlock(hlString);
  47. LocalFree(hlString);
  48. Error1:
  49. return(hString);
  50. }
  51. BOOL NEAR PASCAL DoFileOpenDlg(HWND hWnd, WORD wTitle, WORD wFilter,
  52. WORD wCustomFilter, HANDLE *hCustomFilter, HANDLE *hFileName, BOOL bOpen)
  53. {
  54. HANDLE hOfn, hFilter, hTitle;
  55. LPOPENFILENAME lpOfn;
  56. LPSTR lpFileName, lpFilter;
  57. BOOL result = FALSE;
  58. #ifdef USECUSTOMFILTER
  59. HANDLE hpFilter;
  60. LPSTR lpCustomFilter;
  61. WORD wSize;
  62. #endif
  63. if(!(hOfn=GlobalAlloc(GMEM_FIXED, sizeof(OPENFILENAME))))
  64. goto Error1;
  65. if(!(lpOfn=(LPOPENFILENAME)GlobalLock(hOfn)))
  66. goto Error2;
  67. if(!(hFilter=MyLoadGlobalString(wFilter, NULL)))
  68. goto Error3;
  69. lpFilter = GlobalLock(hFilter);
  70. ReplaceChar(AnsiNext(lpFilter), *lpFilter, '\0');
  71. if(!(hTitle=MyLoadGlobalString(wTitle, NULL)))
  72. goto Error4;
  73. if(!(*hFileName=GlobalAlloc(GMEM_MOVEABLE, MYMAXPATH)))
  74. goto Error5;
  75. if(!(lpFileName=GlobalLock(*hFileName)))
  76. goto Error6;
  77. *lpFileName = '\0';
  78. #ifdef USECUSTOMFILTER
  79. if(*hCustomFilter) {
  80. lpCustomFilter = GlobalLock(*hCustomFilter);
  81. } else {
  82. if(!(*hCustomFilter=MyLoadGlobalString(wCustomFilter, &wSize)))
  83. goto Error7;
  84. if(hpFilter=GlobalReAlloc(*hCustomFilter, 2*wSize, GMEM_MOVEABLE))
  85. *hCustomFilter = hpFilter;
  86. lpCustomFilter = GlobalLock(*hCustomFilter);
  87. ReplaceChar(AnsiNext(lpCustomFilter), *lpCustomFilter, '\0');
  88. }
  89. #endif
  90. lpOfn->lStructSize = sizeof(OPENFILENAME);
  91. lpOfn->hwndOwner = hWnd;
  92. lpOfn->hInstance = hInstance;
  93. lpOfn->lpstrFilter = AnsiNext(lpFilter);
  94. #ifdef USECUSTOMFILTER
  95. lpOfn->lpstrCustomFilter = AnsiNext(lpCustomFilter);
  96. lpOfn->nMaxCustFilter = GlobalSize(*hCustomFilter) - 1;
  97. #else
  98. lpOfn->lpstrCustomFilter = NULL;
  99. lpOfn->nMaxCustFilter = 0;
  100. #endif
  101. lpOfn->nFilterIndex = 0;
  102. lpOfn->lpstrFile = lpFileName;
  103. lpOfn->nMaxFile = MYMAXPATH;
  104. lpOfn->lpstrFileTitle = NULL;
  105. lpOfn->nMaxFileTitle = 0;
  106. lpOfn->lpstrInitialDir = NULL;
  107. lpOfn->lpstrTitle = GlobalLock(hTitle);
  108. lpOfn->Flags = OFN_HIDEREADONLY
  109. #ifndef NOHELP
  110. | OFN_SHOWHELP
  111. #endif
  112. | OFN_OVERWRITEPROMPT | OFN_ENABLEHOOK;
  113. lpOfn->lpstrDefExt = NULL;
  114. lpOfn->lCustData = 0;
  115. lpOfn->lpfnHook = (UINT (CALLBACK *)(HWND, UINT, WPARAM, LPARAM))MakeProcInstance(MyOpenDlgProc, hInstance);
  116. lpOfn->lpTemplateName = NULL;
  117. result = bOpen ? GetOpenFileName(lpOfn) : GetSaveFileName(lpOfn);
  118. if(lpOfn->lpfnHook)
  119. FreeProcInstance(lpOfn->lpfnHook);
  120. GlobalUnlock(hTitle);
  121. #ifdef USECUSTOMFILTER
  122. GlobalUnlock(*hCustomFilter);
  123. Error7:
  124. #endif
  125. GlobalUnlock(*hFileName);
  126. Error6:
  127. if(!result)
  128. GlobalFree(*hFileName);
  129. Error5:
  130. GlobalFree(hTitle);
  131. Error4:
  132. GlobalUnlock(hFilter);
  133. GlobalFree(hFilter);
  134. Error3:
  135. GlobalUnlock(hOfn);
  136. Error2:
  137. GlobalFree(hOfn);
  138. Error1:
  139. return(result);
  140. }