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.

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