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.

249 lines
4.4 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. BOOL APIENTRY
  25. PrintToFileDlg(
  26. HWND hwnd,
  27. WORD 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. /* If the file already exists, get the user to verify
  85. * before we overwrite it:
  86. */
  87. if( hFind != INVALID_HANDLE_VALUE )
  88. {
  89. FindClose( hFind );
  90. if( Message( hwnd, MB_OKCANCEL | MB_ICONEXCLAMATION, IDS_LOCALMONITOR,
  91. IDS_OVERWRITE_EXISTING_FILE )
  92. != IDOK )
  93. {
  94. return TRUE;
  95. }
  96. }
  97. hFile = CreateFile( pFileName, GENERIC_WRITE, FILE_SHARE_READ, NULL,
  98. OPEN_ALWAYS,
  99. FILE_ATTRIBUTE_NORMAL | FILE_FLAG_SEQUENTIAL_SCAN,
  100. NULL );
  101. if( hFile != INVALID_HANDLE_VALUE )
  102. {
  103. LPWSTR pTempFileName;
  104. WCHAR szCurrentDir[MAX_PATH];
  105. WCHAR szQualifiedPath[MAX_PATH];
  106. LPWSTR pszIgnore;
  107. DWORD cchLen;
  108. CloseHandle(hFile);
  109. if (!GetCurrentDirectory(sizeof(szCurrentDir)/sizeof(szCurrentDir[0]),
  110. szCurrentDir))
  111. goto Fail;
  112. cchLen = SearchPath(szCurrentDir,
  113. pFileName,
  114. NULL,
  115. sizeof(szQualifiedPath)/sizeof(szQualifiedPath[0]),
  116. szQualifiedPath,
  117. &pszIgnore);
  118. if (!cchLen)
  119. goto Fail;
  120. pTempFileName = LocalAlloc(LMEM_FIXED,
  121. (cchLen + 1) * sizeof(szQualifiedPath[0]));
  122. if (!pTempFileName)
  123. goto Fail;
  124. wcscpy(pTempFileName, szQualifiedPath);
  125. *ppFileName = pTempFileName;
  126. EndDialog( hwnd, TRUE );
  127. } else {
  128. Fail:
  129. ReportFailure( hwnd, IDS_LOCALMONITOR, IDS_COULD_NOT_OPEN_FILE );
  130. }
  131. return TRUE;
  132. }
  133. /*
  134. *
  135. */
  136. BOOL
  137. PrintToFileCommandCancel(
  138. HWND hwnd
  139. )
  140. {
  141. EndDialog(hwnd, FALSE);
  142. return TRUE;
  143. }
  144. /*++
  145. Routine Name:
  146. PrintToFileHelp
  147. Routine Description:
  148. Handles context sensitive help.
  149. Arguments:
  150. UINT uMsg,
  151. HWND hDlg,
  152. WPARAM wParam,
  153. LPARAM lParam
  154. Return Value:
  155. TRUE if message handled, otherwise FALSE.
  156. --*/
  157. BOOL
  158. PrintToFileHelp(
  159. IN HWND hDlg,
  160. IN UINT uMsg,
  161. IN WPARAM wParam,
  162. IN LPARAM lParam
  163. )
  164. {
  165. BOOL bStatus = FALSE;
  166. switch( uMsg ){
  167. case WM_HELP:
  168. bStatus = WinHelp((HWND)((LPHELPINFO)lParam)->hItemHandle,
  169. szHelpFile,
  170. HELP_WM_HELP,
  171. (ULONG_PTR)g_aHelpIDs );
  172. break;
  173. case WM_CONTEXTMENU:
  174. bStatus = WinHelp((HWND)wParam,
  175. szHelpFile,
  176. HELP_CONTEXTMENU,
  177. (ULONG_PTR)g_aHelpIDs );
  178. break;
  179. }
  180. return bStatus;
  181. }