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.

334 lines
8.0 KiB

  1. /* File: C:\WACKER\TDLL\CPF_DLG.C (Created: 12-Jan-94)
  2. *
  3. * Copyright 1990,1993,1994 by Hilgraeve Inc. -- Monroe, MI
  4. * All rights reserved
  5. *
  6. * $Revision: 9 $
  7. * $Date: 3/26/02 8:48a $
  8. */
  9. #include <windows.h>
  10. #pragma hdrstop
  11. #define DO_RAW_MODE 1
  12. #include "stdtyp.h"
  13. #include "mc.h"
  14. #include <term\res.h>
  15. #include "tdll.h"
  16. #include "misc.h"
  17. #include "assert.h"
  18. #include "globals.h"
  19. #include "session.h"
  20. #include "capture.h"
  21. #include "load_res.h"
  22. #include "open_msc.h"
  23. #include "errorbox.h"
  24. #include "hlptable.h"
  25. #include "htchar.h"
  26. #include "file_msc.h"
  27. #if !defined(DlgParseCmd)
  28. #define DlgParseCmd(i,n,c,w,l) i=LOWORD(w);n=HIWORD(w);c=(HWND)l;
  29. #endif
  30. struct stSaveDlgStuff
  31. {
  32. /*
  33. * Put in whatever else you might need to access later
  34. */
  35. HSESSION hSession;
  36. };
  37. typedef struct stSaveDlgStuff SDS;
  38. #define IDC_TF_FILE 100
  39. #define FNAME_EDIT 105
  40. #define IDC_TF_DIR 106
  41. #define DIRECTORY_TEXT 107
  42. #define BROWSE_BTN 123
  43. #define IDC_PB_START 124
  44. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  45. * FUNCTION:
  46. * CaptureFileDlg
  47. *
  48. * DESCRIPTION:
  49. * This is the dialog proc for the capture to file dialog. No suprises
  50. * here.
  51. *
  52. * ARGUMENTS: Standard Windows dialog manager
  53. *
  54. * RETURNS: Standard Windows dialog manager
  55. *
  56. */
  57. INT_PTR CALLBACK CaptureFileDlg(HWND hDlg, UINT wMsg, WPARAM wPar, LPARAM lPar)
  58. {
  59. BOOL fRc;
  60. DWORD dwMaxComponentLength;
  61. DWORD dwFileSystemFlags;
  62. HWND hwndChild;
  63. INT nId;
  64. INT nNtfy;
  65. SDS *pS;
  66. HSESSION hSession;
  67. LPTSTR pszStr;
  68. TCHAR acBuffer[MAX_PATH];
  69. static DWORD aHlpTable[] = {FNAME_EDIT, IDH_TERM_CAPT_FILENAME,
  70. IDC_TF_FILE, IDH_TERM_CAPT_FILENAME,
  71. BROWSE_BTN, IDH_BROWSE,
  72. IDC_TF_DIR, IDH_TERM_CAPT_DIRECTORY,
  73. DIRECTORY_TEXT, IDH_TERM_CAPT_DIRECTORY,
  74. IDC_PB_START, IDH_TERM_CAPT_START,
  75. IDCANCEL, IDH_CANCEL,
  76. IDOK, IDH_OK,
  77. 0, 0};
  78. switch (wMsg)
  79. {
  80. case WM_INITDIALOG:
  81. {
  82. DWORD dwStyle = SS_WORDELLIPSIS;
  83. pS = (SDS *)malloc(sizeof(SDS));
  84. if (pS == (SDS *)0)
  85. {
  86. /* TODO: decide if we need to display an error here */
  87. EndDialog(hDlg, FALSE);
  88. break;
  89. }
  90. pS->hSession = (HSESSION)lPar;
  91. SetWindowLongPtr(hDlg, DWLP_USER, (LONG_PTR)pS);
  92. hSession = pS->hSession;
  93. mscCenterWindowOnWindow(hDlg, GetParent(hDlg));
  94. // Determine whether long filenames are supported. JRJ 12/94
  95. fRc = GetVolumeInformation(NULL, // pointer to root dir path buffer
  96. NULL, // pointer to volume name buffer
  97. 0, // length of volume name buffer
  98. NULL, // pointer to volume serial number buffer
  99. &dwMaxComponentLength, // the prize - what I'm after
  100. &dwFileSystemFlags, // ptr to file system flag DWORD
  101. NULL, // pointer to file system name buffer
  102. 0); // length of file system name buffer
  103. if(dwMaxComponentLength == 255)
  104. {
  105. // There is support for long file names.
  106. SendDlgItemMessage(hDlg, FNAME_EDIT, EM_SETLIMITTEXT, FNAME_LEN, 0);
  107. }
  108. else
  109. {
  110. // There IS NOT support for long file names. Limit to twelve.
  111. SendDlgItemMessage(hDlg, FNAME_EDIT, EM_SETLIMITTEXT, 12, 0);
  112. }
  113. /* Get the file name first */
  114. TCHAR_Fill(acBuffer, TEXT('\0'), MAX_PATH);
  115. cpfGetCaptureFilename(sessQueryCaptureFileHdl(hSession),
  116. acBuffer, MAX_PATH);
  117. SetDlgItemText(hDlg, FNAME_EDIT, acBuffer);
  118. mscStripName(acBuffer);
  119. pszStr = StrCharLast(acBuffer);
  120. // Remove the trailing backslash from the name
  121. // returned from mscStripName. Leave it on
  122. // in the case of a root directory specification.
  123. //
  124. if (pszStr > acBuffer + (3 * sizeof(TCHAR)) )
  125. {
  126. if (pszStr && ( *pszStr == TEXT('\\') || *pszStr == TEXT('/')))
  127. {
  128. *pszStr = TEXT('\0');
  129. }
  130. }
  131. if (GetWindowsMajorVersion() > 4)
  132. {
  133. dwStyle = SS_PATHELLIPSIS;
  134. }
  135. mscModifyToFit(GetDlgItem(hDlg, DIRECTORY_TEXT), acBuffer, dwStyle);
  136. SetDlgItemText(hDlg, DIRECTORY_TEXT, acBuffer);
  137. }
  138. break;
  139. case WM_DESTROY:
  140. break;
  141. case WM_CONTEXTMENU:
  142. doContextHelp(aHlpTable, wPar, lPar, TRUE, TRUE);
  143. break;
  144. case WM_HELP:
  145. doContextHelp(aHlpTable, wPar, lPar, FALSE, FALSE);
  146. break;
  147. case WM_COMMAND:
  148. /*
  149. * Did we plan to put a macro in here to do the parsing ?
  150. */
  151. DlgParseCmd(nId, nNtfy, hwndChild, wPar, lPar);
  152. switch (nId)
  153. {
  154. case IDC_PB_START:
  155. {
  156. int nDef;
  157. pS = (SDS *)GetWindowLongPtr(hDlg, DWLP_USER);
  158. assert(pS);
  159. hSession = pS->hSession;
  160. /*
  161. * Do whatever saving is necessary
  162. */
  163. nDef = TRUE;
  164. TCHAR_Fill(acBuffer, TEXT('\0'), MAX_PATH);
  165. GetDlgItemText(hDlg, FNAME_EDIT, acBuffer, MAX_PATH);
  166. // Error check the user-supplied name.
  167. if(ValidateFileName(acBuffer) == 1)
  168. {
  169. cpfSetCaptureFilename(sessQueryCaptureFileHdl(hSession),
  170. acBuffer, nDef);
  171. #if defined(DO_RAW_MODE)
  172. cpfSetCaptureMode(sessQueryCaptureFileHdl(hSession),
  173. CPF_MODE_RAW,
  174. FALSE);
  175. #endif
  176. /*
  177. * TODO: actually start the capture to file
  178. */
  179. cpfSetCaptureState(sessQueryCaptureFileHdl(hSession),
  180. CPF_CAPTURE_ON);
  181. /* Free the storage */
  182. free(pS);
  183. pS = (SDS *)0;
  184. EndDialog(hDlg, TRUE);
  185. }
  186. else
  187. {
  188. // There were problems.
  189. // e.g. The user specified a bad capture file name, or
  190. // for some other reason the file couldn't be created.
  191. mscMessageBeep(MB_ICONHAND);
  192. // For now, I'm going to assume that whatever the problem is,
  193. // the only thing the user can do to try again is to specify
  194. // a different filename. So, I'm setting the focus back to
  195. // the filename edit control.
  196. SetFocus(GetDlgItem(hDlg,FNAME_EDIT));
  197. }
  198. }
  199. break;
  200. case IDCANCEL:
  201. pS = (SDS *)GetWindowLongPtr(hDlg, DWLP_USER);
  202. /* Free the storeage */
  203. free(pS);
  204. pS = (SDS *)0;
  205. EndDialog(hDlg, FALSE);
  206. break;
  207. case BROWSE_BTN:
  208. {
  209. DWORD dwStyle = SS_WORDELLIPSIS;
  210. pS = (SDS *)GetWindowLongPtr(hDlg, DWLP_USER);
  211. if (pS)
  212. {
  213. LPTSTR pszRet;
  214. TCHAR acTitle[64];
  215. TCHAR acList[64];
  216. hSession = pS->hSession;
  217. pszRet = NULL;
  218. TCHAR_Fill(acBuffer, TEXT('\0'), MAX_PATH);
  219. GetDlgItemText(hDlg, DIRECTORY_TEXT, acBuffer, MAX_PATH - 1);
  220. LoadString(glblQueryDllHinst(),
  221. IDS_CPF_DLG_FILE,
  222. acTitle,
  223. sizeof(acTitle) / sizeof(TCHAR));
  224. resLoadFileMask(glblQueryDllHinst(),
  225. IDS_CPF_FILES1,
  226. 2,
  227. acList,
  228. sizeof(acList) / sizeof(TCHAR));
  229. //jmh 3/24/97 This was gnrcFindFileDialog, but this lets you
  230. // enter a non-existent file name, which is what we really want
  231. pszRet = gnrcSaveFileDialog(hDlg,
  232. acTitle,
  233. acBuffer,
  234. acList,
  235. "");
  236. if (pszRet != NULL)
  237. {
  238. StrCharCopyN(acBuffer, pszRet, MAX_PATH);
  239. acBuffer[MAX_PATH - 1] = TEXT('\0');
  240. SetDlgItemText(hDlg, FNAME_EDIT, pszRet);
  241. free(pszRet);
  242. pszRet = NULL;
  243. mscStripName(acBuffer);
  244. pszStr = StrCharLast(acBuffer);
  245. // Remove the trailing backslash from the name
  246. // returned from mscStripName. Leave it on
  247. // in the case of a root directory specification.
  248. //
  249. if (pszStr > acBuffer + (3 * sizeof(TCHAR)) )
  250. {
  251. if (pszStr && ( *pszStr == TEXT('\\') || *pszStr == TEXT('/')))
  252. {
  253. *pszStr = TEXT('\0');
  254. }
  255. }
  256. if (GetWindowsMajorVersion() > 4)
  257. {
  258. dwStyle = SS_PATHELLIPSIS;
  259. }
  260. mscModifyToFit(GetDlgItem(hDlg, DIRECTORY_TEXT), acBuffer, dwStyle);
  261. SetDlgItemText(hDlg, DIRECTORY_TEXT, acBuffer);
  262. }
  263. }
  264. }
  265. break;
  266. default:
  267. return FALSE;
  268. }
  269. break;
  270. default:
  271. return FALSE;
  272. }
  273. return TRUE;
  274. }