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.

1851 lines
56 KiB

  1. //*********************************************************************
  2. //* Microsoft Windows **
  3. //* Copyright(c) Microsoft Corp., 1995 **
  4. //*********************************************************************
  5. //
  6. // PROGRAMS.C - "Programs" property sheet UI handlers doe InetCpl
  7. //
  8. //
  9. //
  10. // History:
  11. //
  12. // 6/20/96 t-gpease created
  13. //
  14. #include "inetcplp.h"
  15. #include <mluisupp.h>
  16. #include <advpub.h>
  17. //
  18. // Private Functions and Structures
  19. //
  20. BOOL ProgramsDlgInit( HWND hDlg);
  21. void UpdateMailIconLabel();
  22. typedef struct {
  23. HWND hDlg; // dialog windows handle
  24. HWND hwndMail; // Mail dropdown
  25. HWND hwndNews; // News dropdown
  26. HWND hwndCalendar; // Calendar dropdown
  27. HWND hwndContact; // Contact dropdown
  28. HWND hwndCall; // Internet call dropdown
  29. HWND hwndHtmlEdit; // HTML Editors dropdown
  30. BOOL bAssociationCheck; // Is IE the default browser?
  31. #ifndef UNIX
  32. BOOL bIEIsFTPClient; // Is IE the default FTP Client?
  33. IFtpInstaller * pfi; // FTP Installer
  34. #endif // UNIX
  35. int iHtmlEditor;
  36. int iMail;
  37. int iNews;
  38. int iCalendar;
  39. int iContact;
  40. int iCall;
  41. BOOL fChanged;
  42. #ifdef UNIX
  43. HWND hwndVSource; // View Source
  44. HWND hwndMailEdit;
  45. HWND hwndMailFind;
  46. HWND hwndNewsFind;
  47. HWND hwndNewsEdit;
  48. DWORD dwUseOEMail;
  49. DWORD dwUseOENews;
  50. HWND hwndEnableUseOEMail;
  51. HWND hwndEnableUseOENews;
  52. int iVSource;
  53. #endif
  54. } PROGRAMSPAGE, *LPPROGRAMSPAGE;
  55. #define ARRAYSIZE(a) (sizeof(a)/sizeof(a[0]))
  56. #ifdef WALLET
  57. typedef int (*PFN_DISPLAYWALLETPAYDIALOG_PROC)(HWND, HINSTANCE, LPTSTR, int);
  58. typedef int (*PFN_DISPLAYWALLETADDRDIALOG_PROC)(HWND, HINSTANCE, LPTSTR, int);
  59. #endif
  60. //
  61. //
  62. //
  63. // "File Types" Dialog
  64. //
  65. //
  66. //
  67. // we only have to pull in one page.
  68. #define NUM_FILETYPES_PAGES 1
  69. static const char szAddFileTypesPS[] = "AddMIMEFileTypesPS";
  70. #ifdef WALLET
  71. // NOTE: This is dumb. Wallet uses different GUIDs for Alpha and x86 versions
  72. //
  73. #ifdef _ALPHA_
  74. static const TCHAR g_szWalletPaymentDirKey[] = TEXT("CLSID\\{B7FB4D5C-9FBE-11D0-8965-0000F822DEA9}\\InprocServer32");
  75. static const TCHAR g_szWalletAddressDirKey[] = TEXT("CLSID\\{B7FB4D5C-9FBE-11D0-8965-0000F822DEA9}\\InprocServer32");
  76. #else
  77. static const TCHAR g_szWalletPaymentDirKey[] = TEXT("CLSID\\{87D3CB66-BA2E-11CF-B9D6-00A0C9083362}\\InprocServer32");
  78. static const TCHAR g_szWalletAddressDirKey[] = TEXT("CLSID\\{87D3CB63-BA2E-11CF-B9D6-00A0C9083362}\\InprocServer32");
  79. #endif
  80. static const char g_szWalletPaymentFN[] = "DisplayWalletPaymentDialog";
  81. static const char g_szWalletAddressFN[] = "DisplayWalletAddressDialog";
  82. #endif
  83. BOOL CALLBACK AddFileTypesPropSheetPage(HPROPSHEETPAGE hpage, LPARAM lParam)
  84. {
  85. BOOL bResult;
  86. LPPROPSHEETHEADER ppsh = (LPPROPSHEETHEADER)lParam;
  87. bResult = (ppsh->nPages < NUM_FILETYPES_PAGES);
  88. if (bResult)
  89. ppsh->phpage[ppsh->nPages++] = hpage;
  90. return(bResult);
  91. }
  92. BOOL CreateFileTypesDialog(HWND hDlg)
  93. {
  94. PROPSHEETPAGE psp[NUM_FILETYPES_PAGES]; // only have "File Types" sheet
  95. PROPSHEETHEADER psHeader;
  96. TCHAR szFileTypes[MAX_PATH];
  97. typedef HRESULT (WINAPI *LPADDFILETYPESPS)(LPFNADDPROPSHEETPAGE pfnAddPage,
  98. LPARAM lparam);
  99. LPADDFILETYPESPS AddFileTypesPS;
  100. HINSTANCE hInstFTDll = NULL;
  101. // get the file name from resource
  102. TCHAR szDllFilename[SMALL_BUF_LEN+1];
  103. if (!MLLoadString(IDS_FTDLL_FILENAME,szDllFilename,ARRAYSIZE(szDllFilename)))
  104. {
  105. return FALSE;
  106. }
  107. // load the DLL
  108. hInstFTDll = LoadLibrary(szDllFilename);
  109. if (!hInstFTDll)
  110. {
  111. return FALSE;
  112. }
  113. // get Dialog Proc...
  114. if (!(AddFileTypesPS = (LPADDFILETYPESPS) GetProcAddress(hInstFTDll, szAddFileTypesPS)))
  115. {
  116. FreeLibrary(hInstFTDll);
  117. return FALSE;
  118. }
  119. memset(&psHeader,0,sizeof(psHeader));
  120. MLLoadString(IDS_FILETYPES, szFileTypes, ARRAYSIZE(szFileTypes));
  121. psHeader.dwSize = sizeof(psHeader);
  122. psHeader.dwFlags = PSH_NOAPPLYNOW | PSH_USECALLBACK ;
  123. psHeader.hwndParent = hDlg;
  124. psHeader.hInstance = MLGetHinst();
  125. psHeader.pszIcon = NULL;
  126. psHeader.nPages = 0;
  127. psHeader.ppsp = psp;
  128. psHeader.pszCaption = szFileTypes;
  129. // push the FileTypes page onto the sheet
  130. AddFileTypesPS(AddFileTypesPropSheetPage, (LPARAM)&psHeader);
  131. // don't care about the return value... wait for dialog to be done.
  132. PropertySheet(&psHeader);
  133. // all done... cleanup time...
  134. FreeLibrary(hInstFTDll);
  135. return TRUE; // we succeeded
  136. }
  137. #ifdef WALLET
  138. HINSTANCE GetWalletPaymentDProc(PFN_DISPLAYWALLETPAYDIALOG_PROC * ppfnDialogProc)
  139. {
  140. TCHAR szDLLFile[MAX_PATH];
  141. DWORD dwType;
  142. DWORD dwSize = SIZEOF(szDLLFile);
  143. HINSTANCE hInst = NULL;
  144. *ppfnDialogProc = NULL;
  145. if (ERROR_SUCCESS == SHGetValue(HKEY_CLASSES_ROOT, g_szWalletPaymentDirKey, NULL, &dwType, (LPVOID)szDLLFile, &dwSize))
  146. {
  147. hInst = LoadLibrary(szDLLFile);
  148. // Will Fail if OCX is not installed.
  149. if (hInst)
  150. {
  151. *ppfnDialogProc = (PFN_DISPLAYWALLETPAYDIALOG_PROC) GetProcAddress(hInst, g_szWalletPaymentFN);
  152. }
  153. }
  154. if (!*ppfnDialogProc && hInst)
  155. {
  156. FreeLibrary(hInst);
  157. hInst = NULL;
  158. }
  159. return hInst;
  160. }
  161. BOOL IsWalletPaymentAvailable(VOID)
  162. {
  163. HINSTANCE hInst;
  164. PFN_DISPLAYWALLETPAYDIALOG_PROC pfnDialogProc;
  165. BOOL fIsAvailable = FALSE;
  166. hInst = GetWalletPaymentDProc(&pfnDialogProc);
  167. if (hInst)
  168. {
  169. fIsAvailable = TRUE;
  170. FreeLibrary(hInst);
  171. }
  172. return fIsAvailable;
  173. }
  174. VOID DisplayWalletPaymentDialog(HWND hWnd)
  175. {
  176. HINSTANCE hInst;
  177. PFN_DISPLAYWALLETPAYDIALOG_PROC pfnDialogProc;
  178. hInst = GetWalletPaymentDProc(&pfnDialogProc);
  179. if (hInst)
  180. {
  181. (*pfnDialogProc)(hWnd, NULL, NULL, 0);
  182. FreeLibrary(hInst);
  183. }
  184. }
  185. HINSTANCE GetWalletAddressDProc(PFN_DISPLAYWALLETADDRDIALOG_PROC * ppfnDialogProc)
  186. {
  187. TCHAR szDLLFile[MAX_PATH];
  188. DWORD dwType;
  189. DWORD dwSize = SIZEOF(szDLLFile);
  190. HINSTANCE hInst = NULL;
  191. *ppfnDialogProc = NULL;
  192. if (ERROR_SUCCESS == SHGetValue(HKEY_CLASSES_ROOT, g_szWalletAddressDirKey, NULL, &dwType, (LPVOID)szDLLFile, &dwSize))
  193. {
  194. hInst = LoadLibrary(szDLLFile);
  195. // Will Fail if OCX is not installed.
  196. if (hInst)
  197. {
  198. *ppfnDialogProc = (PFN_DISPLAYWALLETADDRDIALOG_PROC) GetProcAddress(hInst, g_szWalletAddressFN);
  199. }
  200. }
  201. if (!*ppfnDialogProc && hInst)
  202. {
  203. FreeLibrary(hInst);
  204. hInst = NULL;
  205. }
  206. return hInst;
  207. }
  208. BOOL IsWallet3Installed()
  209. {
  210. HINSTANCE hInst;
  211. PFN_DISPLAYWALLETADDRDIALOG_PROC pfnDialogProc;
  212. BOOL fWallet3 = FALSE;
  213. hInst = GetWalletAddressDProc(&pfnDialogProc);
  214. if (hInst)
  215. {
  216. CHAR chPath[MAX_PATH];
  217. if (GetModuleFileNameA(hInst, chPath, ARRAYSIZE(chPath)))
  218. {
  219. DWORD dwMSVer, dwLSVer;
  220. if (SUCCEEDED(GetVersionFromFile(chPath, &dwMSVer, &dwLSVer, TRUE)))
  221. {
  222. if (dwMSVer >= 3)
  223. {
  224. fWallet3 = TRUE;
  225. }
  226. }
  227. }
  228. FreeLibrary(hInst);
  229. }
  230. return fWallet3;
  231. }
  232. BOOL IsWalletAddressAvailable(VOID)
  233. {
  234. HINSTANCE hInst;
  235. PFN_DISPLAYWALLETADDRDIALOG_PROC pfnDialogProc;
  236. BOOL fIsAvailable = FALSE;
  237. hInst = GetWalletAddressDProc(&pfnDialogProc);
  238. if (hInst)
  239. {
  240. fIsAvailable = TRUE;
  241. FreeLibrary(hInst);
  242. }
  243. return fIsAvailable;
  244. }
  245. VOID DisplayWalletAddressDialog(HWND hWnd)
  246. {
  247. HINSTANCE hInst;
  248. PFN_DISPLAYWALLETADDRDIALOG_PROC pfnDialogProc;
  249. hInst = GetWalletAddressDProc(&pfnDialogProc);
  250. if (hInst)
  251. {
  252. (*pfnDialogProc)(hWnd, NULL, NULL, 0);
  253. FreeLibrary(hInst);
  254. }
  255. }
  256. #endif
  257. //
  258. //
  259. //
  260. // "Programs" Tab
  261. //
  262. //
  263. //
  264. #ifndef UNIX
  265. //
  266. // RegPopulateComboBox()
  267. //
  268. // Takes an open HKEY (hkeyProtocol) and populates hwndCB with the friendly
  269. // names of clients. The currently selected client is the "(default)" key of
  270. // hkeyProtocol. The clients are sub-keys under the open key. The friendly
  271. // names of the clients are in the "(default)" value of these sub-keys. This
  272. // function also makes the currently selected client the selected item in
  273. // hwndCB and returns the index number to the item.
  274. //
  275. // History:
  276. //
  277. // 7/ 8/96 t-gpease created
  278. //
  279. UINT RegPopulateComboBox(HWND hwndCB, HKEY hkeyProtocol)
  280. {
  281. TCHAR szFriendlyName [MAX_PATH];
  282. TCHAR szKeyName [MAX_PATH];
  283. TCHAR szCurrent [MAX_PATH];
  284. TCHAR szFriendlyCurrent [MAX_PATH];
  285. FILETIME ftLastWriteTime;
  286. DWORD i; // Index counter
  287. HKEY hkeyClient;
  288. DWORD cb;
  289. // find the currently selected client
  290. cb = sizeof(szCurrent);
  291. if (RegQueryValueEx(hkeyProtocol, NULL, NULL, NULL, (LPBYTE)szCurrent, &cb)
  292. != ERROR_SUCCESS)
  293. {
  294. // if not found then blank the friendly name and keyname.
  295. szCurrent[0]=0;
  296. szFriendlyCurrent[0]=0;
  297. }
  298. // populate the dropdown
  299. for(i=0; // always start with 0
  300. cb=ARRAYSIZE(szKeyName), // string size
  301. ERROR_SUCCESS==RegEnumKeyEx(hkeyProtocol, i, szKeyName, &cb, NULL, NULL, NULL, &ftLastWriteTime);
  302. i++) // get next entry
  303. {
  304. // get the friendly name of the client
  305. if (RegOpenKeyEx(hkeyProtocol, szKeyName, 0, KEY_READ, &hkeyClient)==ERROR_SUCCESS)
  306. {
  307. cb = sizeof(szFriendlyName);
  308. if (RegQueryValueEx(hkeyClient, NULL, NULL, NULL, (LPBYTE)szFriendlyName, &cb)
  309. == ERROR_SUCCESS)
  310. {
  311. // add name to dropdown
  312. SendMessage(hwndCB, CB_ADDSTRING, 0, (LPARAM)szFriendlyName);
  313. // check to see if it's the current default
  314. if (!StrCmp(szKeyName, szCurrent))
  315. {
  316. // save its the friendly name which we'll use later to
  317. // select the current client and what index it is.
  318. StrCpyN(szFriendlyCurrent, szFriendlyName, ARRAYSIZE(szFriendlyCurrent));
  319. }
  320. }
  321. // close key
  322. RegCloseKey(hkeyClient);
  323. }
  324. } // for
  325. // select current client and get index number... just in case listboxes are sorted we
  326. // are doing this last.
  327. return (unsigned int) SendMessage(hwndCB, CB_SELECTSTRING, (WPARAM) 0, (LPARAM) szFriendlyCurrent);
  328. } // RegPopulateComboBox()
  329. #else
  330. #define RegPopulateComboBox RegPopulateEditText
  331. #endif /* UNIX */
  332. //
  333. // Adds the item and its associated HKEY in the combobox. Stores the hkey
  334. // as data associated with the item. Frees hkey if the item is already present
  335. // or if an error occurs.
  336. //
  337. BOOL AddItemToEditorsCombobox
  338. (
  339. HWND hwndCB,
  340. LPTSTR pszFriendlyName, // friendly name of the app
  341. HKEY hkey // location of assoc shell\edit verb
  342. )
  343. {
  344. ASSERT(pszFriendlyName);
  345. ASSERT(hkey);
  346. BOOL fRet = FALSE;
  347. // Only add if not already in combo
  348. if (SendMessage(hwndCB, CB_FINDSTRINGEXACT, -1, (LPARAM)pszFriendlyName) == CB_ERR)
  349. {
  350. // Add name to dropdown
  351. INT_PTR i = SendMessage(hwndCB, CB_ADDSTRING, 0, (LPARAM)pszFriendlyName);
  352. if (i >= 0)
  353. {
  354. fRet = (SendMessage(hwndCB, CB_SETITEMDATA, i, (LPARAM)hkey) != CB_ERR);
  355. }
  356. }
  357. if (!fRet)
  358. {
  359. RegCloseKey(hkey);
  360. }
  361. return fRet;
  362. }
  363. //
  364. // Adds the edit verb to the OpenWithList associated with .htm files.
  365. //
  366. void AddToOpenWithList(LPCTSTR pszFriendly, HKEY hkeyFrom, HKEY hkeyOpenWithList)
  367. {
  368. ASSERT(pszFriendly);
  369. ASSERT(hkeyFrom);
  370. if (NULL == hkeyOpenWithList)
  371. {
  372. return;
  373. }
  374. TCHAR szBuf[MAX_PATH];
  375. StrCpyN(szBuf, pszFriendly, ARRAYSIZE(szBuf));
  376. StrCatBuff(szBuf, TEXT("\\shell\\edit"), ARRAYSIZE(szBuf));
  377. DWORD dwDisposition;
  378. HKEY hkeyDest;
  379. if (hkeyOpenWithList &&
  380. ERROR_SUCCESS == RegCreateKeyEx(hkeyOpenWithList, szBuf, 0,
  381. NULL, 0, KEY_READ | KEY_WRITE, NULL, &hkeyDest, &dwDisposition))
  382. {
  383. // Copy everything under shell if this item did not exist
  384. if (dwDisposition == REG_CREATED_NEW_KEY)
  385. {
  386. SHCopyKey(hkeyFrom, L"shell\\edit", hkeyDest, 0);
  387. }
  388. RegCloseKey(hkeyDest);
  389. }
  390. }
  391. //
  392. // Returns TRUE if the verb
  393. //
  394. BOOL IsHtmlStub
  395. (
  396. HKEY hkeyVerb, // reg location of the shell\verb\command
  397. LPCWSTR pszVerb // verb to check for ("edit" or "open")
  398. )
  399. {
  400. BOOL fRet = FALSE;
  401. // We don't display programs that are simple redirectors (such as Office's msohtmed.exe)
  402. TCHAR sz[MAX_PATH];
  403. if (SUCCEEDED(AssocQueryStringByKey(ASSOCF_VERIFY, ASSOCSTR_EXECUTABLE, hkeyVerb, pszVerb, sz, (LPDWORD)MAKEINTRESOURCE(SIZECHARS(sz)))))
  404. {
  405. // Get the MULTISZ list of known redirectors
  406. TCHAR szRedir[MAX_PATH];
  407. ZeroInit(szRedir, ARRAYSIZE(szRedir)); // Protect against non-multisz strings in the reg
  408. DWORD dwType;
  409. DWORD cb = sizeof(szRedir) - 4;
  410. if (ERROR_SUCCESS != SHGetValue(HKEY_LOCAL_MACHINE, REGSTR_PATH_DEFAULT_HTML_EDITOR, L"Stubs", &dwType, szRedir, &cb))
  411. {
  412. // Nothing in registry, so default to ignore the Office redirector
  413. StrCpyN(szRedir, L"msohtmed.exe\0", ARRAYSIZE(szRedir));
  414. }
  415. // Compare exe name with list of redirectors
  416. LPCTSTR pszFile = PathFindFileName(sz);
  417. for (LPTSTR p = szRedir; *p != NULL; p += lstrlen(p) + 1)
  418. {
  419. if (StrCmpI(p, pszFile) == 0)
  420. {
  421. fRet = TRUE;
  422. break;
  423. }
  424. }
  425. }
  426. return fRet;
  427. }
  428. BOOL GetAppKey(LPCWSTR pszApp, HKEY *phkApp)
  429. {
  430. ASSERT(pszApp && *pszApp);
  431. WCHAR szKey[MAX_PATH];
  432. StrCpy(szKey, L"Applications\\");
  433. StrCatBuff(szKey, pszApp, SIZECHARS(szKey));
  434. return (NOERROR == RegOpenKeyEx(
  435. HKEY_CLASSES_ROOT,
  436. szKey,
  437. 0L,
  438. MAXIMUM_ALLOWED,
  439. phkApp));
  440. }
  441. //
  442. // Adds the html editors to the combobox. Looks for edit verbs associated
  443. // with the .htm extension, the .htm OpenWithList, and the current default
  444. // editor.
  445. //
  446. void PopulateEditorsCombobox(HWND hwndCB)
  447. {
  448. //
  449. // Add items from the OpenWithList for .htm
  450. //
  451. DWORD dw;
  452. HKEY hkeyOpenWithList = NULL;
  453. TCHAR szOpenWith[MAX_PATH];
  454. if (ERROR_SUCCESS == RegCreateKeyEx(HKEY_CLASSES_ROOT, L".htm\\OpenWithList", 0,
  455. NULL, 0, KEY_READ | KEY_WRITE, NULL, &hkeyOpenWithList, &dw))
  456. {
  457. //
  458. // First enumerate the entries in the OpenWithList
  459. //
  460. HKEY hkeyOpenWith = NULL;
  461. DWORD dwIndex = 0;
  462. DWORD dwSize = ARRAYSIZE(szOpenWith);
  463. while (ERROR_SUCCESS == RegEnumKeyEx(hkeyOpenWithList, dwIndex, szOpenWith, &dwSize, NULL, NULL, NULL, NULL))
  464. {
  465. if (GetAppKey(szOpenWith, &hkeyOpenWith))
  466. {
  467. // We only accept items that have an edit verb
  468. TCHAR sz[MAX_PATH];
  469. if (SUCCEEDED(AssocQueryStringByKey(ASSOCF_VERIFY, ASSOCSTR_FRIENDLYAPPNAME, hkeyOpenWith, L"edit", sz, (LPDWORD)MAKEINTRESOURCE(SIZECHARS(sz)))))
  470. {
  471. // Note that we store hkeyOpenWith in the combo so don't close it
  472. AddItemToEditorsCombobox(hwndCB, sz, hkeyOpenWith);
  473. }
  474. else
  475. {
  476. RegCloseKey(hkeyOpenWith);
  477. }
  478. }
  479. ++dwIndex;
  480. dwSize = ARRAYSIZE(szOpenWith);
  481. }
  482. // hkeyOpenWithList is closed below
  483. }
  484. //
  485. // Add the editor associated with .htm
  486. //
  487. HKEY hkeyHtm;
  488. // FEATURE - should use AssocCreate(IQueryAssociations) here instead
  489. if (SUCCEEDED(AssocQueryKey(0, ASSOCKEY_SHELLEXECCLASS, L".htm", NULL, &hkeyHtm)))
  490. {
  491. TCHAR sz[MAX_PATH];
  492. if (!IsHtmlStub(hkeyHtm, L"edit") &&
  493. SUCCEEDED(AssocQueryStringByKey(ASSOCF_VERIFY, ASSOCSTR_FRIENDLYAPPNAME, hkeyHtm, L"edit", sz, (LPDWORD)MAKEINTRESOURCE(SIZECHARS(sz)))))
  494. {
  495. AddItemToEditorsCombobox(hwndCB, sz, hkeyHtm);
  496. AddToOpenWithList(sz, hkeyHtm, hkeyOpenWithList);
  497. // Don't free the key we cached away
  498. hkeyHtm = NULL;
  499. }
  500. if (hkeyHtm)
  501. {
  502. RegCloseKey(hkeyHtm);
  503. }
  504. }
  505. //
  506. // Get the default editor. We check both hkcu & hklm.
  507. //
  508. HKEY hkeyDefault;
  509. if (ERROR_SUCCESS == RegOpenKeyEx(HKEY_CURRENT_USER, REGSTR_PATH_DEFAULT_HTML_EDITOR, 0, KEY_READ, &hkeyDefault) ||
  510. ERROR_SUCCESS == RegOpenKeyEx(HKEY_LOCAL_MACHINE, REGSTR_PATH_DEFAULT_HTML_EDITOR, 0, KEY_READ, &hkeyDefault))
  511. {
  512. TCHAR sz[MAX_PATH];
  513. if (SUCCEEDED(AssocQueryStringByKey(ASSOCF_VERIFY, ASSOCSTR_FRIENDLYAPPNAME, hkeyDefault, L"edit", sz, (LPDWORD)MAKEINTRESOURCE(SIZECHARS(sz)))))
  514. {
  515. // Add name to dropdown and save hkeyDefault in the combobox (so don't close it)
  516. AddItemToEditorsCombobox(hwndCB, sz, hkeyDefault);
  517. // Select this item
  518. SendMessage(hwndCB, CB_SELECTSTRING, -1, (LPARAM)sz);
  519. //
  520. // Make sure the default editor is in the htm OpenWithList so it doesn't dissapear
  521. // if we change it
  522. //
  523. AddToOpenWithList(sz, hkeyDefault, hkeyOpenWithList);
  524. }
  525. else
  526. {
  527. RegCloseKey(hkeyDefault);
  528. }
  529. }
  530. if (hkeyOpenWithList)
  531. {
  532. RegCloseKey(hkeyOpenWithList);
  533. }
  534. }
  535. //
  536. // ProgramsDlgInit()
  537. //
  538. // Does initalization for Programs Dlg.
  539. //
  540. // History:
  541. //
  542. // 6/17/96 t-gpease created
  543. // 7/ 8/96 t-gpease added Mail and News initialization
  544. //
  545. BOOL ProgramsDlgInit( HWND hDlg)
  546. {
  547. LPPROGRAMSPAGE pPrg;
  548. DWORD dw;
  549. HKEY hkey;
  550. pPrg = (LPPROGRAMSPAGE)LocalAlloc(LPTR, sizeof(*pPrg));
  551. if (!pPrg)
  552. {
  553. EndDialog(hDlg, 0);
  554. return FALSE; // no memory?
  555. }
  556. // tell dialog where to get info
  557. SetWindowLongPtr(hDlg, DWLP_USER, (LONG_PTR)pPrg);
  558. // save the handle to the page
  559. pPrg->hDlg = hDlg;
  560. //
  561. // Set default values.
  562. //
  563. #ifndef UNIX
  564. pPrg->bAssociationCheck = TRUE; // we want everybody to use IE!
  565. SUCCEEDED(CoCreateInstance(CLSID_FtpInstaller, NULL, CLSCTX_INPROC_SERVER, IID_IFtpInstaller, (void **) &pPrg->pfi));
  566. if (pPrg->pfi)
  567. pPrg->bIEIsFTPClient = ((S_OK == pPrg->pfi->IsIEDefautlFTPClient()) ? TRUE : FALSE);
  568. #endif
  569. pPrg->iMail = -1; // nothing selected
  570. pPrg->iNews = -1; // nothing selected
  571. #ifndef UNIX
  572. pPrg->bAssociationCheck = SHRegGetBoolUSValue(REGSTR_PATH_MAIN,REGSTR_VAL_CHECKASSOC,FALSE,TRUE);
  573. //
  574. // Get the html editors
  575. //
  576. pPrg->hwndHtmlEdit = GetDlgItem(pPrg->hDlg, IDC_PROGRAMS_HTMLEDITOR_COMBO);
  577. PopulateEditorsCombobox(pPrg->hwndHtmlEdit);
  578. // Sundown: coercion to int because 32b is sufficient for cursor selection
  579. pPrg->iHtmlEditor = (int) SendMessage(pPrg->hwndHtmlEdit, CB_GETCURSEL, 0, 0);
  580. //
  581. // Get the Mail Clients
  582. //
  583. pPrg->hwndMail = GetDlgItem(pPrg->hDlg, IDC_PROGRAMS_MAIL_COMBO);
  584. if (RegCreateKeyEx(HKEY_LOCAL_MACHINE, REGSTR_PATH_MAILCLIENTS,
  585. 0, NULL, 0, KEY_READ, NULL, &hkey, &dw) == ERROR_SUCCESS)
  586. #else
  587. pPrg->hwndMail = GetDlgItem(pPrg->hDlg, IDC_EDIT_PROGRAMS_MAIL);
  588. if (RegCreateKeyEx(HKEY_CURRENT_USER, REGSTR_PATH_MAILCLIENTS,
  589. 0, NULL, 0, KEY_READ, NULL, &hkey, &dw) == ERROR_SUCCESS)
  590. #endif
  591. {
  592. // populate the combobox
  593. pPrg->iMail = RegPopulateComboBox(pPrg->hwndMail, hkey);
  594. // close the keys
  595. RegCloseKey(hkey);
  596. }
  597. //
  598. // Get the News Clients
  599. //
  600. #ifndef UNIX
  601. pPrg->hwndNews = GetDlgItem(pPrg->hDlg, IDC_PROGRAMS_NEWS_COMBO);
  602. if (RegCreateKeyEx(HKEY_LOCAL_MACHINE, REGSTR_PATH_NEWSCLIENTS,
  603. 0, NULL, 0, KEY_READ, NULL, &hkey, &dw) == ERROR_SUCCESS)
  604. #else
  605. pPrg->hwndNews = GetDlgItem(pPrg->hDlg, IDC_EDIT_PROGRAMS_NEWS);
  606. if (RegCreateKeyEx(HKEY_CURRENT_USER, REGSTR_PATH_NEWSCLIENTS,
  607. 0, NULL, 0, KEY_READ, NULL, &hkey, &dw) == ERROR_SUCCESS)
  608. #endif
  609. {
  610. // populate the combobox
  611. pPrg->iNews = RegPopulateComboBox(pPrg->hwndNews, hkey);
  612. // close the keys
  613. RegCloseKey(hkey);
  614. }
  615. //
  616. // get the calendar clients
  617. //
  618. #ifndef UNIX
  619. pPrg->hwndCalendar = GetDlgItem(pPrg->hDlg, IDC_PROGRAMS_CALENDAR_COMBO);
  620. if (RegCreateKeyEx(HKEY_LOCAL_MACHINE, REGSTR_PATH_CALENDARCLIENTS,
  621. 0, NULL, 0, KEY_READ, NULL, &hkey, &dw) == ERROR_SUCCESS)
  622. {
  623. // populate the combobox
  624. pPrg->iCalendar = RegPopulateComboBox(pPrg->hwndCalendar, hkey);
  625. // close the keys
  626. RegCloseKey(hkey);
  627. }
  628. //
  629. // get the contacts clients
  630. //
  631. pPrg->hwndContact = GetDlgItem(pPrg->hDlg, IDC_PROGRAMS_CONTACT_COMBO);
  632. if (RegCreateKeyEx(HKEY_LOCAL_MACHINE, REGSTR_PATH_CONTACTCLIENTS,
  633. 0, NULL, 0, KEY_READ, NULL, &hkey, &dw) == ERROR_SUCCESS)
  634. {
  635. // populate the combobox
  636. pPrg->iContact = RegPopulateComboBox(pPrg->hwndContact, hkey);
  637. // close the keys
  638. RegCloseKey(hkey);
  639. }
  640. //
  641. // get the internet call clients
  642. //
  643. pPrg->hwndCall = GetDlgItem(pPrg->hDlg, IDC_PROGRAMS_CALL_COMBO);
  644. if (RegCreateKeyEx(HKEY_LOCAL_MACHINE, REGSTR_PATH_CALLCLIENTS,
  645. 0, NULL, 0, KEY_READ, NULL, &hkey, &dw) == ERROR_SUCCESS)
  646. {
  647. // populate the combobox
  648. pPrg->iCall = RegPopulateComboBox(pPrg->hwndCall, hkey);
  649. // close the keys
  650. RegCloseKey(hkey);
  651. }
  652. // Set dialog items
  653. CheckDlgButton(hDlg, IDC_CHECK_ASSOCIATIONS_CHECKBOX, pPrg->bAssociationCheck);
  654. HRESULT hrIEDefaultFTPClient = E_FAIL;
  655. if (pPrg->pfi)
  656. {
  657. hrIEDefaultFTPClient = pPrg->pfi->IsIEDefautlFTPClient();
  658. // Is this option not applicable because only the IE FTP client is installed?
  659. if (SUCCEEDED(hrIEDefaultFTPClient))
  660. CheckDlgButton(hDlg, IDC_PROGRAMS_IE_IS_FTPCLIENT, pPrg->bIEIsFTPClient);
  661. }
  662. if (FAILED(hrIEDefaultFTPClient))
  663. {
  664. // Yes, so remove the option.
  665. ShowWindow(GetDlgItem(hDlg, IDC_PROGRAMS_IE_IS_FTPCLIENT), SW_HIDE);
  666. }
  667. if( g_restrict.fMailNews )
  668. {
  669. EnableWindow( GetDlgItem(hDlg, IDC_PROGRAMS_MAIL_COMBO), FALSE);
  670. EnableWindow( GetDlgItem(hDlg, IDC_PROGRAMS_NEWS_COMBO), FALSE);
  671. EnableWindow( GetDlgItem(hDlg, IDC_PROGRAMS_CALL_COMBO), FALSE);
  672. }
  673. if ( g_restrict.fCalContact )
  674. {
  675. EnableWindow( GetDlgItem(hDlg, IDC_PROGRAMS_CALENDAR_COMBO), FALSE);
  676. EnableWindow( GetDlgItem(hDlg, IDC_PROGRAMS_CONTACT_COMBO), FALSE);
  677. }
  678. EnableWindow( GetDlgItem(hDlg, IDC_RESETWEBSETTINGS), !g_restrict.fResetWebSettings );
  679. EnableWindow( GetDlgItem(hDlg, IDC_CHECK_ASSOCIATIONS_CHECKBOX), !g_restrict.fDefault );
  680. #else /* !UNIX */
  681. pPrg->hwndVSource = GetDlgItem(pPrg->hDlg, IDC_EDIT_PROGRAMS_VSOURCE);
  682. pPrg->hwndMailFind = GetDlgItem(pPrg->hDlg, IDC_MAIL_FIND);
  683. pPrg->hwndMailEdit = GetDlgItem(pPrg->hDlg, IDC_MAIL_EDIT);
  684. pPrg->hwndNewsFind = GetDlgItem(pPrg->hDlg, IDC_NEWS_FIND);
  685. pPrg->hwndNewsEdit = GetDlgItem(pPrg->hDlg, IDC_NEWS_EDIT);
  686. pPrg->hwndEnableUseOEMail = GetDlgItem(pPrg->hDlg, IDC_OE_MAIL);
  687. pPrg->hwndEnableUseOENews = GetDlgItem(pPrg->hDlg, IDC_OE_NEWS);
  688. if (RegCreateKeyEx(HKEY_CURRENT_USER, REGSTR_PATH_VSOURCECLIENTS,
  689. 0, NULL, 0, KEY_READ, NULL, &hkey, &dw) == ERROR_SUCCESS)
  690. {
  691. // populate the combobox
  692. pPrg->iVSource = RegPopulateComboBox(pPrg->hwndVSource, hkey);
  693. // close the keys
  694. RegCloseKey(hkey);
  695. }
  696. // Set dialog items
  697. {
  698. // Look for the oexpress executable in the directory the
  699. // current process was executed from... Use the value for the
  700. // excutable name as stored in the registry for msimn.exe
  701. DWORD dwType;
  702. TCHAR szPresentName[MAX_PATH];
  703. DWORD dwSize = sizeof(szPresentName)/sizeof(szPresentName[0]);
  704. if (SHGetValue(IE_USE_OE_PRESENT_HKEY, IE_USE_OE_PRESENT_KEY,
  705. IE_USE_OE_PRESENT_VALUE, &dwType, (void*)szPresentName, &dwSize) ||
  706. (dwType != REG_SZ) || LocalFileCheck(szPresentName))
  707. {
  708. // Disable user's access to OE settings
  709. EnableWindow(pPrg->hwndEnableUseOEMail, FALSE);
  710. EnableWindow(pPrg->hwndEnableUseOENews, FALSE);
  711. // Reset the internal state of the Use OE check buttons
  712. pPrg->dwUseOEMail = FALSE;
  713. pPrg->dwUseOENews = FALSE;
  714. }
  715. else
  716. {
  717. // Reset the values of the check button for use OE MAIL
  718. // Based on registry values
  719. dwSize = sizeof(pPrg->dwUseOEMail);
  720. if (SHGetValue(IE_USE_OE_MAIL_HKEY, IE_USE_OE_MAIL_KEY,
  721. IE_USE_OE_MAIL_VALUE, &dwType, (void*)&pPrg->dwUseOEMail,
  722. &dwSize) || (dwType != REG_DWORD))
  723. {
  724. // The default value for mail is FALSE
  725. pPrg->dwUseOEMail = FALSE;
  726. }
  727. // Reset the UI elements
  728. CheckDlgButton(hDlg, IDC_OE_MAIL, pPrg->dwUseOEMail ? BST_CHECKED :
  729. BST_UNCHECKED);
  730. EnableWindow(pPrg->hwndMail, pPrg->dwUseOEMail ? FALSE : TRUE);
  731. EnableWindow(pPrg->hwndMailEdit, pPrg->dwUseOEMail ? FALSE : TRUE);
  732. EnableWindow(pPrg->hwndMailFind, pPrg->dwUseOEMail ? FALSE : TRUE);
  733. // Repeat the above for the NEWS settings
  734. dwSize = sizeof(pPrg->dwUseOENews);
  735. if (SHGetValue(IE_USE_OE_NEWS_HKEY, IE_USE_OE_NEWS_KEY,
  736. IE_USE_OE_NEWS_VALUE, &dwType, (void*)&pPrg->dwUseOENews,
  737. &dwSize) || (dwType != REG_DWORD))
  738. {
  739. // The default value for News is FALSE
  740. pPrg->dwUseOENews = FALSE;
  741. }
  742. CheckDlgButton(hDlg, IDC_OE_NEWS, pPrg->dwUseOENews ? BST_CHECKED :
  743. BST_UNCHECKED);
  744. EnableWindow(pPrg->hwndNews, pPrg->dwUseOENews ? FALSE : TRUE);
  745. EnableWindow(pPrg->hwndNewsEdit, pPrg->dwUseOENews ? FALSE : TRUE);
  746. EnableWindow(pPrg->hwndNewsFind, pPrg->dwUseOENews ? FALSE : TRUE);
  747. }
  748. }
  749. if( g_restrict.fMailNews )
  750. {
  751. EnableWindow( GetDlgItem(hDlg, IDC_EDIT_PROGRAMS_MAIL), FALSE);
  752. EnableWindow( GetDlgItem(hDlg, IDC_EDIT_PROGRAMS_NEWS), FALSE);
  753. EnableWindow( GetDlgItem(hDlg, IDC_EDIT_PROGRAMS_VSOURCE), FALSE);
  754. EnableWindow( GetDlgItem(hDlg, IDC_OE_MAIL), FALSE);
  755. EnableWindow( GetDlgItem(hDlg, IDC_OE_NEWS), FALSE);
  756. EnableWindow( GetDlgItem(hDlg, IDC_MAIL_FIND), FALSE);
  757. EnableWindow( GetDlgItem(hDlg, IDC_NEWS_FIND), FALSE);
  758. EnableWindow( GetDlgItem(hDlg, IDC_VSOURCE_FIND), FALSE);
  759. EnableWindow( GetDlgItem(hDlg, IDC_MAIL_EDIT), FALSE);
  760. EnableWindow( GetDlgItem(hDlg, IDC_NEWS_EDIT), FALSE);
  761. EnableWindow( GetDlgItem(hDlg, IDC_VSOURCE_EDIT), FALSE);
  762. }
  763. SendMessage( pPrg->hwndMail, EM_LIMITTEXT, MAX_PATH, 0 );
  764. SendMessage( pPrg->hwndNews, EM_LIMITTEXT, MAX_PATH, 0 );
  765. SendMessage( pPrg->hwndVSource, EM_LIMITTEXT, MAX_PATH, 0 );
  766. #endif /* !UNIX */
  767. return TRUE; // success
  768. } // ProgramsDlgInit()
  769. //
  770. // RegCopyKey()
  771. //
  772. // Copies all the keys from hkeySrc down into hkeyRoot:pszDest.
  773. //
  774. // History:
  775. //
  776. // 7/ 8/96 t-gpease created
  777. //
  778. void RegCopyKey(HKEY hkeyRoot, const TCHAR *pszDest, HKEY hkeySrc)
  779. {
  780. HKEY hkeyDest;
  781. HKEY hkey;
  782. DWORD dw;
  783. DWORD i;
  784. DWORD cb;
  785. DWORD cbData;
  786. DWORD Type;
  787. TCHAR szName[MAX_PATH];
  788. TCHAR szData[MAX_URL_STRING+1];
  789. // open/create the destination key
  790. if (RegCreateKeyEx(hkeyRoot, pszDest,
  791. NULL, 0, NULL, KEY_READ|KEY_WRITE, NULL, &hkeyDest, &dw) == ERROR_SUCCESS)
  792. {
  793. i=0;
  794. // copy values of the key
  795. while(1)
  796. {
  797. // find next value
  798. cb=ARRAYSIZE(szName);
  799. cbData=sizeof(szData);
  800. if (RegEnumValue(hkeySrc, i, szName, &cb, NULL, &Type, (LPBYTE)&szData, &cbData)!=ERROR_SUCCESS)
  801. break; // not found... exit loop
  802. // make a copy of the value in new location
  803. RegSetValueEx(hkeyDest, szName, NULL, Type, (CONST BYTE *)szData, cbData);
  804. #ifdef UNIX
  805. RegFlushKey(hkeyDest);
  806. #endif
  807. // increase index count
  808. i++;
  809. } // while
  810. // look for more sub-keys in the source
  811. for(i=0;
  812. cb=ARRAYSIZE(szName),
  813. RegEnumKey(hkeySrc, i, szName, cb)==ERROR_SUCCESS;
  814. i++)
  815. {
  816. // open the sub-key
  817. if (RegCreateKeyEx(hkeySrc, szName,
  818. NULL, 0, NULL, KEY_READ, NULL, &hkey, &dw) == ERROR_SUCCESS)
  819. {
  820. // copy the sub-key
  821. RegCopyKey(hkeyDest, szName, hkey);
  822. // close the key
  823. RegCloseKey(hkey);
  824. } // if RegCreateKey()
  825. } // for
  826. // close the key
  827. RegCloseKey(hkeyDest);
  828. } // if RegCreateKey()
  829. } // RegCopyKey()
  830. //
  831. // CopyInfoTo()
  832. //
  833. // Copies the information needed to run a mailto: or news: protocol
  834. //
  835. // History:
  836. //
  837. // 7/ 8/96 t-gpease created
  838. //
  839. void CopyInfoTo(const TCHAR *pszKeyName, HKEY hkeyClient)
  840. {
  841. HKEY hkey;
  842. TCHAR szName[MAX_PATH];
  843. // create the protocol sub-key path
  844. StrCpyN(szName, TSZPROTOCOLSPATH, ARRAYSIZE(szName));
  845. int len = lstrlen(szName);
  846. StrCpyN(szName + len, pszKeyName, ARRAYSIZE(szName) - len);
  847. // make sure it has the protocol we are looking for
  848. if (RegOpenKeyEx(hkeyClient, szName, NULL, KEY_READ|KEY_WRITE, &hkey)
  849. ==ERROR_SUCCESS)
  850. {
  851. // Netscape Messenger registry patch: they are missing "URL Protocol" in the HKLM mailto branch
  852. // and we should set this value, otherwise we get the 68992 bug. The source is changed rather
  853. // than the destination to protect against other programs copying the tree without the value.
  854. // Might as well check this for all clients rather than look for Netscape, since we don't
  855. // change any data if it exists.
  856. if (lstrcmpi(pszKeyName, TSZMAILTOPROTOCOL) == 0 &&
  857. RegQueryValueEx(hkey, TEXT("URL Protocol"), NULL, NULL, NULL, NULL) != ERROR_SUCCESS)
  858. {
  859. RegSetValueEx(hkey, TEXT("URL Protocol"), 0, REG_SZ, (BYTE *) TEXT(""), sizeof(TCHAR));
  860. }
  861. // start by deleting all the old info
  862. if ( lstrcmpi(pszKeyName, TSZLDAPPROTOCOL) )
  863. SHDeleteKey(HKEY_CLASSES_ROOT, pszKeyName);
  864. // recreate key and copy the protocol info
  865. RegCopyKey(HKEY_CLASSES_ROOT, pszKeyName, hkey);
  866. // close the key
  867. RegCloseKey(hkey);
  868. } // if RegOpenKey()
  869. } // CopyInfoTo()
  870. //
  871. // FindClient()
  872. //
  873. // Finds the currently selected item in hwndComboBox and locates it
  874. // in the szPath's subkeys. If found it will then make a call to copy
  875. // the information to szProtocol key under HKCR.
  876. //
  877. // History:
  878. //
  879. // 7/ 8/96 t-gpease created
  880. //
  881. void FindClient(LPCTSTR szProtocol, HWND hwndComboBox, int iSelected, LPCTSTR szPath)
  882. {
  883. TCHAR szFriendlyName[MAX_PATH];
  884. TCHAR szKeyName[MAX_PATH];
  885. TCHAR szCurrent[MAX_PATH];
  886. FILETIME ftLastWriteTime;
  887. DWORD i; // Index counter
  888. HKEY hkeyClient;
  889. HKEY hkey;
  890. DWORD dw;
  891. // get the name of the new client
  892. if (CB_ERR!=SendMessage(hwndComboBox, CB_GETLBTEXT, (WPARAM)iSelected, (LPARAM)szCurrent))
  893. {
  894. // got the friendly name... now lets find the internal name
  895. if (RegCreateKeyEx(HKEY_LOCAL_MACHINE, szPath,
  896. 0, NULL, 0, KEY_READ|KEY_WRITE, NULL, &hkey, &dw) == ERROR_SUCCESS)
  897. {
  898. DWORD cb;
  899. // we must search all the sub-keys for the correct friendly name
  900. for(i=0; // always start with 0
  901. cb=ARRAYSIZE(szKeyName), // string size
  902. ERROR_SUCCESS==RegEnumKeyEx(hkey, i, szKeyName, &cb, NULL, NULL, NULL, &ftLastWriteTime);
  903. i++) // get next entry
  904. {
  905. // get more info on the entry
  906. if (RegOpenKeyEx(hkey, szKeyName, 0, KEY_READ, &hkeyClient)==ERROR_SUCCESS)
  907. {
  908. // get the friendly name of the client
  909. cb = sizeof(szFriendlyName);
  910. if (RegQueryValueEx(hkeyClient, NULL, NULL, NULL, (LPBYTE)szFriendlyName, &cb)
  911. == ERROR_SUCCESS)
  912. {
  913. // is it the one we are looking for?
  914. if (!StrCmp(szFriendlyName, szCurrent))
  915. {
  916. // yep... copy its info
  917. CopyInfoTo(szProtocol, hkeyClient);
  918. // make it the default handler
  919. cb = (lstrlen(szKeyName) + 1)*sizeof(TCHAR);
  920. RegSetValueEx(hkey, NULL, NULL, REG_SZ, (LPBYTE)szKeyName, cb);
  921. }
  922. }
  923. // close key
  924. RegCloseKey(hkeyClient);
  925. } // if RegOpenKey()
  926. } // for
  927. // close the keys
  928. RegCloseKey(hkey);
  929. } // if RegCreateKeyEx()
  930. }
  931. } // FindClient()
  932. //
  933. // ProgramsDlgApplyNow()
  934. //
  935. // Enters "Programs" changes into registry.
  936. //
  937. // History:
  938. //
  939. // 6/20/96 t-gpease created
  940. // 7/ 8/96 t-gpease added Mail and News
  941. //
  942. void ProgramsDlgApplyNow(LPPROGRAMSPAGE pPrg)
  943. {
  944. int tmp;
  945. if (pPrg->fChanged)
  946. {
  947. #ifndef UNIX
  948. // Did the user have a chance to change this option?
  949. if (pPrg->pfi)
  950. {
  951. HRESULT hrIEDefaultFTPClient = pPrg->pfi->IsIEDefautlFTPClient();
  952. if (IsWindowVisible(GetDlgItem(pPrg->hDlg, IDC_PROGRAMS_IE_IS_FTPCLIENT)))
  953. {
  954. // Yes, so see if they changed it.
  955. pPrg->bIEIsFTPClient = IsDlgButtonChecked(pPrg->hDlg, IDC_PROGRAMS_IE_IS_FTPCLIENT);
  956. // Did they user want IE as default and currently someone else is?
  957. if (pPrg->bIEIsFTPClient && (S_FALSE == hrIEDefaultFTPClient))
  958. pPrg->pfi->MakeIEDefautlFTPClient();
  959. // Did they user NOT want IE as default and it currently is?
  960. if (!pPrg->bIEIsFTPClient && (S_OK == hrIEDefaultFTPClient))
  961. pPrg->pfi->RestoreFTPClient();
  962. }
  963. }
  964. pPrg->bAssociationCheck = IsDlgButtonChecked(pPrg->hDlg, IDC_CHECK_ASSOCIATIONS_CHECKBOX);
  965. TCHAR szYesNo[5];
  966. StrCpyN(szYesNo, (pPrg->bAssociationCheck ? TEXT("yes") : TEXT("no")), ARRAYSIZE(szYesNo));
  967. SHRegSetUSValue(REGSTR_PATH_MAIN,
  968. REGSTR_VAL_CHECKASSOC,
  969. REG_SZ,
  970. (LPVOID)szYesNo,
  971. (lstrlen(szYesNo)+1)*sizeof(TCHAR),
  972. SHREGSET_DEFAULT);
  973. #else
  974. // Set if OE in use
  975. SHSetValue(IE_USE_OE_MAIL_HKEY, IE_USE_OE_MAIL_KEY,
  976. IE_USE_OE_MAIL_VALUE, REG_DWORD, (void*)&pPrg->dwUseOEMail,
  977. sizeof(pPrg->dwUseOEMail));
  978. // Set if OE in use
  979. SHSetValue(IE_USE_OE_NEWS_HKEY, IE_USE_OE_NEWS_KEY,
  980. IE_USE_OE_NEWS_VALUE, REG_DWORD, (void*)&pPrg->dwUseOENews,
  981. sizeof(pPrg->dwUseOENews));
  982. #endif
  983. //
  984. // Save the new default editor
  985. //
  986. #ifndef UNIX
  987. // See if the selection was changed
  988. tmp = (int) SendMessage(pPrg->hwndHtmlEdit, CB_GETCURSEL, 0, 0);
  989. if (tmp != pPrg->iHtmlEditor)
  990. {
  991. pPrg->iHtmlEditor = tmp;
  992. // Get the text and hkey for the selected item
  993. WCHAR szDefault[MAX_PATH];
  994. SendMessage(pPrg->hwndHtmlEdit, CB_GETLBTEXT, tmp, (LPARAM)szDefault);
  995. HKEY hkeyFrom = (HKEY)SendMessage(pPrg->hwndHtmlEdit, CB_GETITEMDATA, tmp, 0);
  996. if (hkeyFrom && (INT_PTR)hkeyFrom != CB_ERR)
  997. {
  998. //
  999. // Save the selected item as the default editor
  1000. //
  1001. DWORD dw;
  1002. HKEY hkeyDest;
  1003. if (ERROR_SUCCESS == RegCreateKeyEx(HKEY_CURRENT_USER, REGSTR_PATH_DEFAULT_HTML_EDITOR, 0,
  1004. NULL, 0, KEY_READ | KEY_WRITE, NULL, &hkeyDest, &dw))
  1005. {
  1006. // Update the name of the default editor
  1007. SHSetValue(hkeyDest, NULL, L"Description", REG_SZ, szDefault, CbFromCch(lstrlen(szDefault)+1));
  1008. // Delete the old shell command (and all subkeys). This purges keys such as DDEEXEC.
  1009. SHDeleteKey(hkeyDest, L"shell");
  1010. // Update the verb of the default editor
  1011. HKEY hkeyEdit;
  1012. if (ERROR_SUCCESS == RegCreateKeyEx(hkeyDest, L"shell\\edit", 0,
  1013. NULL, 0, KEY_READ | KEY_WRITE, NULL, &hkeyEdit, &dw))
  1014. {
  1015. SHCopyKey(hkeyFrom, L"shell\\edit", hkeyEdit, 0);
  1016. RegCloseKey(hkeyEdit);
  1017. }
  1018. RegCloseKey(hkeyDest);
  1019. }
  1020. //
  1021. // Also update Office's default editor
  1022. //
  1023. if (ERROR_SUCCESS == RegCreateKeyEx(HKEY_CURRENT_USER, L"Software\\Microsoft\\Shared\\HTML\\Default Editor", 0,
  1024. NULL, 0, KEY_READ | KEY_WRITE, NULL, &hkeyDest, &dw))
  1025. {
  1026. // Delete the old shell command (and all subkeys). This purges keys such as DDEEXEC.
  1027. SHDeleteKey(hkeyDest, L"shell\\edit");
  1028. // Update the verb of the default editor
  1029. HKEY hkeyEdit;
  1030. if (ERROR_SUCCESS == RegCreateKeyEx(hkeyDest, L"shell\\edit", 0,
  1031. NULL, 0, KEY_READ | KEY_WRITE, NULL, &hkeyEdit, &dw))
  1032. {
  1033. SHCopyKey(hkeyFrom, L"shell\\edit", hkeyEdit, 0);
  1034. RegCloseKey(hkeyEdit);
  1035. }
  1036. RegCloseKey(hkeyDest);
  1037. }
  1038. //
  1039. // Finally, update the edit verb for .htm files so that the shell honors the change.
  1040. // But if .htm uses a stub like moshtmed, we leave it alone and assume that it
  1041. // uses one of the above keys as the default editor.
  1042. //
  1043. HKEY hkeyHtm;
  1044. if (SUCCEEDED(AssocQueryKey(0, ASSOCKEY_SHELLEXECCLASS, L".htm", NULL, &hkeyHtm)))
  1045. {
  1046. if (!IsHtmlStub(hkeyHtm, L"edit"))
  1047. {
  1048. // Delete the old shell command (and all subkeys). This purges keys such as DDEEXEC.
  1049. SHDeleteKey(hkeyHtm, L"shell\\edit");
  1050. // Copy the edit verb to the .htm
  1051. HKEY hkeyEdit;
  1052. if (ERROR_SUCCESS == RegCreateKeyEx(hkeyHtm, L"shell\\edit", 0,
  1053. NULL, 0, KEY_READ | KEY_WRITE, NULL, &hkeyEdit, &dw))
  1054. {
  1055. SHCopyKey(hkeyFrom, L"shell\\edit", hkeyEdit, 0);
  1056. RegCloseKey(hkeyEdit);
  1057. }
  1058. }
  1059. RegCloseKey(hkeyHtm);
  1060. }
  1061. }
  1062. }
  1063. #endif //!UNIX
  1064. //
  1065. // Save Mail Client Info
  1066. //
  1067. // is there a new client?
  1068. #ifndef UNIX
  1069. tmp = (int) SendMessage(pPrg->hwndMail, CB_GETCURSEL, 0, 0);
  1070. if (tmp!=pPrg->iMail)
  1071. {
  1072. pPrg->iMail = tmp;
  1073. // find it and copy its info
  1074. FindClient(TSZMAILTOPROTOCOL, pPrg->hwndMail, tmp, REGSTR_PATH_MAILCLIENTS);
  1075. //Update the mail icon label
  1076. UpdateMailIconLabel();
  1077. #else
  1078. if (pPrg->iMail)
  1079. {
  1080. // copy its info
  1081. FindEditClient(TSZMAILTOPROTOCOL, pPrg->hDlg, IDC_EDIT_PROGRAMS_MAIL,
  1082. REGSTR_PATH_MAILCLIENTS);
  1083. #endif
  1084. // tell the world that something has changed
  1085. SendBroadcastMessage(WM_WININICHANGE, 0, (LPARAM)REGSTR_PATH_MAILCLIENTS);
  1086. }
  1087. //
  1088. // Save News Client Info
  1089. //
  1090. // is there a new client?
  1091. #ifndef UNIX
  1092. tmp = (int) SendMessage(pPrg->hwndNews, CB_GETCURSEL, 0, 0);
  1093. if (tmp!=pPrg->iNews)
  1094. {
  1095. pPrg->iNews = tmp;
  1096. // find it and copy its info
  1097. FindClient(TSZNEWSPROTOCOL, pPrg->hwndNews, tmp, REGSTR_PATH_NEWSCLIENTS);
  1098. FindClient(TEXT("snews"), pPrg->hwndNews, tmp, REGSTR_PATH_NEWSCLIENTS);
  1099. FindClient(TEXT("nntp"), pPrg->hwndNews, tmp, REGSTR_PATH_NEWSCLIENTS);
  1100. #else
  1101. if (pPrg->iNews)
  1102. {
  1103. // copy its info
  1104. FindEditClient(TSZNEWSPROTOCOL, pPrg->hDlg, IDC_EDIT_PROGRAMS_NEWS,
  1105. REGSTR_PATH_NEWSCLIENTS);
  1106. //FindEditClient(TEXT("snews"), pPrg->hwndNews, REGSTR_PATH_NEWSCLIENTS);
  1107. //FindEditClient(TEXT("nntp"), pPrg->hwndNews, REGSTR_PATH_NEWSCLIENTS);
  1108. #endif
  1109. // tell the world that something has changed
  1110. SendBroadcastMessage(WM_WININICHANGE, 0, (LPARAM)REGSTR_PATH_NEWSCLIENTS);
  1111. }
  1112. //
  1113. // Save Internet Call Client info
  1114. //
  1115. // is there a new client?
  1116. #ifndef UNIX
  1117. tmp = (int) SendMessage(pPrg->hwndCall, CB_GETCURSEL, 0, 0);
  1118. if (tmp!=pPrg->iCall)
  1119. {
  1120. pPrg->iCall = tmp;
  1121. // find it and copy its info
  1122. FindClient(TSZCALLTOPROTOCOL, pPrg->hwndCall, tmp, REGSTR_PATH_CALLCLIENTS);
  1123. // tell the world that something has changed
  1124. SendBroadcastMessage(WM_WININICHANGE, 0, (LPARAM)REGSTR_PATH_CALLCLIENTS);
  1125. }
  1126. #else
  1127. if (pPrg->iVSource)
  1128. {
  1129. // copy its info
  1130. FindEditClient(TSZVSOURCEPROTOCOL, pPrg->hDlg, IDC_EDIT_PROGRAMS_VSOURCE,
  1131. REGSTR_PATH_VSOURCECLIENTS);
  1132. // tell the world that something has changed
  1133. SendBroadcastMessage(WM_WININICHANGE, 0, (LPARAM)REGSTR_PATH_VSOURCECLIENTS);
  1134. }
  1135. #endif
  1136. #ifndef UNIX
  1137. //
  1138. // Save Contacts Client Info
  1139. //
  1140. // is there a new client?
  1141. tmp = (int) SendMessage(pPrg->hwndContact, CB_GETCURSEL, 0, 0);
  1142. if (tmp!=pPrg->iContact)
  1143. {
  1144. pPrg->iContact = tmp;
  1145. // find it and copy its info
  1146. FindClient(TSZLDAPPROTOCOL, pPrg->hwndContact, tmp, REGSTR_PATH_CONTACTCLIENTS);
  1147. // tell the world that something has changed
  1148. SendBroadcastMessage(WM_WININICHANGE, 0, (LPARAM)REGSTR_PATH_CONTACTCLIENTS);
  1149. }
  1150. //
  1151. // Save Calendar Client Info
  1152. //
  1153. // is there a new client?
  1154. tmp = (int) SendMessage(pPrg->hwndCalendar, CB_GETCURSEL, 0, 0);
  1155. if (tmp!=pPrg->iCalendar)
  1156. {
  1157. pPrg->iCalendar = tmp;
  1158. // find it and copy its info
  1159. FindClient(TSZCALENDARPROTOCOL, pPrg->hwndCalendar, tmp, REGSTR_PATH_CALENDARCLIENTS);
  1160. // tell the world that something has changed
  1161. SendBroadcastMessage(WM_WININICHANGE, 0, (LPARAM)REGSTR_PATH_CALENDARCLIENTS);
  1162. }
  1163. #endif
  1164. UpdateAllWindows();
  1165. pPrg->fChanged = FALSE;
  1166. }
  1167. } // ProgramsDlgApplyNow()
  1168. extern HRESULT ResetWebSettings(HWND hwnd, BOOL *pfChangedHomePage);
  1169. #ifndef UNIX
  1170. //
  1171. // ProgramsOnCommand()
  1172. //
  1173. // Handles "Programs" property page's window commands
  1174. //
  1175. // History:
  1176. //
  1177. // 6/20/96 t-gpease created
  1178. //
  1179. void ProgramsOnCommand(LPPROGRAMSPAGE pPrg, UINT id, UINT nCmd)
  1180. {
  1181. switch (id) {
  1182. case IDC_PROGRAMS_HTMLEDITOR_COMBO:
  1183. {
  1184. INT_PTR tmp;
  1185. // Is there a new editor?
  1186. tmp = SendMessage(pPrg->hwndHtmlEdit, CB_GETCURSEL, 0, 0);
  1187. if (tmp != pPrg->iHtmlEditor)
  1188. {
  1189. ENABLEAPPLY(pPrg->hDlg);
  1190. pPrg->fChanged = TRUE;
  1191. }
  1192. }
  1193. break;
  1194. case IDC_PROGRAMS_NEWS_COMBO:
  1195. {
  1196. INT_PTR tmp;
  1197. // is there a new client?
  1198. tmp = SendMessage(pPrg->hwndNews, CB_GETCURSEL, 0, 0);
  1199. if (tmp != pPrg->iNews)
  1200. {
  1201. ENABLEAPPLY(pPrg->hDlg);
  1202. pPrg->fChanged = TRUE;
  1203. }
  1204. }
  1205. break;
  1206. case IDC_PROGRAMS_MAIL_COMBO:
  1207. {
  1208. INT_PTR tmp;
  1209. // is there a new client?
  1210. tmp = SendMessage(pPrg->hwndMail, CB_GETCURSEL, 0, 0);
  1211. if (tmp != pPrg->iMail)
  1212. {
  1213. ENABLEAPPLY(pPrg->hDlg);
  1214. pPrg->fChanged = TRUE;
  1215. }
  1216. }
  1217. break;
  1218. case IDC_PROGRAMS_CALENDAR_COMBO:
  1219. {
  1220. INT_PTR tmp;
  1221. // is there a new client?
  1222. tmp = SendMessage(pPrg->hwndCalendar, CB_GETCURSEL, 0, 0);
  1223. if (tmp != pPrg->iCalendar)
  1224. {
  1225. ENABLEAPPLY(pPrg->hDlg);
  1226. pPrg->fChanged = TRUE;
  1227. }
  1228. }
  1229. break;
  1230. case IDC_PROGRAMS_CONTACT_COMBO:
  1231. {
  1232. INT_PTR tmp;
  1233. // is there a new client?
  1234. tmp = SendMessage(pPrg->hwndContact, CB_GETCURSEL, 0, 0);
  1235. if (tmp != pPrg->iContact)
  1236. {
  1237. ENABLEAPPLY(pPrg->hDlg);
  1238. pPrg->fChanged = TRUE;
  1239. }
  1240. }
  1241. break;
  1242. case IDC_PROGRAMS_CALL_COMBO:
  1243. {
  1244. INT_PTR tmp;
  1245. // is there a new client?
  1246. tmp = SendMessage(pPrg->hwndCall, CB_GETCURSEL, 0, 0);
  1247. if (tmp != pPrg->iCall)
  1248. {
  1249. ENABLEAPPLY(pPrg->hDlg);
  1250. pPrg->fChanged = TRUE;
  1251. }
  1252. }
  1253. break;
  1254. case IDC_RESETWEBSETTINGS:
  1255. {
  1256. BOOL fReloadHomePage;
  1257. ResetWebSettings(pPrg->hDlg,&fReloadHomePage);
  1258. if (fReloadHomePage)
  1259. g_fReloadHomePage = TRUE;
  1260. }
  1261. break;
  1262. case IDC_PROGRAMS_IE_IS_FTPCLIENT:
  1263. case IDC_CHECK_ASSOCIATIONS_CHECKBOX:
  1264. ENABLEAPPLY(pPrg->hDlg);
  1265. pPrg->fChanged = TRUE;
  1266. break;
  1267. } // switch
  1268. } // ProgramsOnCommand()
  1269. #else /* !UNIX */
  1270. //
  1271. // ProgramsOnCommand()
  1272. //
  1273. // Handles "Programs" property page's window commands
  1274. //
  1275. // History:
  1276. //
  1277. // 6/20/96 t-gpease created
  1278. //
  1279. void ProgramsOnCommand(LPPROGRAMSPAGE pPrg, UINT id, UINT nCmd)
  1280. {
  1281. switch (id) {
  1282. case IDC_EDIT_PROGRAMS_MAIL:
  1283. {
  1284. if (nCmd == EN_CHANGE)
  1285. {
  1286. if (pPrg->iMail != -1)
  1287. {
  1288. ENABLEAPPLY(pPrg->hDlg);
  1289. pPrg->iMail = 1; //change has occoured
  1290. pPrg->fChanged = TRUE;
  1291. }
  1292. }
  1293. }
  1294. break;
  1295. case IDC_OE_MAIL:
  1296. {
  1297. pPrg->dwUseOEMail = IsDlgButtonChecked(pPrg->hDlg,
  1298. IDC_OE_MAIL) == BST_CHECKED;
  1299. ENABLEAPPLY(pPrg->hDlg);
  1300. pPrg->fChanged = TRUE;
  1301. EnableWindow(pPrg->hwndMail, !pPrg->dwUseOEMail);
  1302. EnableWindow(pPrg->hwndMailEdit, !pPrg->dwUseOEMail);
  1303. EnableWindow(pPrg->hwndMailFind, !pPrg->dwUseOEMail);
  1304. }
  1305. break;
  1306. case IDC_EDIT_PROGRAMS_NEWS:
  1307. {
  1308. if (nCmd == EN_CHANGE)
  1309. {
  1310. if (pPrg->iNews != -1)
  1311. {
  1312. ENABLEAPPLY(pPrg->hDlg);
  1313. pPrg->iNews = 1; //change has occoured
  1314. pPrg->fChanged = TRUE;
  1315. }
  1316. }
  1317. }
  1318. break;
  1319. case IDC_OE_NEWS:
  1320. {
  1321. pPrg->dwUseOENews = IsDlgButtonChecked(pPrg->hDlg,
  1322. IDC_OE_NEWS) == BST_CHECKED;
  1323. ENABLEAPPLY(pPrg->hDlg);
  1324. pPrg->fChanged = TRUE;
  1325. EnableWindow(pPrg->hwndNews, !pPrg->dwUseOENews);
  1326. EnableWindow(pPrg->hwndNewsEdit, !pPrg->dwUseOENews);
  1327. EnableWindow(pPrg->hwndNewsFind, !pPrg->dwUseOENews);
  1328. }
  1329. break;
  1330. case IDC_EDIT_PROGRAMS_VSOURCE:
  1331. {
  1332. if (nCmd == EN_CHANGE)
  1333. {
  1334. if (pPrg->iVSource != -1)
  1335. {
  1336. ENABLEAPPLY(pPrg->hDlg);
  1337. pPrg->iVSource = 1; //change has occoured
  1338. pPrg->fChanged = TRUE;
  1339. }
  1340. }
  1341. }
  1342. break;
  1343. case IDC_MAIL_EDIT:
  1344. {
  1345. HKEY hkeyProtocol;
  1346. DWORD dw;
  1347. if (RegCreateKeyEx(HKEY_CURRENT_USER, REGSTR_PATH_MAILCLIENTS,
  1348. 0, NULL, 0, KEY_READ, NULL, &hkeyProtocol, &dw) != ERROR_SUCCESS)
  1349. break;
  1350. EditScript(hkeyProtocol);
  1351. RegCloseKey(hkeyProtocol);
  1352. }
  1353. break;
  1354. case IDC_NEWS_EDIT:
  1355. {
  1356. HKEY hkeyProtocol;
  1357. DWORD dw;
  1358. if (RegCreateKeyEx(HKEY_CURRENT_USER, REGSTR_PATH_NEWSCLIENTS,
  1359. 0, NULL, 0, KEY_READ, NULL, &hkeyProtocol, &dw) != ERROR_SUCCESS)
  1360. break;
  1361. EditScript(hkeyProtocol);
  1362. RegCloseKey(hkeyProtocol);
  1363. }
  1364. break;
  1365. case IDC_VSOURCE_EDIT:
  1366. {
  1367. HKEY hkeyProtocol;
  1368. DWORD dw;
  1369. if (RegCreateKeyEx(HKEY_CURRENT_USER, REGSTR_PATH_VSOURCECLIENTS,
  1370. 0, NULL, 0, KEY_READ, NULL, &hkeyProtocol, &dw) != ERROR_SUCCESS)
  1371. break;
  1372. EditScript(hkeyProtocol);
  1373. RegCloseKey(hkeyProtocol);
  1374. }
  1375. break;
  1376. case IDC_MAIL_FIND:
  1377. {
  1378. HKEY hkeyProtocol;
  1379. DWORD dw;
  1380. if (RegCreateKeyEx(HKEY_CURRENT_USER, REGSTR_PATH_MAILCLIENTS,
  1381. 0, NULL, 0, KEY_READ, NULL, &hkeyProtocol, &dw) != ERROR_SUCCESS)
  1382. break;
  1383. FindScript(pPrg->hwndMail, hkeyProtocol);
  1384. RegCloseKey(hkeyProtocol);
  1385. }
  1386. break;
  1387. case IDC_NEWS_FIND:
  1388. {
  1389. HKEY hkeyProtocol;
  1390. DWORD dw;
  1391. if (RegCreateKeyEx(HKEY_CURRENT_USER, REGSTR_PATH_NEWSCLIENTS,
  1392. 0, NULL, 0, KEY_READ, NULL, &hkeyProtocol, &dw) != ERROR_SUCCESS)
  1393. break;
  1394. FindScript(pPrg->hwndNews, hkeyProtocol);
  1395. RegCloseKey(hkeyProtocol);
  1396. }
  1397. break;
  1398. case IDC_VSOURCE_FIND:
  1399. {
  1400. HKEY hkeyProtocol;
  1401. DWORD dw;
  1402. if (RegCreateKeyEx(HKEY_CURRENT_USER, REGSTR_PATH_VSOURCECLIENTS,
  1403. 0, NULL, 0, KEY_READ, NULL, &hkeyProtocol, &dw) != ERROR_SUCCESS)
  1404. break;
  1405. FindScript(pPrg->hwndVSource, hkeyProtocol);
  1406. RegCloseKey(hkeyProtocol);
  1407. }
  1408. break;
  1409. } // switch
  1410. } // ProgramsOnCommand()
  1411. #endif /* !UNIX */
  1412. //
  1413. // ProgramsDlgProc()
  1414. //
  1415. // Handles window messages sent to the Programs Property Sheet.
  1416. //
  1417. // History:
  1418. //
  1419. // 6/20/96 t-gpease created
  1420. //
  1421. INT_PTR CALLBACK ProgramsDlgProc(HWND hDlg, UINT uMsg, WPARAM wParam,
  1422. LPARAM lParam)
  1423. {
  1424. LPPROGRAMSPAGE pPrg;
  1425. if (uMsg == WM_INITDIALOG)
  1426. return ProgramsDlgInit( hDlg );
  1427. else
  1428. pPrg= (LPPROGRAMSPAGE) GetWindowLongPtr(hDlg, DWLP_USER);
  1429. if (!pPrg)
  1430. return FALSE;
  1431. switch (uMsg) {
  1432. case WM_COMMAND:
  1433. ProgramsOnCommand(pPrg, LOWORD(wParam), HIWORD(wParam));
  1434. return TRUE;
  1435. case WM_NOTIFY:
  1436. {
  1437. NMHDR *lpnm = (NMHDR *) lParam;
  1438. ASSERT(lpnm);
  1439. switch (lpnm->code)
  1440. {
  1441. case PSN_KILLACTIVE:
  1442. #ifdef UNIX
  1443. if (!(FoundProgram(pPrg->hDlg, IDC_EDIT_PROGRAMS_MAIL) &&
  1444. FoundProgram(pPrg->hDlg, IDC_EDIT_PROGRAMS_NEWS) &&
  1445. FoundProgram(pPrg->hDlg, IDC_EDIT_PROGRAMS_VSOURCE)))
  1446. {
  1447. MessageBox(pPrg->hDlg, TEXT("One (or more) program is not found or not executable."), NULL, MB_OK);
  1448. SetWindowLongPtr(hDlg, DWLP_MSGRESULT, TRUE);
  1449. return TRUE;
  1450. }
  1451. SetWindowLongPtr(hDlg, DWLP_MSGRESULT, FALSE);
  1452. return TRUE;
  1453. #endif //UNIX
  1454. case PSN_QUERYCANCEL:
  1455. case PSN_RESET:
  1456. SetWindowLongPtr(hDlg, DWLP_MSGRESULT, FALSE);
  1457. return TRUE;
  1458. case PSN_APPLY:
  1459. //
  1460. // Save Programs Dlg Stuff.
  1461. //
  1462. ProgramsDlgApplyNow(pPrg);
  1463. break;
  1464. }
  1465. }
  1466. break;
  1467. case WM_HELP: // F1
  1468. ResWinHelp( (HWND)((LPHELPINFO)lParam)->hItemHandle, IDS_HELPFILE,
  1469. HELP_WM_HELP, (DWORD_PTR)(LPSTR)mapIDCsToIDHs);
  1470. break;
  1471. case WM_CONTEXTMENU: // right mouse click
  1472. ResWinHelp( (HWND) wParam, IDS_HELPFILE,
  1473. HELP_CONTEXTMENU, (DWORD_PTR)(LPSTR)mapIDCsToIDHs);
  1474. break;
  1475. case WM_DESTROY:
  1476. {
  1477. #ifndef UNIX
  1478. // Free the data stored the HTML editor combo
  1479. int iMax = (int) SendMessage(pPrg->hwndHtmlEdit, CB_GETCOUNT, 0, 0);
  1480. HKEY hkey;
  1481. for (int i = 0; i < iMax; ++i)
  1482. {
  1483. hkey = (HKEY) SendMessage(pPrg->hwndHtmlEdit, CB_GETITEMDATA, i, 0);
  1484. if (hkey && (INT_PTR)hkey != CB_ERR)
  1485. {
  1486. RegCloseKey(hkey);
  1487. }
  1488. }
  1489. if (pPrg)
  1490. {
  1491. if (pPrg->pfi)
  1492. pPrg->pfi->Release();
  1493. LocalFree(pPrg);
  1494. }
  1495. #endif
  1496. SetWindowLongPtr(hDlg, DWLP_USER, (LONG)NULL);
  1497. break;
  1498. }
  1499. }
  1500. return FALSE;
  1501. }
  1502. static const TCHAR c_szMailIcon[] = TEXT("Software\\Microsoft\\MailIcon");
  1503. static const TCHAR c_szMailIconGuid[] = TEXT("CLSID\\{dacf95b0-0a3f-11d1-9389-006097d503d9}");
  1504. static const TCHAR c_szKeyMail[] = TEXT("Software\\Clients\\Mail");
  1505. static const TCHAR c_szRegFmt2[] = TEXT("%s\\%s");
  1506. static const TCHAR c_szFormatClient[] = TEXT("FormatClient");
  1507. static const TCHAR c_szFormatNoClient[] = TEXT("FormatNoClient");
  1508. static WCHAR c_wszMailIconGuid[] = L"::{dacf95b0-0a3f-11d1-9389-006097d503d9}";
  1509. void UpdateMailIconLabel()
  1510. {
  1511. TCHAR szOldLabel[MAX_PATH];
  1512. TCHAR szNewLabel[MAX_PATH];
  1513. TCHAR szDefClient[MAX_PATH];
  1514. TCHAR szTemp[MAX_PATH];
  1515. DWORD cbSize;
  1516. HKEY hKey;
  1517. *szNewLabel = 0;
  1518. *szOldLabel = 0;
  1519. // check if the mail icon is even installed
  1520. if (ERROR_SUCCESS == RegOpenKeyEx(HKEY_LOCAL_MACHINE, c_szMailIcon, 0, KEY_READ, &hKey))
  1521. {
  1522. cbSize = sizeof(szOldLabel);
  1523. // get the current mail icon label
  1524. if (ERROR_SUCCESS == RegQueryValue(HKEY_CLASSES_ROOT, c_szMailIconGuid, szOldLabel, (PLONG)&cbSize))
  1525. {
  1526. cbSize = sizeof(szDefClient);
  1527. // get the default client's reg key
  1528. if (ERROR_SUCCESS == RegQueryValue(HKEY_LOCAL_MACHINE, c_szKeyMail, szDefClient, (PLONG)&cbSize) && cbSize)
  1529. {
  1530. wnsprintf(szTemp, ARRAYSIZE(szTemp), c_szRegFmt2, c_szKeyMail, szDefClient);
  1531. cbSize = sizeof(szDefClient);
  1532. // get the default client's display name
  1533. if (ERROR_SUCCESS == RegQueryValue(HKEY_LOCAL_MACHINE, szTemp, szDefClient, (PLONG)&cbSize) && cbSize)
  1534. {
  1535. cbSize = sizeof(szTemp);
  1536. // get the mail icon label format string
  1537. if (ERROR_SUCCESS == RegQueryValueEx(hKey, c_szFormatClient, 0, NULL, (LPBYTE)szTemp, &cbSize))
  1538. {
  1539. wnsprintf(szNewLabel, ARRAYSIZE(szNewLabel), szTemp, szDefClient);
  1540. }
  1541. }
  1542. }
  1543. else
  1544. {
  1545. cbSize = sizeof(szNewLabel);
  1546. // get the mail icon label format string
  1547. RegQueryValueEx(hKey, c_szFormatNoClient, 0, NULL, (LPBYTE)szNewLabel, &cbSize);
  1548. }
  1549. }
  1550. // if the above succeeded, and the label is different
  1551. if (*szNewLabel && StrCmp(szNewLabel, szOldLabel))
  1552. {
  1553. IShellFolder *psf;
  1554. // set the new label
  1555. RegSetValue(HKEY_CLASSES_ROOT, c_szMailIconGuid, REG_SZ, szNewLabel, (lstrlen(szNewLabel)+1)*sizeof(TCHAR));
  1556. // let the shell know that it changed
  1557. if (SUCCEEDED(SHGetDesktopFolder(&psf)))
  1558. {
  1559. LPITEMIDLIST pidl;
  1560. ULONG chEaten;
  1561. if (SUCCEEDED(psf->ParseDisplayName(NULL, NULL, c_wszMailIconGuid, &chEaten, &pidl, NULL)))
  1562. {
  1563. SHChangeNotify(SHCNE_UPDATEITEM, SHCNF_IDLIST, pidl, NULL);
  1564. SHFree(pidl);
  1565. }
  1566. psf->Release();
  1567. }
  1568. }
  1569. RegCloseKey(hKey);
  1570. }
  1571. }