accwiz.cpp
Upload User: xhy777
Upload Date: 2007-02-14
Package Size: 24088k
Code Size: 9k
Category:

Windows Kernel

Development Platform:

Visual C++

  1. #include "pch.hxx" // PCH
  2. #pragma hdrstop
  3. #include "AccWiz.h"
  4. #include "resource.h"
  5. #include "pgfinish.h"
  6. #include "pgGenric.h"
  7. #include "pgWizOpt.h"
  8. #include "pgWizWiz.h"
  9. // Color pages
  10. #include "pgLokPrv.h"
  11. //#include "pgHghCon.h"
  12. // Sound pages
  13. #include "pgSndSen.h"
  14. // Keyboard pages
  15. #include "pgStkKey.h"
  16. #include "pgFltKey.h"
  17. #include "pgTglKey.h"
  18. #include "pgShwHlp.h"
  19. //#include "pgSerKey.h"
  20. // Mouse pages
  21. #include "pgMseKey.h"
  22. #include "pgMseCur.h"
  23. #include "pgMseBut.h"
  24. // Text size pages
  25. #include "pgMinTxt.h"
  26. #include "pgMinTx2.h"
  27. #include "pgScrBar.h"
  28. #include "pgIconSz.h"
  29. #include "pgHotKey.h"
  30. #include "pgTmeOut.h"
  31. #include "pgSveDef.h"
  32. #include "pgSveFil.h"
  33. #include "LookPrev.h"
  34. // Declaration of the global options variable
  35. CAccWizOptions g_Options;
  36. HINSTANCE g_hInstDll = NULL;    // DLL instance handle.
  37. int WINAPI WinMain( 
  38.    HINSTANCE hInstance, // handle to current instance 
  39.    HINSTANCE hPrevInstance, // handle to previous instance 
  40.    LPSTR lpCmdLine, // pointer to command line 
  41.    int nCmdShow // show state of window 
  42.    )
  43. {
  44. g_hInstDll = hInstance;
  45. VERIFY(CLookPrev::sm_Globals.Initialize()); // Make sure this has been initialized
  46. AccWiz_RunDllA(NULL, hInstance, lpCmdLine, nCmdShow);
  47. return 0;
  48. }
  49. HRESULT
  50. CreateAndRunWizard(
  51.    HWND hwndParent);
  52. HRESULT
  53. OnProcessAttach(
  54. HINSTANCE hInstDll);
  55. HRESULT
  56. OnProcessDetach(
  57. VOID);
  58. INT
  59. PropSheetCallback(
  60.   HWND hwnd,
  61.   UINT uMsg,
  62.   LPARAM lParam);
  63. VOID WINAPI AccWiz_RunDllA(HWND hwnd, HINSTANCE hInstance, LPSTR pszCmdLineA, INT nCmdShow)
  64. {
  65. if (NULL != pszCmdLineA)
  66. {
  67. LPWSTR pszCmdLineW = NULL;
  68. INT cchCmdLine = MultiByteToWideChar(CP_ACP,
  69.  0,
  70.  pszCmdLineA,
  71.  -1,
  72.  NULL,
  73.  0);
  74. pszCmdLineW = new WCHAR[cchCmdLine];
  75. if (NULL != pszCmdLineW)
  76. {
  77. MultiByteToWideChar(CP_ACP,
  78. 0,
  79. pszCmdLineA,
  80. -1,
  81. pszCmdLineW,
  82. cchCmdLine);
  83. AccWiz_RunDllW(hwnd, hInstance, pszCmdLineW, nCmdShow);
  84. delete[] pszCmdLineW;
  85. }
  86. }
  87. }
  88. VOID WINAPI AccWiz_RunDllW(HWND hwnd, HINSTANCE hInstance, LPWSTR pszCmdLineW, INT nCmdShow)
  89. {
  90. HWND hwndParent   = GetDesktopWindow();
  91. HRESULT hResult = CreateAndRunWizard(hwndParent);
  92. if(!SUCCEEDED(hResult))
  93. {
  94. // TODO: Put out of memory message here
  95. _ASSERTE(FALSE);
  96. #pragma message("Put Out of Memory message here")
  97. }
  98. }
  99. const INT MAX_PAGES  = 29;
  100. HRESULT
  101. CreateAndRunWizard(
  102.    HWND hwndParent)
  103. {
  104. HRESULT hResult = E_OUTOFMEMORY;
  105. PROPSHEETPAGE psp[MAX_PAGES];
  106. WizardPage *rgpwp[MAX_PAGES];
  107. // Zero init the arrays
  108. memset(&psp, 0, sizeof(psp));
  109. memset(&rgpwp, 0, sizeof(rgpwp));
  110. // ///////////////////////
  111. // Create Pages Here - NOTE: Order does not matter - we'll control it with our own list
  112. //
  113. int nCountPages = 0;
  114. rgpwp[nCountPages++] = new CWizWizPg(psp + nCountPages);
  115. rgpwp[nCountPages++] = new CWizardOptionsPg(psp + nCountPages);
  116. // Size
  117. rgpwp[nCountPages++] = new CLookPreviewMinText1Pg(psp + nCountPages);
  118. rgpwp[nCountPages++] = new CLookPreviewMinText2Pg(psp + nCountPages);
  119. rgpwp[nCountPages++] = new CLookPreviewMinText3Pg(psp + nCountPages);
  120. rgpwp[nCountPages++] = new CMinTextPg(psp + nCountPages);
  121. rgpwp[nCountPages++] = new CMinText2Pg(psp + nCountPages);
  122. rgpwp[nCountPages++] = new CLookPreviewScrollBar1Pg(psp + nCountPages);
  123. rgpwp[nCountPages++] = new CLookPreviewScrollBar2Pg(psp + nCountPages);
  124. rgpwp[nCountPages++] = new CScrollBarPg(psp + nCountPages);
  125. rgpwp[nCountPages++] = new CLookPreviewBorder1Pg(psp + nCountPages);
  126. rgpwp[nCountPages++] = new CLookPreviewBorder2Pg(psp + nCountPages);
  127. rgpwp[nCountPages++] = new CIconSizePg(psp + nCountPages);
  128. // Color
  129. rgpwp[nCountPages++] = new CLookPreviewColorPg(psp + nCountPages);
  130. // rgpwp[nCountPages++] = new CHighContrastPg(psp + nCountPages);
  131. // Sound
  132. rgpwp[nCountPages++] = new CSoundSentryShowSoundsPg(psp + nCountPages);
  133. // Keyboard
  134. rgpwp[nCountPages++] = new CStickyKeysPg(psp + nCountPages);
  135. rgpwp[nCountPages++] = new CFilterKeysPg(psp + nCountPages);
  136. rgpwp[nCountPages++] = new CToggleKeysPg(psp + nCountPages);
  137. rgpwp[nCountPages++] = new CShowKeyboardHelpPg(psp + nCountPages);
  138. // rgpwp[nCountPages++] = new CSerialKeysPg(psp + nCountPages);
  139. // Mouse
  140. rgpwp[nCountPages++] = new CMouseKeysPg(psp + nCountPages);
  141. rgpwp[nCountPages++] = new CMouseCursorPg(psp + nCountPages);
  142. rgpwp[nCountPages++] = new CMouseButtonPg(psp + nCountPages);
  143. // Standard Wizard pages
  144. rgpwp[nCountPages++] = new CGenericWizPg(psp + nCountPages, IDD_WIZNOOPTIONSSELECTED, IDS_WIZNOOPTIONSSELECTEDTITLE, IDS_WIZNOOPTIONSSELECTEDSUBTITLE);
  145. rgpwp[nCountPages++] = new CHotKeysPg(psp + nCountPages);
  146. rgpwp[nCountPages++] = new CAccessTimeOutPg1(psp + nCountPages);
  147. rgpwp[nCountPages++] = new CAccessTimeOutPg2(psp + nCountPages);
  148. rgpwp[nCountPages++] = new CSaveForDefaultUserPg(psp + nCountPages);
  149. rgpwp[nCountPages++] = new CSaveToFilePg(psp + nCountPages);
  150. rgpwp[nCountPages++] = new FinishWizPg(psp + nCountPages);
  151. // Make sure we have the correct number of pages in our wizard
  152. _ASSERTE(MAX_PAGES == nCountPages);
  153. // Make sure pages were created
  154. for (int i = 0; i < nCountPages; i++)
  155. {
  156. if (NULL == rgpwp[i])
  157. break;
  158. }
  159. if(i<nCountPages)
  160. {
  161. // We didn't have enough memory to create all the pages
  162. // Clean out allocated pages and return
  163. for(int i=0;i<nCountPages;i++)
  164. if(rgpwp[i])
  165. delete rgpwp[i];
  166. return E_OUTOFMEMORY;
  167. }
  168. // Create the orders for the pages to be run
  169. DWORD rgdwMainPath[] = {
  170. IDD_WIZWIZ,
  171. IDD_WIZOPTIONS,
  172. IDD_WIZFINISH // We need this placeholder here so we get a 'NEXT' button on IDD_WIZOPTIONS
  173. };
  174. if(!WizardPage::sm_WizPageOrder.AddPages(0xFFFFFFFF, rgdwMainPath, ARRAYSIZE(rgdwMainPath)))
  175. return E_OUTOFMEMORY;
  176. /////////////////////////////////////////////
  177. // See if we need the 16 or 256 color bitmap
  178. BOOL bUse256ColorBmp = FALSE;
  179. HDC hdc = GetDC(NULL);
  180. if(hdc)
  181. {
  182. if(GetDeviceCaps(hdc,BITSPIXEL) >= 8)
  183. bUse256ColorBmp = TRUE;
  184. ReleaseDC(NULL, hdc);
  185. }
  186. ////////////////////////////////
  187. // Do the property sheet
  188. PROPSHEETHEADER psh;
  189. memset(&psh, 0, sizeof(psh));
  190. psh.dwSize = sizeof(PROPSHEETHEADER);
  191. psh.dwFlags  = PSH_USECALLBACK | PSH_WIZARD | PSH_PROPSHEETPAGE
  192. | PSH_WIZARD97 /*| PSH_WATERMARK |*/ /*PSH_HEADER | *//*PSH_STRETCHWATERMARK*/;
  193. psh.hwndParent = hwndParent;
  194. psh.hInstance = g_hInstDll;
  195. psh.pszIcon  = NULL;
  196. psh.pszCaption = NULL;
  197. psh.nPages = MAX_PAGES;
  198. psh.nStartPage = 54331; // We will actually set it in PropSheetCallback to rgdwMainPath[0]
  199. // NOTE: Bug - This only works if nStartPage is non-zero
  200. psh.ppsp = psp;
  201. psh.pfnCallback = PropSheetCallback;
  202. #if 0
  203. psh.nStartPage = 0; // We will actually set it in PropSheetCallback to rgdwMainPath[0]
  204. psh.pfnCallback = NULL;
  205. psh.dwFlags  = PSH_WIZARD | PSH_PROPSHEETPAGE;
  206. #endif
  207. #if 0 // Right now, no watermarks
  208. psh.pszbmWatermark = bUse256ColorBmp?MAKEINTRESOURCE(IDB_WATERMARK256):MAKEINTRESOURCE(IDB_WATERMARK16);
  209. psh.pszbmHeader = bUse256ColorBmp?MAKEINTRESOURCE(IDB_BANNER256):MAKEINTRESOURCE(IDB_BANNER16);
  210. #endif
  211. if (-1 != PropertySheet(&psh))
  212. hResult = NO_ERROR;
  213. else
  214. hResult = E_FAIL;
  215. // Clean up memory allocated for WizardPage's
  216. for(i=0;i<nCountPages;i++)
  217. if(rgpwp[i])
  218. delete rgpwp[i];
  219. return hResult;
  220. }
  221. INT
  222. PropSheetCallback(
  223.   HWND hwnd,
  224.   UINT uMsg,
  225.   LPARAM lParam
  226.   )
  227. {
  228. switch(uMsg)
  229. {
  230. case PSCB_PRECREATE:
  231. break;
  232. case PSCB_INITIALIZED:
  233. {
  234. // Set the first page according to are global list of page orders
  235. // PropSheet_SetCurSelByID(hwnd, WizardPage::sm_WizPageOrder.GetFirstPage());
  236. // HACK - Set TO Options page since we added WIZWIZ page
  237. _ASSERTE(IDD_WIZWIZ == WizardPage::sm_WizPageOrder.GetFirstPage()); // Change this if we remove the wiz wiz page
  238. PropSheet_SetCurSelByID(hwnd, IDD_WIZOPTIONS);
  239. }
  240. break;
  241. }
  242. return 0;
  243. }
  244. // Helper functions
  245. // Helper function
  246. void LoadArrayFromStringTable(int nIdString, int *rgnValues, int *pnCountValues)
  247. {
  248. // This function load the allowed value array from the string table
  249. // If the values are not stored in the string table, the function
  250. // can be overridden in a derived class
  251. // Load in allowed sizes for scroll bar from string table
  252. _ASSERTE(nIdString); // Make sure we were passed a string
  253. TCHAR szArray[255];
  254.     LoadString(g_hInstDll, nIdString, szArray, ARRAYSIZE(szArray));
  255. // Assume at most MAX_DISTINCT_VALUES sizes
  256. LPTSTR szCurrentLocation = szArray;
  257. for(int i=0;i<MAX_DISTINCT_VALUES;i++)
  258. {
  259. if(!szCurrentLocation)
  260. break;
  261. _stscanf(szCurrentLocation, __TEXT("%i"), &rgnValues[i]);
  262. // Find the next space
  263. // NOTE: If there are more than one spaces between characters, this will read the same entry twice
  264. szCurrentLocation = _tcschr(++szCurrentLocation, __TEXT(' '));
  265. }
  266. *pnCountValues = i;
  267. _ASSERTE(*pnCountValues);
  268. }