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.

392 lines
12 KiB

  1. #if !defined(AFX_PAGESTARTUP_H__928475DA_B332_47F4_8180_5C8B79DFC203__INCLUDED_)
  2. #define AFX_PAGESTARTUP_H__928475DA_B332_47F4_8180_5C8B79DFC203__INCLUDED_
  3. #if _MSC_VER > 1000
  4. #pragma once
  5. #endif // _MSC_VER > 1000
  6. #include "PageBase.h"
  7. #include "MSConfigState.h"
  8. //============================================================================
  9. // The CStartupItem class is used to encapsulate an individual startup
  10. // item. Pointers to these objects are maintained in the list.
  11. //============================================================================
  12. class CStartupItem
  13. {
  14. public:
  15. //------------------------------------------------------------------------
  16. // Constructor and destructor.
  17. //------------------------------------------------------------------------
  18. CStartupItem() { }
  19. virtual ~CStartupItem() { }
  20. //------------------------------------------------------------------------
  21. // If the derived classes use the base class member variables, these won't
  22. // need to be overridden.
  23. //------------------------------------------------------------------------
  24. virtual void GetDisplayInfo(CString & strItem, CString & strLocation, CString & strCommand)
  25. {
  26. strItem = m_strItem;
  27. strLocation = m_strLocation;
  28. strCommand = m_strCommand;
  29. }
  30. virtual BOOL IsLive()
  31. {
  32. return m_fLive;
  33. }
  34. //------------------------------------------------------------------------
  35. // Set whether or not the startup item is enabled. If disabling the
  36. // startup item, add a registry entry so it will be loaded again.
  37. // If enabling the startup item, delete the registry entry.
  38. //
  39. // Of course, do the appropriate thing to registry keys, etc.
  40. //------------------------------------------------------------------------
  41. virtual BOOL SetEnable(BOOL fEnable) = 0;
  42. protected:
  43. BOOL m_fLive;
  44. CString m_strItem;
  45. CString m_strLocation;
  46. CString m_strCommand;
  47. };
  48. //============================================================================
  49. // The CStartupItemRegistry class is used to encapsulate an individual startup
  50. // item stored in the registry.
  51. //============================================================================
  52. class CStartupItemRegistry : public CStartupItem
  53. {
  54. public:
  55. //------------------------------------------------------------------------
  56. // Overridden methods for this type of startup item.
  57. //------------------------------------------------------------------------
  58. CStartupItemRegistry();
  59. CStartupItemRegistry(HKEY hkey, LPCTSTR szKey, LPCTSTR szName, LPCTSTR szValueName, LPCTSTR szValue);
  60. CStartupItemRegistry(LPCTSTR szKey, LPCTSTR szName, LPCTSTR szValueName, LPCTSTR szValue);
  61. BOOL SetEnable(BOOL fEnable);
  62. //------------------------------------------------------------------------
  63. // Functions for this subclass.
  64. //------------------------------------------------------------------------
  65. BOOL Create(LPCTSTR szKeyName, HKEY hkey);
  66. static void RemovePersistedEntries();
  67. private:
  68. HKEY m_hkey;
  69. CString m_strKey;
  70. CString m_strValueName;
  71. BOOL m_fIniMapping;
  72. };
  73. //============================================================================
  74. // The CStartupItemFolder class is used to encapsulate an individual startup
  75. // stored in the startup folder.
  76. //============================================================================
  77. class CStartupItemFolder : public CStartupItem
  78. {
  79. public:
  80. //------------------------------------------------------------------------
  81. // Class used to get information about a shortcut from a function running
  82. // in a different thread.
  83. //------------------------------------------------------------------------
  84. class CIconInfo
  85. {
  86. public:
  87. TCHAR szPath[MAX_PATH * 2];
  88. TCHAR szTarget[MAX_PATH * 2];
  89. TCHAR szArgs[MAX_PATH * 2];
  90. HRESULT hResult;
  91. };
  92. public:
  93. //------------------------------------------------------------------------
  94. // Overridden methods for this type of startup item.
  95. //------------------------------------------------------------------------
  96. CStartupItemFolder();
  97. BOOL SetEnable(BOOL fEnable);
  98. //------------------------------------------------------------------------
  99. // Functions for this subclass.
  100. //------------------------------------------------------------------------
  101. BOOL Create(LPCTSTR szKeyName, HKEY hkey);
  102. BOOL Create(const WIN32_FIND_DATA & fd, HKEY hkey, LPCTSTR szRegPathToFolder, LPCTSTR szFolder, LPCTSTR szDir);
  103. static void RemovePersistedEntries();
  104. HRESULT GetIconInfo(CIconInfo & info);
  105. private:
  106. CString m_strFilePath;
  107. CString m_strBackupPath;
  108. };
  109. //============================================================================
  110. // The class which implements the startup tab.
  111. //============================================================================
  112. class CPageStartup : public CPropertyPage, public CPageBase
  113. {
  114. DECLARE_DYNCREATE(CPageStartup)
  115. // Construction
  116. public:
  117. CPageStartup();
  118. ~CPageStartup();
  119. // Dialog Data
  120. //{{AFX_DATA(CPageStartup)
  121. enum { IDD = IDD_PAGESTARTUP };
  122. // NOTE - ClassWizard will add data members here.
  123. // DO NOT EDIT what you see in these blocks of generated code !
  124. //}}AFX_DATA
  125. // Overrides
  126. // ClassWizard generate virtual function overrides
  127. //{{AFX_VIRTUAL(CPageStartup)
  128. protected:
  129. virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
  130. //}}AFX_VIRTUAL
  131. // Implementation
  132. protected:
  133. // Generated message map functions
  134. //{{AFX_MSG(CPageStartup)
  135. virtual BOOL OnInitDialog();
  136. afx_msg void OnDestroy();
  137. afx_msg void OnItemChangedList(NMHDR* pNMHDR, LRESULT* pResult);
  138. afx_msg void OnButtonDisableAll();
  139. afx_msg void OnButtonEnableAll();
  140. afx_msg void OnSetFocusList(NMHDR* pNMHDR, LRESULT* pResult);
  141. afx_msg void OnButtonRestore();
  142. //}}AFX_MSG
  143. DECLARE_MESSAGE_MAP()
  144. public:
  145. //=========================================================================
  146. // Functions overridden from CPageBase
  147. //=========================================================================
  148. TabState GetCurrentTabState();
  149. BOOL OnApply();
  150. void CommitChanges();
  151. void SetNormal();
  152. void SetDiagnostic();
  153. LPCTSTR GetName() { return _T("startup"); };
  154. private:
  155. //=========================================================================
  156. // Functions specific to this tab.
  157. //=========================================================================
  158. void LoadStartupList();
  159. void LoadStartupListLiveItems();
  160. void LoadStartupListLiveItemsRunKey();
  161. void LoadStartupListLiveItemsStartup();
  162. void LoadStartupListLiveItemsWinIniKey();
  163. void LoadStartupListDisabledItems();
  164. void GetCommandName(CString & strCommand);
  165. void InsertStartupItem(CStartupItem * pItem);
  166. void EmptyList(BOOL fFreeMemoryOnly);
  167. void SetEnableForList(BOOL fEnable);
  168. HWND GetDlgItemHWND(UINT nID)
  169. {
  170. HWND hwnd = NULL;
  171. CWnd * pWnd = GetDlgItem(nID);
  172. if (pWnd)
  173. hwnd = pWnd->m_hWnd;
  174. ASSERT(hwnd);
  175. return hwnd;
  176. }
  177. //=========================================================================
  178. // Member variables.
  179. //=========================================================================
  180. CWindow m_list;
  181. int m_iNextPosition;
  182. BOOL m_fIgnoreListChanges;
  183. TabState m_stateRequested; // save the requested state in case there are no startup items
  184. };
  185. //============================================================================
  186. // CRestoreStartup implements a dialog box which allows the user to restore
  187. // startup items disabled during upgrade.
  188. //============================================================================
  189. #define DISABLED_KEY _T("Software\\Microsoft\\Windows\\CurrentVersion\\Setup\\DisabledRunKeys")
  190. #define ENABLED_KEY _T("Software\\Microsoft\\Windows\\CurrentVersion\\Run")
  191. #define DISABLED_STARTUP _T("\\Disabled Startup")
  192. class CRestoreStartup : public CDialog
  193. {
  194. // Construction
  195. public:
  196. CRestoreStartup(CWnd* pParent = NULL); // standard constructor
  197. // Dialog Data
  198. //{{AFX_DATA(CRestoreStartup)
  199. enum { IDD = IDD_RESTORE };
  200. // NOTE: the ClassWizard will add data members here
  201. //}}AFX_DATA
  202. // Overrides
  203. // ClassWizard generated virtual function overrides
  204. //{{AFX_VIRTUAL(CRestoreStartup)
  205. protected:
  206. virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
  207. //}}AFX_VIRTUAL
  208. // Implementation
  209. public:
  210. static BOOL AreItemsToRestore();
  211. private:
  212. //-------------------------------------------------------------------------
  213. // These classes are used to represent the various types of disabled
  214. // startup items we might restore. CStartupDisabled is an abstract base.
  215. //-------------------------------------------------------------------------
  216. class CStartupDisabled
  217. {
  218. public:
  219. CStartupDisabled() {};
  220. virtual ~CStartupDisabled() {};
  221. virtual void GetColumnCaptions(CString & strItem, CString & strLocation) = 0;
  222. virtual void Restore() = 0;
  223. };
  224. //-------------------------------------------------------------------------
  225. // CStartupDisabledRegistry represents Run key items in the registry that
  226. // were disabled.
  227. //-------------------------------------------------------------------------
  228. class CStartupDisabledRegistry : public CStartupDisabled
  229. {
  230. public:
  231. CStartupDisabledRegistry(LPCTSTR szValueName, LPCTSTR szValue, LPCTSTR szLocation, HKEY hkeyBase) :
  232. m_strValueName(szValueName),
  233. m_strValue(szValue),
  234. m_strLocation(szLocation),
  235. m_hkeyBase(hkeyBase) {};
  236. ~CStartupDisabledRegistry() {};
  237. void GetColumnCaptions(CString & strItem, CString & strLocation)
  238. {
  239. strItem = m_strValueName + CString(_T(" = ")) + m_strValue;
  240. strLocation = ((m_hkeyBase == HKEY_LOCAL_MACHINE) ? CString(_T("HKLM\\")) : CString(_T("HKCU\\"))) + m_strLocation;
  241. }
  242. void Restore()
  243. {
  244. // Create the value in the Run registry key.
  245. CRegKey regkey;
  246. if (ERROR_SUCCESS != regkey.Open(m_hkeyBase, m_strLocation, KEY_WRITE))
  247. return;
  248. BOOL fSet = (ERROR_SUCCESS == regkey.SetValue(m_strValue, m_strValueName));
  249. regkey.Close();
  250. // Delete it from the disabled location.
  251. if (fSet)
  252. {
  253. if (ERROR_SUCCESS != regkey.Open(m_hkeyBase, DISABLED_KEY, KEY_WRITE))
  254. return;
  255. regkey.DeleteValue(m_strValueName);
  256. regkey.Close();
  257. }
  258. }
  259. private:
  260. CString m_strValueName;
  261. CString m_strValue;
  262. CString m_strLocation;
  263. HKEY m_hkeyBase;
  264. };
  265. //-------------------------------------------------------------------------
  266. // CStartupDisabledStartup represents startup group items that were
  267. // disabled.
  268. //-------------------------------------------------------------------------
  269. class CStartupDisabledStartup : public CStartupDisabled
  270. {
  271. public:
  272. CStartupDisabledStartup(LPCTSTR szFile, LPCTSTR szDestination, LPCTSTR szCurrentLocation) :
  273. m_strFile(szFile),
  274. m_strDestination(szDestination),
  275. m_strCurrentLocation(szCurrentLocation) {};
  276. ~CStartupDisabledStartup() {};
  277. void GetColumnCaptions(CString & strItem, CString & strLocation)
  278. {
  279. strItem = m_strFile;
  280. strLocation = m_strDestination;
  281. }
  282. void Restore()
  283. {
  284. // Move the file to the startup directory.
  285. CString strExisting(m_strCurrentLocation);
  286. if (strExisting.Right(1) != CString(_T("\\")))
  287. strExisting += CString(_T("\\"));
  288. strExisting += m_strFile;
  289. CString strDestination(m_strDestination);
  290. if (strDestination.Right(1) != CString(_T("\\")))
  291. strDestination += CString(_T("\\"));
  292. strDestination += m_strFile;
  293. ::MoveFileEx(strExisting, strDestination, 0);
  294. }
  295. private:
  296. CString m_strFile;
  297. CString m_strDestination;
  298. CString m_strCurrentLocation;
  299. };
  300. private:
  301. CWindow m_list;
  302. int m_iNextPosition;
  303. private:
  304. void InsertDisabledStartupItem(CStartupDisabled * pItem);
  305. BOOL LoadDisabledStartupGroup();
  306. BOOL LoadDisabledRegistry();
  307. BOOL LoadDisabledItemList();
  308. void EmptyList();
  309. void SetOKState();
  310. protected:
  311. // Generated message map functions
  312. //{{AFX_MSG(CRestoreStartup)
  313. virtual BOOL OnInitDialog();
  314. afx_msg void OnDestroy();
  315. virtual void OnOK();
  316. afx_msg void OnItemChangedRestoreList(NMHDR* pNMHDR, LRESULT* pResult);
  317. //}}AFX_MSG
  318. DECLARE_MESSAGE_MAP()
  319. };
  320. //{{AFX_INSERT_LOCATION}}
  321. // Microsoft Visual C++ will insert additional declarations immediately before the previous line.
  322. #endif // !defined(AFX_PAGESTARTUP_H__928475DA_B332_47F4_8180_5C8B79DFC203__INCLUDED_)