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.

247 lines
4.7 KiB

  1. /*++
  2. Copyright (c) 1990-1995 Microsoft Corporation
  3. All rights reserved
  4. Module Name:
  5. pfdlg.c
  6. Abstract:
  7. Author:
  8. Environment:
  9. User Mode -Win32
  10. Revision History:
  11. --*/
  12. #include "precomp.h"
  13. #pragma hdrstop
  14. #include "client.h"
  15. #include "pfdlg.h"
  16. static const DWORD g_aHelpIDs[]=
  17. {
  18. IDD_PF_EF_OUTPUTFILENAME, 8810218, // Print to File: "" (Edit)
  19. 0, 0
  20. };
  21. /*
  22. *
  23. */
  24. INT_PTR CALLBACK
  25. PrintToFileDlg(
  26. HWND hwnd,
  27. UINT msg,
  28. WPARAM wparam,
  29. LPARAM lparam
  30. )
  31. {
  32. switch(msg)
  33. {
  34. case WM_INITDIALOG:
  35. return PrintToFileInitDialog(hwnd, (LPWSTR *)lparam);
  36. case WM_COMMAND:
  37. switch (LOWORD(wparam))
  38. {
  39. case IDOK:
  40. return PrintToFileCommandOK(hwnd);
  41. case IDCANCEL:
  42. return PrintToFileCommandCancel(hwnd);
  43. }
  44. break;
  45. case WM_HELP:
  46. case WM_CONTEXTMENU:
  47. return PrintToFileHelp(hwnd, msg, wparam, lparam);
  48. break;
  49. }
  50. return FALSE;
  51. }
  52. /*
  53. *
  54. */
  55. BOOL
  56. PrintToFileInitDialog(
  57. HWND hwnd,
  58. LPWSTR *ppFileName
  59. )
  60. {
  61. BringWindowToTop( hwnd );
  62. SetFocus(hwnd);
  63. SetWindowLongPtr( hwnd, GWLP_USERDATA, (LONG_PTR)ppFileName );
  64. SendDlgItemMessage( hwnd, IDD_PF_EF_OUTPUTFILENAME, EM_LIMITTEXT, MAX_PATH-2, 0);
  65. return TRUE;
  66. }
  67. /*
  68. *
  69. */
  70. BOOL
  71. PrintToFileCommandOK(
  72. HWND hwnd
  73. )
  74. {
  75. WCHAR pFileName[MAX_PATH];
  76. WIN32_FIND_DATA FindData;
  77. HANDLE hFile;
  78. HANDLE hFind;
  79. LPWSTR *ppFileName;
  80. ppFileName = (LPWSTR *)GetWindowLongPtr( hwnd, GWLP_USERDATA );
  81. GetDlgItemText( hwnd, IDD_PF_EF_OUTPUTFILENAME,
  82. pFileName, MAX_PATH );
  83. hFind = FindFirstFile( pFileName, &FindData );
  84. //
  85. // If the file already exists, get the user to verify
  86. // before we overwrite it:
  87. //
  88. if( hFind != INVALID_HANDLE_VALUE )
  89. {
  90. FindClose( hFind );
  91. if( Message( hwnd, MB_OKCANCEL | MB_ICONEXCLAMATION, IDS_LOCALMONITOR,
  92. IDS_OVERWRITE_EXISTING_FILE )
  93. != IDOK )
  94. {
  95. return TRUE;
  96. }
  97. }
  98. hFile = CreateFile( pFileName, GENERIC_WRITE, FILE_SHARE_READ, NULL,
  99. OPEN_ALWAYS,
  100. FILE_ATTRIBUTE_NORMAL | FILE_FLAG_SEQUENTIAL_SCAN,
  101. NULL );
  102. if( hFile != INVALID_HANDLE_VALUE )
  103. {
  104. LPWSTR pTempFileName;
  105. WCHAR szCurrentDir[MAX_PATH];
  106. WCHAR szQualifiedPath[MAX_PATH];
  107. LPWSTR pszIgnore;
  108. DWORD cchLen;
  109. CloseHandle(hFile);
  110. if (!GetCurrentDirectory(sizeof(szCurrentDir)/sizeof(szCurrentDir[0]),
  111. szCurrentDir))
  112. goto Fail;
  113. cchLen = SearchPath(szCurrentDir,
  114. pFileName,
  115. NULL,
  116. sizeof(szQualifiedPath)/sizeof(szQualifiedPath[0]),
  117. szQualifiedPath,
  118. &pszIgnore);
  119. if (!cchLen)
  120. goto Fail;
  121. pTempFileName = LocalAlloc(LMEM_FIXED,
  122. (cchLen + 1) * sizeof(szQualifiedPath[0]));
  123. if (!pTempFileName)
  124. goto Fail;
  125. StringCchCopy(pTempFileName, cchLen+1, szQualifiedPath);
  126. *ppFileName = pTempFileName;
  127. EndDialog( hwnd, TRUE );
  128. } else {
  129. Fail:
  130. ReportFailure( hwnd, IDS_LOCALMONITOR, IDS_COULD_NOT_OPEN_FILE );
  131. }
  132. return TRUE;
  133. }
  134. BOOL
  135. PrintToFileCommandCancel(
  136. HWND hwnd
  137. )
  138. {
  139. EndDialog(hwnd, FALSE);
  140. return TRUE;
  141. }
  142. /*++
  143. Routine Name:
  144. PrintToFileHelp
  145. Routine Description:
  146. Handles context sensitive help.
  147. Arguments:
  148. UINT uMsg,
  149. HWND hDlg,
  150. WPARAM wParam,
  151. LPARAM lParam
  152. Return Value:
  153. TRUE if message handled, otherwise FALSE.
  154. --*/
  155. BOOL
  156. PrintToFileHelp(
  157. IN HWND hDlg,
  158. IN UINT uMsg,
  159. IN WPARAM wParam,
  160. IN LPARAM lParam
  161. )
  162. {
  163. BOOL bStatus = FALSE;
  164. switch( uMsg ){
  165. case WM_HELP:
  166. bStatus = WinHelp((HWND)((LPHELPINFO)lParam)->hItemHandle,
  167. szHelpFile,
  168. HELP_WM_HELP,
  169. (ULONG_PTR)g_aHelpIDs );
  170. break;
  171. case WM_CONTEXTMENU:
  172. bStatus = WinHelp((HWND)wParam,
  173. szHelpFile,
  174. HELP_CONTEXTMENU,
  175. (ULONG_PTR)g_aHelpIDs );
  176. break;
  177. }
  178. return bStatus;
  179. }