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.

351 lines
11 KiB

  1. #include "shellprv.h"
  2. #include "ids.h"
  3. #include "ftadv.h"
  4. #include "ftcmmn.h"
  5. #include "ftaction.h"
  6. #include "ftassoc.h"
  7. const static DWORD cs_rgdwHelpIDsArray[] =
  8. { // Context Help IDs
  9. IDC_FT_CMD_ACTION, IDH_FCAB_FT_CMD_ACTION,
  10. IDC_FT_CMD_EXETEXT, IDH_FCAB_FT_CMD_EXE,
  11. IDC_FT_CMD_EXE, IDH_FCAB_FT_CMD_EXE,
  12. IDC_FT_CMD_BROWSE, IDH_FCAB_FT_CMD_BROWSE,
  13. IDC_FT_CMD_DDEGROUP, IDH_FCAB_FT_CMD_USEDDE,
  14. IDC_FT_CMD_USEDDE, IDH_FCAB_FT_CMD_USEDDE,
  15. IDC_FT_CMD_DDEMSG, IDH_FCAB_FT_CMD_DDEMSG,
  16. IDC_FT_CMD_DDEAPP, IDH_FCAB_FT_CMD_DDEAPP,
  17. IDC_FT_CMD_DDEAPPNOT, IDH_FCAB_FT_CMD_DDEAPPNOT,
  18. IDC_FT_CMD_DDETOPIC, IDH_FCAB_FT_CMD_DDETOPIC,
  19. 0, 0
  20. };
  21. CFTActionDlg::CFTActionDlg(PROGIDACTION* pProgIDAction, LPTSTR pszProgIDDescr,
  22. BOOL fEdit) :
  23. CFTDlg((ULONG_PTR)cs_rgdwHelpIDsArray),
  24. _pProgIDAction(pProgIDAction), _pszProgIDDescr(pszProgIDDescr),
  25. _fEdit(fEdit)
  26. {
  27. }
  28. CFTActionDlg::~CFTActionDlg()
  29. {
  30. }
  31. ///////////////////////////////////////////////////////////////////////////////
  32. // Logic specific to our problem
  33. LRESULT CFTActionDlg::OnInitDialog(WPARAM wParam, LPARAM lParam)
  34. {
  35. DECLAREWAITCURSOR;
  36. SetWaitCursor();
  37. if (_fEdit || _fShowAgain)
  38. {
  39. TCHAR szTitle[50 + MAX_PROGIDDESCR + 5];
  40. TCHAR szTitleTemplate[50];
  41. _fShowAgain = FALSE;
  42. if (LoadString(g_hinst, IDS_FT_EDITTITLE, szTitleTemplate, ARRAYSIZE(szTitleTemplate)))
  43. {
  44. StringCchPrintf(szTitle, ARRAYSIZE(szTitle), szTitleTemplate, _pszProgIDDescr);
  45. SetWindowText(_hwnd, szTitle);
  46. }
  47. SetDlgItemText(_hwnd, IDC_FT_CMD_ACTION, _pProgIDAction->szAction);
  48. SetDlgItemText(_hwnd, IDC_FT_CMD_EXE, _pProgIDAction->szCmdLine);
  49. SetDlgItemText(_hwnd, IDC_FT_CMD_DDEMSG, _pProgIDAction->szDDEMsg);
  50. SetDlgItemText(_hwnd, IDC_FT_CMD_DDEAPP, _pProgIDAction->szDDEApplication);
  51. SetDlgItemText(_hwnd, IDC_FT_CMD_DDEAPPNOT, _pProgIDAction->szDDEAppNotRunning);
  52. SetDlgItemText(_hwnd, IDC_FT_CMD_DDETOPIC, _pProgIDAction->szDDETopic);
  53. CheckDlgButton(_hwnd, IDC_FT_CMD_USEDDE, _pProgIDAction->fUseDDE);
  54. _ResizeDlgForDDE(_pProgIDAction->fUseDDE);
  55. }
  56. else
  57. {
  58. CheckDlgButton(_hwnd, IDC_FT_CMD_USEDDE, FALSE);
  59. _ResizeDlgForDDE(FALSE);
  60. }
  61. Edit_LimitText(GetDlgItem(_hwnd, IDC_FT_CMD_ACTION), MAX_ACTION - 1);
  62. Edit_LimitText(GetDlgItem(_hwnd, IDC_FT_CMD_EXE), MAX_ACTIONCMDLINE - 1);
  63. Edit_LimitText(GetDlgItem(_hwnd, IDC_FT_CMD_DDEMSG), MAX_ACTIONDDEMSG - 1);
  64. Edit_LimitText(GetDlgItem(_hwnd, IDC_FT_CMD_DDEAPP), MAX_ACTIONAPPL - 1);
  65. Edit_LimitText(GetDlgItem(_hwnd, IDC_FT_CMD_DDEAPPNOT), MAX_ACTIONDDEAPPNOTRUN - 1);
  66. Edit_LimitText(GetDlgItem(_hwnd, IDC_FT_CMD_DDETOPIC), MAX_ACTIONTOPIC - 1);
  67. ResetWaitCursor();
  68. // Return TRUE so that system set focus
  69. return TRUE;
  70. }
  71. BOOL CFTActionDlg::_Validate()
  72. {
  73. BOOL bRet = TRUE;
  74. // Check the Action
  75. TCHAR szAction[MAX_ACTION];
  76. if (!GetDlgItemText(_hwnd, IDC_FT_CMD_ACTION, szAction, ARRAYSIZE(szAction)) ||
  77. !*szAction)
  78. {
  79. ShellMessageBox(g_hinst, _hwnd, MAKEINTRESOURCE(IDS_FT_MB_NOACTION),
  80. MAKEINTRESOURCE(IDS_FT), MB_OK | MB_ICONSTOP);
  81. PostMessage(_hwnd, WM_CTRL_SETFOCUS, (WPARAM)0,
  82. (LPARAM)GetDlgItem(_hwnd, IDC_FT_CMD_ACTION));
  83. bRet = FALSE;
  84. }
  85. if (bRet)
  86. {
  87. TCHAR szPath[MAX_PATH];
  88. LPTSTR pszFileName = NULL;
  89. // Check for valid exe
  90. GetDlgItemText(_hwnd, IDC_FT_CMD_EXE, szPath, ARRAYSIZE(szPath));
  91. PathRemoveArgs(szPath);
  92. PathUnquoteSpaces(szPath);
  93. pszFileName = PathFindFileName(szPath);
  94. if(!(*szPath) ||
  95. !(PathIsExe(szPath)) ||
  96. ((!(PathFileExists(szPath))) && (!(PathFindOnPath(pszFileName, NULL)))))
  97. {
  98. // Tell user that this exe is invalid
  99. ShellMessageBox(g_hinst, _hwnd, MAKEINTRESOURCE(IDS_FT_MB_EXETEXT),
  100. MAKEINTRESOURCE(IDS_FT), MB_OK | MB_ICONSTOP);
  101. PostMessage(_hwnd, WM_CTRL_SETFOCUS, (WPARAM)0,
  102. (LPARAM)GetDlgItem(_hwnd, IDC_FT_CMD_EXE));
  103. bRet = FALSE;
  104. }
  105. }
  106. return bRet;
  107. }
  108. void CFTActionDlg::SetShowAgain()
  109. {
  110. _fShowAgain = TRUE;
  111. }
  112. BOOL _IsThereAnyPercentArgument(LPTSTR pszCommand)
  113. {
  114. BOOL fRet = FALSE;
  115. LPTSTR pszArgs = PathGetArgs(pszCommand);
  116. if (pszArgs && *pszArgs)
  117. {
  118. if (StrStr(pszArgs, TEXT("%")))
  119. {
  120. fRet = TRUE;
  121. }
  122. }
  123. return fRet;
  124. }
  125. LRESULT CFTActionDlg::OnOK(WORD wNotif)
  126. {
  127. if (_Validate())
  128. {
  129. GetDlgItemText(_hwnd, IDC_FT_CMD_ACTION, _pProgIDAction->szAction, MAX_ACTION);
  130. // Is this a new action?
  131. if (!_fEdit)
  132. {
  133. // Yes, initialize the old action field
  134. StringCchCopy(_pProgIDAction->szOldAction, ARRAYSIZE(_pProgIDAction->szOldAction), _pProgIDAction->szAction);
  135. // Build the ActionReg
  136. StringCchCopy(_pProgIDAction->szActionReg, ARRAYSIZE(_pProgIDAction->szActionReg), _pProgIDAction->szAction);
  137. // Replace spaces with underscores
  138. LPTSTR psz = _pProgIDAction->szActionReg;
  139. while (*psz)
  140. {
  141. if (TEXT(' ') == *psz)
  142. {
  143. *psz = TEXT('_');
  144. }
  145. psz = CharNext(psz);
  146. }
  147. StringCchCopy(_pProgIDAction->szOldActionReg, ARRAYSIZE(_pProgIDAction->szOldActionReg),
  148. _pProgIDAction->szActionReg);
  149. }
  150. GetDlgItemText(_hwnd, IDC_FT_CMD_EXE, _pProgIDAction->szCmdLine, MAX_ACTIONCMDLINE);
  151. GetDlgItemText(_hwnd, IDC_FT_CMD_DDEMSG, _pProgIDAction->szDDEMsg, MAX_ACTIONDDEMSG);
  152. GetDlgItemText(_hwnd, IDC_FT_CMD_DDEAPP, _pProgIDAction->szDDEApplication, MAX_ACTIONAPPL);
  153. GetDlgItemText(_hwnd, IDC_FT_CMD_DDEAPPNOT, _pProgIDAction->szDDEAppNotRunning, MAX_ACTIONDDEAPPNOTRUN);
  154. GetDlgItemText(_hwnd, IDC_FT_CMD_DDETOPIC, _pProgIDAction->szDDETopic, MAX_ACTIONTOPIC);
  155. _pProgIDAction->fUseDDE = IsDlgButtonChecked(_hwnd, IDC_FT_CMD_USEDDE);
  156. // Append %1 to action field, if required
  157. if (!_IsThereAnyPercentArgument(_pProgIDAction->szCmdLine))
  158. {
  159. TCHAR* pszPercentToAppend;
  160. if (StrChr(_pProgIDAction->szCmdLine,TEXT('\\')))
  161. {
  162. if (App_IsLFNAware(_pProgIDAction->szCmdLine))
  163. pszPercentToAppend = TEXT(" \"%1\"");
  164. else
  165. pszPercentToAppend = TEXT(" %1");
  166. }
  167. else
  168. {
  169. TCHAR szFullPathFileName[MAX_PATH];
  170. //
  171. StringCchCopy(szFullPathFileName, ARRAYSIZE(szFullPathFileName), _pProgIDAction->szCmdLine);
  172. //PathFindOnPath: first param is the filename, if it is on the path
  173. // then it returns fully qualified, if not return false.
  174. //Second param is optional directory to look in first
  175. if (PathFindOnPath(szFullPathFileName, NULL))
  176. {
  177. if (App_IsLFNAware(szFullPathFileName))
  178. pszPercentToAppend = TEXT(" \"%1\"");
  179. else
  180. pszPercentToAppend = TEXT(" %1");
  181. }
  182. else
  183. {//just in case, default to good old behavior. Should not come here because
  184. // ActionExeIsValid was done earlier
  185. pszPercentToAppend = TEXT(" %1");
  186. }
  187. }
  188. //append...
  189. StringCchCat(_pProgIDAction->szCmdLine, ARRAYSIZE(_pProgIDAction->szCmdLine), pszPercentToAppend);
  190. }
  191. EndDialog(_hwnd, IDOK);
  192. }
  193. return FALSE;
  194. }
  195. LRESULT CFTActionDlg::OnCancel(WORD wNotif)
  196. {
  197. EndDialog(_hwnd, IDCANCEL);
  198. return FALSE;
  199. }
  200. LRESULT CFTActionDlg::OnUseDDE(WORD wNotif)
  201. {
  202. _ResizeDlgForDDE(IsDlgButtonChecked(_hwnd, IDC_FT_CMD_USEDDE));
  203. return FALSE;
  204. }
  205. LRESULT CFTActionDlg::OnBrowse(WORD wNotif)
  206. {
  207. TCHAR szPath[MAX_PATH];
  208. TCHAR szTitle[40];
  209. TCHAR szEXE[MAX_PATH];
  210. TCHAR szFilters[MAX_PATH];
  211. LPTSTR psz;
  212. szPath[0] = 0;
  213. EVAL(LoadString(g_hinst, IDS_CAP_OPENAS, szTitle, ARRAYSIZE(szTitle)));
  214. EVAL(LoadString(g_hinst, IDS_FT_EXE, szEXE, ARRAYSIZE(szEXE)));
  215. // And we need to convert #'s to \0's...
  216. EVAL(LoadString(g_hinst, IDS_PROGRAMSFILTER, szFilters, ARRAYSIZE(szFilters)));
  217. psz = szFilters;
  218. while (*psz)
  219. {
  220. if (*psz == TEXT('#'))
  221. {
  222. LPTSTR pszT = psz;
  223. psz = CharNext(psz);
  224. *pszT = TEXT('\0');
  225. }
  226. else
  227. psz = CharNext(psz);
  228. }
  229. if (GetFileNameFromBrowse(_hwnd, szPath, ARRAYSIZE(szPath), NULL, szEXE, szFilters, szTitle))
  230. {
  231. PathQuoteSpaces(szPath);
  232. SetDlgItemText(_hwnd, IDC_FT_CMD_EXE, szPath);
  233. }
  234. return FALSE;
  235. }
  236. void CFTActionDlg::_ResizeDlgForDDE(BOOL fShow)
  237. {
  238. RECT rcDialog;
  239. RECT rcControl;
  240. GetWindowRect(_hwnd, &rcDialog);
  241. if(fShow)
  242. GetWindowRect(GetDlgItem(_hwnd, IDC_FT_CMD_DDEGROUP), &rcControl);
  243. else
  244. GetWindowRect(GetDlgItem(_hwnd, IDC_FT_CMD_USEDDE), &rcControl);
  245. // Hide/Show the windows to take care of the Tabbing. If we don't hide them then
  246. // we tab through the "visible" window outside of the dialog.
  247. ShowWindow(GetDlgItem(_hwnd, IDC_FT_CMD_DDEMSG), fShow);
  248. ShowWindow(GetDlgItem(_hwnd, IDC_FT_CMD_DDEAPP), fShow);
  249. ShowWindow(GetDlgItem(_hwnd, IDC_FT_CMD_DDEAPPNOT), fShow);
  250. ShowWindow(GetDlgItem(_hwnd, IDC_FT_CMD_DDETOPIC), fShow);
  251. ShowWindow(GetDlgItem(_hwnd, IDC_FT_CMD_DDEGROUP), fShow);
  252. SetWindowPos(GetDlgItem(_hwnd, IDC_FT_CMD_USEDDE), HWND_TOPMOST,
  253. 0, 0, 0, 0, SWP_NOMOVE|SWP_NOSIZE|SWP_SHOWWINDOW);
  254. MoveWindow(_hwnd, rcDialog.left, rcDialog.top, rcDialog.right - rcDialog.left,
  255. (rcControl.bottom - rcDialog.top) + 10, TRUE);
  256. SetFocus(GetDlgItem(_hwnd, IDC_FT_CMD_USEDDE));
  257. }
  258. LRESULT CFTActionDlg::OnDestroy(WPARAM wParam, LPARAM lParam)
  259. {
  260. CFTDlg::OnDestroy(wParam, lParam);
  261. return FALSE;
  262. }
  263. ///////////////////////////////////////////////////////////////////////////////
  264. // Windows boiler plate code
  265. LRESULT CFTActionDlg::OnCommand(WPARAM wParam, LPARAM lParam)
  266. {
  267. LRESULT lRes = FALSE;
  268. switch(GET_WM_COMMAND_ID(wParam, lParam))
  269. {
  270. case IDC_FT_CMD_USEDDE:
  271. // Resize Dialog to see/hide DDE controls
  272. lRes = OnUseDDE(GET_WM_COMMAND_CMD(wParam, lParam));
  273. break;
  274. case IDC_FT_CMD_BROWSE:
  275. lRes = OnBrowse(GET_WM_COMMAND_CMD(wParam, lParam));
  276. break;
  277. default:
  278. lRes = CFTDlg::OnCommand(wParam, lParam);
  279. break;
  280. }
  281. return lRes;
  282. }