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.

440 lines
15 KiB

  1. #include <privcpp.h>
  2. #include <windows.h>
  3. #include <prsht.h>
  4. #include <shlwapi.h>
  5. #include <shsemip.h>
  6. #include "ids.h"
  7. #define IDS_FILENOTFOUND 0x2331
  8. //
  9. // FUNCTION: PackWiz_SelectFileDlgProc(HWND,UINT,WPARAM,LPARAM)
  10. //
  11. // PURPOSE: Dialog procedure for FIRST page of Create New Package Wizard
  12. //
  13. //
  14. INT_PTR CALLBACK PackWiz_SelectFileDlgProc(HWND hDlg, UINT uMsg , WPARAM wParam, LPARAM lParam)
  15. {
  16. LPPACKAGER_INFO lppi = (LPPACKAGER_INFO)GetWindowLongPtr(hDlg, DWLP_USER);
  17. static BOOL bStayHere = FALSE;
  18. switch (uMsg)
  19. {
  20. case WM_INITDIALOG:
  21. lppi = (LPPACKAGER_INFO)((LPPROPSHEETPAGE)lParam)->lParam;
  22. SetWindowLongPtr(hDlg, DWLP_USER, (LONG_PTR)lppi);
  23. Edit_LimitText(GetDlgItem(hDlg, IDC_COMMAND), ARRAYSIZE(lppi->szFilename) - 1);
  24. CheckDlgButton(hDlg, IDC_CHECK1, lppi->bUseCommandLine);
  25. if (*lppi->szFilename)
  26. SetDlgItemText(hDlg, IDC_COMMAND, lppi->szFilename);
  27. break;
  28. case WM_COMMAND:
  29. switch (GET_WM_COMMAND_ID(wParam, lParam))
  30. {
  31. case IDHELP:
  32. break;
  33. case IDC_COMMAND:
  34. // Check to see if we have a change in the edit control
  35. switch (GET_WM_COMMAND_CMD(wParam, lParam))
  36. {
  37. case EN_CHANGE:
  38. if (GetWindowTextLength(GetDlgItem(hDlg, IDC_COMMAND)) > 0)
  39. PropSheet_SetWizButtons(GetParent(hDlg), PSWIZB_NEXT);
  40. else
  41. PropSheet_SetWizButtons(GetParent(hDlg), 0);
  42. break;
  43. }
  44. break;
  45. case IDC_BROWSE:
  46. {
  47. TCHAR szExt[MAX_PATH];
  48. TCHAR szFilter[80];
  49. TCHAR szTitle[80];
  50. TCHAR szFilename[MAX_PATH];
  51. int ret;
  52. LPTSTR lpsz = szFilter;
  53. // load the filter and then replace all the @ characters
  54. // with NULL. The end of the string will be doubly
  55. // null-terminated
  56. LoadString(g_hinstResDLL, IDS_BROWSEFILTER, szFilter, ARRAYSIZE(szFilter)-1);
  57. while (*lpsz) {
  58. if (*lpsz == TEXT('@')) {
  59. *lpsz = 0;
  60. lpsz++;
  61. }
  62. else {
  63. lpsz = CharNext(lpsz);
  64. }
  65. }
  66. *(lpsz+1) = 0;
  67. LoadString(g_hinstResDLL, IDS_BROWSEEXT, szExt, ARRAYSIZE(szExt));
  68. LoadString(g_hinstResDLL, IDS_BROWSETITLE, szTitle, ARRAYSIZE(szTitle));
  69. GetDlgItemText(hDlg, IDC_COMMAND, lppi->szFilename, ARRAYSIZE(lppi->szFilename));
  70. // Danger - this is a TCHAR API!
  71. ret = GetFileNameFromBrowse(hDlg,szFilename, ARRAYSIZE(lppi->szFilename), NULL, szExt, szFilter, szTitle);
  72. if (ret > 0)
  73. {
  74. StringCchCopy(lppi->szFilename, ARRAYSIZE(lppi->szFilename), szFilename);
  75. }
  76. SetDlgItemText(hDlg, IDC_COMMAND, lppi->szFilename);
  77. break;
  78. }
  79. }
  80. break;
  81. case WM_NOTIFY:
  82. switch (((NMHDR *)lParam)->code)
  83. {
  84. case PSN_KILLACTIVE:
  85. SetWindowLongPtr(hDlg, DWLP_MSGRESULT, bStayHere);
  86. return TRUE;
  87. case PSN_RESET:
  88. // reset to original values
  89. *lppi->szFilename = TEXT('\0');
  90. SetWindowLongPtr(hDlg, DWLP_MSGRESULT, FALSE);
  91. break;
  92. case PSN_SETACTIVE:
  93. Edit_SetText(GetDlgItem(hDlg, IDC_COMMAND), lppi->szFilename);
  94. if (GetWindowTextLength(GetDlgItem(hDlg, IDC_COMMAND)) > 0)
  95. PropSheet_SetWizButtons(GetParent(hDlg), PSWIZB_NEXT);
  96. else
  97. PropSheet_SetWizButtons(GetParent(hDlg), 0);
  98. break;
  99. case PSN_WIZNEXT:
  100. {
  101. bStayHere = FALSE;
  102. GetDlgItemText(hDlg, IDC_COMMAND, lppi->szFilename, ARRAYSIZE(lppi->szFilename));
  103. lppi->bUseCommandLine = IsDlgButtonChecked(hDlg, IDC_CHECK1);
  104. if(!lppi->bUseCommandLine)
  105. {
  106. DWORD dwFileAttributes = GetFileAttributes(lppi->szFilename);
  107. if(-1 == dwFileAttributes || (dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY))
  108. {
  109. HINSTANCE shell32Inst;
  110. shell32Inst = LoadLibraryEx(L"shell32.dll", NULL, LOAD_LIBRARY_AS_DATAFILE);
  111. ShellMessageBox(shell32Inst,
  112. NULL,
  113. MAKEINTRESOURCE(IDS_FILENOTFOUND),
  114. MAKEINTRESOURCE(IDS_FILENOTFOUND),
  115. MB_OK | MB_ICONERROR | MB_TASKMODAL);
  116. FreeLibrary(shell32Inst);
  117. bStayHere = TRUE;
  118. return TRUE;
  119. }
  120. }
  121. }
  122. break;
  123. case PSN_QUERYCANCEL:
  124. *lppi->szFilename = TEXT('\0');
  125. return FALSE;
  126. default:
  127. return FALSE;
  128. }
  129. break;
  130. case WM_DESTROY:
  131. case WM_HELP:
  132. case WM_CONTEXTMENU:
  133. break;
  134. default:
  135. return FALSE;
  136. } // end of switch on uMsg
  137. return TRUE;
  138. }
  139. //
  140. // FUNCTION: PackWiz_SelectLabelDlgProc(HWND, UINT, WPARAM, LPARAM)
  141. //
  142. // PURPOSE: Dialog procedure for THIRD page of Create New Package Wizard
  143. //
  144. //
  145. INT_PTR CALLBACK PackWiz_SelectLabelDlgProc(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
  146. {
  147. LPPACKAGER_INFO lppi = (LPPACKAGER_INFO)GetWindowLongPtr(hDlg, DWLP_USER);
  148. switch (uMsg)
  149. {
  150. case WM_INITDIALOG:
  151. lppi = (LPPACKAGER_INFO)((LPPROPSHEETPAGE)lParam)->lParam;
  152. SetWindowLongPtr(hDlg, DWLP_USER, (LONG_PTR)lppi);
  153. Edit_LimitText(GetDlgItem(hDlg, IDC_COMMAND), ARRAYSIZE(lppi->szLabel) - 1);
  154. GetDisplayName(lppi->szLabel, lppi->szFilename);
  155. break;
  156. case WM_COMMAND:
  157. switch (GET_WM_COMMAND_ID(wParam, lParam))
  158. {
  159. case IDHELP:
  160. break;
  161. case IDC_COMMAND:
  162. // Check to see if we have a change in the edit control
  163. switch (GET_WM_COMMAND_CMD(wParam, lParam))
  164. {
  165. case EN_CHANGE:
  166. if (GetWindowTextLength(GetDlgItem(hDlg, IDC_COMMAND)) > 0)
  167. PropSheet_SetWizButtons(GetParent(hDlg), PSWIZB_BACK|PSWIZB_FINISH);
  168. else
  169. PropSheet_SetWizButtons(GetParent(hDlg), PSWIZB_BACK);
  170. break;
  171. }
  172. break;
  173. }
  174. break;
  175. case WM_NOTIFY:
  176. switch (((NMHDR *)lParam)->code)
  177. {
  178. case PSN_KILLACTIVE:
  179. SetWindowLongPtr(hDlg, DWLP_MSGRESULT, FALSE);
  180. return TRUE;
  181. case PSN_RESET:
  182. // reset to original values
  183. *lppi->szLabel = TEXT('\0');
  184. SetWindowLongPtr(hDlg, DWLP_MSGRESULT, FALSE);
  185. break;
  186. case PSN_SETACTIVE:
  187. Edit_SetText(GetDlgItem(hDlg, IDC_COMMAND), lppi->szLabel);
  188. if (GetWindowTextLength(GetDlgItem(hDlg, IDC_COMMAND)) > 0)
  189. PropSheet_SetWizButtons(GetParent(hDlg), PSWIZB_BACK|PSWIZB_FINISH);
  190. else
  191. PropSheet_SetWizButtons(GetParent(hDlg), PSWIZB_BACK);
  192. break;
  193. case PSN_WIZBACK:
  194. GetDlgItemText(hDlg, IDC_COMMAND, lppi->szLabel, ARRAYSIZE(lppi->szLabel));
  195. break;
  196. case PSN_WIZFINISH:
  197. GetDlgItemText(hDlg, IDC_COMMAND, lppi->szLabel, ARRAYSIZE(lppi->szLabel));
  198. break;
  199. case PSN_QUERYCANCEL:
  200. *lppi->szFilename = TEXT('\0');
  201. return FALSE;
  202. default:
  203. return FALSE;
  204. }
  205. break;
  206. case WM_DESTROY:
  207. case WM_HELP:
  208. case WM_CONTEXTMENU:
  209. break;
  210. default:
  211. return FALSE;
  212. } // end of switch on uMsg
  213. return TRUE;
  214. }
  215. //
  216. // FUNCTION: PackWiz_EditPackageDlgProc(HWND,UINT,WPARAM,LPARAM)
  217. //
  218. // PURPOSE: Dialog procedure for Edit Package
  219. //
  220. // NOTE: We have two different types of packages we could edit, but they
  221. // both have exactly the same dialog layout, except for some static text, which
  222. // doesn't affect the dialog procedure
  223. //
  224. //
  225. INT_PTR CALLBACK PackWiz_EditPackageDlgProc(HWND hDlg, UINT uMsg , WPARAM wParam, LPARAM lParam)
  226. {
  227. LPPACKAGER_INFO lppi = (LPPACKAGER_INFO)GetWindowLongPtr(hDlg, DWLP_USER);
  228. switch (uMsg) {
  229. case WM_INITDIALOG:
  230. {
  231. HICON hicon;
  232. lppi = (LPPACKAGER_INFO)lParam;
  233. SetWindowLongPtr(hDlg, DWLP_USER, lParam);
  234. Edit_LimitText(GetDlgItem(hDlg, IDC_EDIT1), ARRAYSIZE(lppi->szFilename) - 1);
  235. Edit_LimitText(GetDlgItem(hDlg, IDC_EDIT2), ARRAYSIZE(lppi->szLabel) - 1);
  236. SetDlgItemText(hDlg, IDC_EDIT1, lppi->szFilename);
  237. SetDlgItemText(hDlg, IDC_EDIT2, lppi->szLabel);
  238. if (*lppi->szIconPath != TEXT('\0'))
  239. hicon = ExtractAssociatedIcon(g_hinstResDLL, lppi->szIconPath, (LPWORD)&(lppi->iIcon));
  240. else
  241. hicon = LoadIcon(g_hinstResDLL, MAKEINTRESOURCE(IDI_PACKAGER));
  242. HWND hPackIcon = GetDlgItem(hDlg, IDC_PACKICON);
  243. SendMessage(hPackIcon, STM_SETICON, (WPARAM)hicon, (LPARAM)0);
  244. break;
  245. }
  246. case WM_COMMAND:
  247. switch (GET_WM_COMMAND_ID(wParam, lParam))
  248. {
  249. case IDHELP:
  250. break;
  251. case IDOK:
  252. if(!gCmdLineOK && !PathFileExists(lppi->szFilename))
  253. {
  254. ShellMessageBox(g_hinstResDLL,
  255. NULL,
  256. MAKEINTRESOURCE(IDS_NO_SUCH_FILE_CANNOT_SAVE),
  257. MAKEINTRESOURCE(IDS_APP_TITLE),
  258. MB_OK | MB_ICONERROR | MB_TASKMODAL);
  259. }
  260. else
  261. {
  262. GetDlgItemText(hDlg, IDC_EDIT1, lppi->szFilename, ARRAYSIZE(lppi->szFilename));
  263. GetDlgItemText(hDlg, IDC_EDIT2, lppi->szLabel, ARRAYSIZE(lppi->szLabel));
  264. }
  265. EndDialog(hDlg, 1);
  266. break;
  267. case IDCANCEL:
  268. EndDialog(hDlg, -1);
  269. break;
  270. case IDC_BROWSE:
  271. {
  272. TCHAR szExt[80];
  273. TCHAR szFilter[80];
  274. TCHAR szTitle[80];
  275. LPTSTR lpsz = szFilter;
  276. // load the filter and then replace all the @ characters
  277. // with NULL. The end of the string will be doubly
  278. // null-terminated
  279. LoadString(g_hinstResDLL, IDS_BROWSEFILTER, szFilter, ARRAYSIZE(szFilter)-1);
  280. while (*lpsz) {
  281. if (*lpsz == TEXT('@')) {
  282. *lpsz = 0;
  283. lpsz++;
  284. }
  285. else {
  286. lpsz = CharNext(lpsz);
  287. }
  288. }
  289. *(lpsz+1) = 0;
  290. LoadString(g_hinstResDLL, IDS_BROWSEEXT, szExt, ARRAYSIZE(szExt));
  291. LoadString(g_hinstResDLL, IDS_BROWSETITLE, szTitle, ARRAYSIZE(szTitle));
  292. GetDlgItemText(hDlg, IDC_EDIT1, lppi->szFilename, ARRAYSIZE(lppi->szFilename));
  293. GetFileNameFromBrowse(hDlg,lppi->szFilename,
  294. ARRAYSIZE(lppi->szFilename), NULL, szExt, szFilter, szTitle);
  295. SetDlgItemText(hDlg, IDC_EDIT1, lppi->szFilename);
  296. }
  297. break;
  298. }
  299. break;
  300. case WM_DESTROY:
  301. case WM_HELP:
  302. case WM_CONTEXTMENU:
  303. break;
  304. default:
  305. return FALSE;
  306. } // end of switch on uMsg
  307. return TRUE;
  308. }
  309. //
  310. //
  311. // FUNCTION: PackWiz_FillInPropertyPage(PROPSHEETPAGE *, int, LPFN)
  312. //
  313. // PURPOSE: Fills in the given PROPSHEETPAGE structure
  314. //
  315. // COMMENTS:
  316. //
  317. // This function fills in a PROPSHEETPAGE structure with the
  318. // information the system needs to create the page.
  319. //
  320. void PackWiz_FillInPropertyPage(PROPSHEETPAGE* psp, int idDlg, DLGPROC pfnDlgProc, LPPACKAGER_INFO lppi)
  321. {
  322. ZeroMemory(psp, sizeof(PROPSHEETPAGE));
  323. psp->dwSize = sizeof(PROPSHEETPAGE);
  324. psp->dwFlags = 0;
  325. psp->hInstance = g_hinstResDLL;
  326. psp->pszTemplate = MAKEINTRESOURCE(idDlg);
  327. psp->pszIcon = NULL;
  328. psp->pfnDlgProc = pfnDlgProc;
  329. psp->pszTitle = NULL;
  330. psp->lParam = (LPARAM)lppi;
  331. }
  332. //
  333. //
  334. // FUNCTION: PackWiz_CreateWizard(HWND)
  335. //
  336. // PURPOSE: Create the Wizard control.
  337. //
  338. // COMMENTS:
  339. //
  340. // This function creates the wizard property sheet.
  341. //
  342. int PackWiz_CreateWizard(HWND hwndOwner, LPPACKAGER_INFO lppi)
  343. {
  344. PROPSHEETPAGE psp[PACKWIZ_NUM_PAGES];
  345. PROPSHEETHEADER psh;
  346. ZeroMemory(&psh, sizeof(psh));
  347. PackWiz_FillInPropertyPage(&psp[0], IDD_SELECTFILE, PackWiz_SelectFileDlgProc,lppi);
  348. PackWiz_FillInPropertyPage(&psp[1], IDD_SELECTLABEL, PackWiz_SelectLabelDlgProc,lppi);
  349. psh.dwSize = sizeof(PROPSHEETHEADER);
  350. psh.dwFlags = PSH_PROPSHEETPAGE | PSH_WIZARD;
  351. psh.hwndParent = hwndOwner;
  352. psh.nPages = ARRAYSIZE(psp);
  353. psh.nStartPage = 0;
  354. psh.pszIcon = NULL;
  355. psh.ppsp = (LPCPROPSHEETPAGE) &psp;
  356. return (int)(PropertySheet(&psh));
  357. }
  358. //
  359. // FUNCTION: PackWiz_EditPackage(HWND, WORD, LPPACKAGER_INFO)
  360. //
  361. // PURPOSE: To Run the Edit Package Dialog Procedure
  362. //
  363. //
  364. int PackWiz_EditPackage(HWND hwnd, int idDlg, LPPACKAGER_INFO lppi)
  365. {
  366. return (int)DialogBoxParam(g_hinstResDLL, MAKEINTRESOURCE(idDlg), hwnd, PackWiz_EditPackageDlgProc, (LPARAM)lppi);
  367. }