Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

483 lines
13 KiB

  1. /*
  2. File: main.cpp
  3. Project: Universal Joystick Control Panel OLE Client
  4. Author: Brycej
  5. Date: 02/28/95
  6. Comments:
  7. Copyright (c) 1995, Microsoft Corporation
  8. */
  9. //#pragma pack (8)
  10. #include <afxcmn.h>
  11. #include <cpl.h>
  12. #include "cpanel.h"
  13. #include "resource.h"
  14. // Windows bug 578471 -- remove from server
  15. //#include "creditst.h" // for the Credit Dialog!
  16. #define JOYSTICK_CPL 0
  17. #define MAX_CPL_PAGES 6
  18. HINSTANCE ghInstance;
  19. extern WCHAR *pwszTypeArray[MAX_DEVICES];
  20. extern WCHAR *pwszGameportDriverArray[MAX_GLOBAL_PORT_DRIVERS];
  21. extern WCHAR *pwszGameportBus[MAX_BUSSES]; // List of enumerated gameport buses
  22. extern BYTE nGamingDevices; // Gaming Devices Enumeration Counter
  23. extern BYTE nGameportDriver; // Global Port Driver Enumeration Counter
  24. extern BYTE nGameportBus; // Gameport Bus Enumeration Counter
  25. extern short nFlags; // State Flags the CPL defined in CPANEL.H
  26. static void AddPage(LPPROPSHEETHEADER ppsh, short nTemplateID, int nTabID, DLGPROC pfn);
  27. static void DoProperties(HWND hWnd, UINT nStartPage);
  28. void WINAPI ShowJoyCPL(HWND);
  29. void ParseArgs(HWND hDlg, LPTSTR lpArgList);
  30. INT_PTR CALLBACK SplashDialogProc(HWND hDlg, ULONG uMsg, WPARAM wParam, LPARAM lParam);
  31. // From AppMan.cpp
  32. //extern HRESULT AppManInit();
  33. // Windows bug 578471 -- remove from server
  34. // From Retrocfg.cpp
  35. //extern HRESULT DVoiceCPLInit();
  36. //extern INT_PTR CALLBACK RetrofitProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam);
  37. //extern INT_PTR RetrofitDestroyHandler(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam);
  38. BYTE nID, nStartPageDef, nStartPageCPL;
  39. BOOL WINAPI DllMain(HANDLE hModule, ULONG uReason, LPVOID pv)
  40. {
  41. switch( uReason )
  42. {
  43. case DLL_PROCESS_ATTACH:
  44. ghInstance = (HINSTANCE)hModule;
  45. // needed because CEdit will Assert without this line!!!
  46. afxCurrentInstanceHandle = ghInstance;
  47. afxCurrentResourceHandle = ghInstance;
  48. break;
  49. // case DLL_PROCESS_DETACH:
  50. // ClearArrays();
  51. case DLL_THREAD_ATTACH:
  52. DisableThreadLibraryCalls((HMODULE)hModule);
  53. case DLL_THREAD_DETACH:
  54. break;
  55. }
  56. return(TRUE);
  57. }
  58. /*
  59. function: CPlApplet()
  60. comments:
  61. Entry point for control panel applets.
  62. */
  63. LONG WINAPI CPlApplet(HWND hWnd, UINT uMsg, LPARAM lParam1, LPARAM lParam2)
  64. {
  65. switch( uMsg )
  66. {
  67. case CPL_INIT:
  68. return(1);
  69. case CPL_GETCOUNT:
  70. return(1);
  71. case CPL_INQUIRE:
  72. ((LPCPLINFO)lParam2)->idIcon = IDI_CPANEL;
  73. ((LPCPLINFO)lParam2)->idName = IDS_GEN_CPANEL_TITLE;
  74. ((LPCPLINFO)lParam2)->idInfo = IDS_GEN_CPANEL_INFO;
  75. ((LPCPLINFO)lParam2)->lData = 0;
  76. return(1);
  77. case CPL_DBLCLK:
  78. nID = (NUMJOYDEVS<<1);
  79. // Applet icon double clicked -- invoke property sheet with
  80. // The first property sheet page on top.
  81. DoProperties(hWnd, 0);
  82. break;
  83. /*
  84. * This function requires Windows 2000. Not available on Win9x.
  85. */
  86. case CPL_STARTWPARMS:
  87. // Same as CPL_DBLCLK, but lParam2 is a long pointer to
  88. // a string of extra directions that are to be supplied to
  89. // the property sheet that is to be initiated.
  90. // The arguments are as follows:
  91. // @nCPLDialog Index, nStartPageCPL, nStartPageDef
  92. // Don't do anything if there are no arguments!
  93. if( *(LPTSTR)lParam2 )
  94. ParseArgs(hWnd, (LPTSTR)lParam2);
  95. return(TRUE); // return non-zero to indicate message handled
  96. case CPL_EXIT:
  97. case CPL_STOP:
  98. break;
  99. }
  100. return(0);
  101. }
  102. /*
  103. Function: DoProperties(HWND hWnd, UINT nStartPage)
  104. Arguements: hWnd - Handle to Main Window
  105. nStartPage - Page number to start
  106. */
  107. static void DoProperties(HWND hWnd, UINT nStartPage)
  108. {
  109. static HWND hPrevHwnd;
  110. static HANDLE hMutex = CreateMutex(NULL, TRUE, MUTEX_NAME);
  111. if( GetLastError() == ERROR_ALREADY_EXISTS )
  112. {
  113. SetForegroundWindow(hPrevHwnd);
  114. } else
  115. {
  116. hPrevHwnd = hWnd;
  117. nFlags = (GetVersion() < 0x80000000) ? ON_NT : 0;
  118. HPROPSHEETPAGE *pPages = new (HPROPSHEETPAGE[MAX_CPL_PAGES]);
  119. ASSERT (pPages);
  120. LPPROPSHEETHEADER ppsh = new (PROPSHEETHEADER);
  121. ASSERT(ppsh);
  122. ZeroMemory(ppsh, sizeof(PROPSHEETHEADER));
  123. ppsh->dwSize = sizeof(PROPSHEETHEADER);
  124. ppsh->dwFlags = PSH_NOAPPLYNOW | PSH_USEICONID;
  125. ppsh->hwndParent = hWnd;
  126. ppsh->hInstance = ghInstance;
  127. ppsh->pszCaption = MAKEINTRESOURCE(IDS_GEN_CPANEL_TITLE);
  128. ppsh->pszIcon = MAKEINTRESOURCE(IDI_CPANEL);
  129. ppsh->nStartPage = nStartPage;
  130. ppsh->phpage = pPages;
  131. AddPage(ppsh, IDD_CPANEL, IDS_GENERAL_TAB, CPanelProc);
  132. AddPage(ppsh, IDD_ADVANCED, IDS_ADVANCED_TAB, AdvancedProc);
  133. // Windows bug 578471 -- remove from server
  134. // if( SUCCEEDED ( DVoiceCPLInit() )) {
  135. // AddPage(ppsh, IDD_PROP_RETROFIT, IDS_DVOICE_TAB, RetrofitProc);
  136. // }
  137. // if( SUCCEEDED ( AppManInit() ) ) {
  138. // AddPage(ppsh, IDD_APPMAN, IDS_APPMAN_TAB, AppManProc);
  139. // AddPage(ppsh, IDD_APPMAN_LOCKING, IDS_APPMANLOCK_TAB, AppManLockProc);
  140. // }
  141. #ifdef SYMANTIC_MAPPER
  142. AddPage(ppsh, IDD_SMAPPER, ID_SMAPPER_TAB, SMapperProc);
  143. #endif // SYMANTIC_MAPPER
  144. // trap for return...
  145. VERIFY(PropertySheet(ppsh) != -1);
  146. if( pPages )
  147. delete[] (pPages);
  148. if( ppsh )
  149. delete (ppsh);
  150. ReleaseMutex(hMutex);
  151. CloseHandle(hMutex);
  152. // Windows bug 578471 -- remove from server
  153. // Ensure voice is always cleaned up
  154. //RetrofitDestroyHandler( NULL, 0, 0, 0 );
  155. ClearArrays();
  156. }
  157. }
  158. static void AddPage(LPPROPSHEETHEADER ppsh, short nTemplateID, int nTabID, DLGPROC pfn)
  159. {
  160. if( ppsh->nPages < MAX_CPL_PAGES )
  161. {
  162. LPPROPSHEETPAGE ppsp = new (PROPSHEETPAGE);
  163. ASSERT(ppsp);
  164. ZeroMemory(ppsp, sizeof(PROPSHEETPAGE));
  165. ppsp->dwSize = sizeof(PROPSHEETPAGE);
  166. ppsp->pszTitle = MAKEINTRESOURCE(nTabID);
  167. ppsp->hInstance = ghInstance;
  168. ppsp->pfnDlgProc = pfn;
  169. ppsp->pszTemplate = MAKEINTRESOURCE(nTemplateID);
  170. ppsh->phpage[ppsh->nPages] = CreatePropertySheetPage(ppsp);
  171. if( ppsp )
  172. delete (ppsp);
  173. if( ppsh->phpage[ppsh->nPages] )
  174. ppsh->nPages++;
  175. }
  176. } // AddPage
  177. // DO NOT REMOVE THIS!!!
  178. // This is here because the games group loads the CPL from the exported function
  179. // If you remove this Hellbender, Monster Truck Maddness, CART, etc will fail to
  180. // load the Joystick CPL!!!
  181. // DO NOT REMOVE THIS!!!
  182. void WINAPI ShowJoyCPL(HWND hWnd)
  183. {
  184. nID = (NUMJOYDEVS<<1);
  185. DoProperties(hWnd, 0);
  186. }
  187. void LaunchExtention(HWND hWnd)
  188. {
  189. // These are defined in CPANEL.CPP
  190. extern LPDIRECTINPUT lpDIInterface;
  191. extern IDirectInputJoyConfig* pDIJoyConfig;
  192. HRESULT hr = DirectInputCreate(ghInstance, DIRECTINPUT_VERSION, &lpDIInterface, NULL);
  193. if( FAILED(hr) ) return;
  194. // Call CreateJoyConfigInterface!
  195. if( SUCCEEDED(lpDIInterface->QueryInterface(IID_IDirectInputJoyConfig, (LPVOID*)&pDIJoyConfig)) )
  196. {
  197. // Create a pJoy and populate it's GUID from GetTypeInfo
  198. PJOY pJoy = new (JOY);
  199. ASSERT (pJoy);
  200. pJoy->ID = nID;
  201. DIJOYCONFIG_DX5 JoyConfig;
  202. JoyConfig.dwSize = sizeof (DIJOYCONFIG_DX5);
  203. if( SUCCEEDED(pDIJoyConfig->GetConfig(nID, (LPDIJOYCONFIG)&JoyConfig, DIJC_REGHWCONFIGTYPE)) )
  204. {
  205. LPDIJOYTYPEINFO_DX5 pdiJoyTypeInfo = new (DIJOYTYPEINFO_DX5);
  206. ASSERT (pdiJoyTypeInfo);
  207. pdiJoyTypeInfo->dwSize = sizeof (DIJOYTYPEINFO_DX5);
  208. hr = pDIJoyConfig->GetTypeInfo(JoyConfig.wszType, (LPDIJOYTYPEINFO)pdiJoyTypeInfo, DITC_CLSIDCONFIG);
  209. if( !IsEqualIID(pdiJoyTypeInfo->clsidConfig, GUID_NULL) )
  210. pJoy->clsidPropSheet = pdiJoyTypeInfo->clsidConfig;
  211. if( pdiJoyTypeInfo )
  212. delete (pdiJoyTypeInfo);
  213. }
  214. if( SUCCEEDED(hr) )
  215. Launch(hWnd, pJoy, nStartPageDef);
  216. if( pJoy )
  217. delete (pJoy);
  218. // release the DI JoyConfig interface pointer
  219. if( pDIJoyConfig )
  220. {
  221. pDIJoyConfig->Release();
  222. pDIJoyConfig = 0;
  223. }
  224. }
  225. // release the DI Device interface pointer
  226. if( lpDIInterface )
  227. {
  228. lpDIInterface->Release();
  229. lpDIInterface = 0;
  230. }
  231. }
  232. void ParseArgs(HWND hDlg, LPTSTR lpArgList)
  233. {
  234. BOOL bShowCPL = TRUE;
  235. // Check for '-', as they may not want to show the CPL!
  236. if( *lpArgList == '-' )
  237. {
  238. bShowCPL = FALSE;
  239. *lpArgList++;
  240. }
  241. nStartPageCPL = nStartPageCPL = nStartPageDef = 0;
  242. // parse command line for nStartPageCPL!
  243. while( *lpArgList && (*lpArgList != ',') )
  244. {
  245. nStartPageCPL *= 10;
  246. nStartPageCPL += *lpArgList++ - '0';
  247. }
  248. // check to make sure nStartPageCPL is within range!
  249. if( bShowCPL ) {
  250. if( nStartPageCPL > MAX_CPL_PAGES )
  251. {
  252. #ifdef _DEBUG
  253. OutputDebugString(TEXT("JOY.CPL: Command line requested an invalid start page, reset to default!\n"));
  254. #endif
  255. // NUMJOYDEVS is used to send the user to the Add dialog on start-up!
  256. if( nStartPageCPL != NUMJOYDEVS )
  257. nStartPageCPL = 0;
  258. }
  259. }
  260. // Only continue if you have something further to parse!
  261. if( *lpArgList == ',' )
  262. {
  263. *lpArgList++;
  264. nID = 0;
  265. // Parse for ID's
  266. while( *lpArgList && (*lpArgList != ',') )
  267. {
  268. nID *= 10;
  269. nID += *lpArgList++ - '0';
  270. }
  271. // Check for error cases!
  272. if( (nID < 1) || (nID > NUMJOYDEVS) )
  273. {
  274. #ifdef _DEBUG
  275. OutputDebugString(TEXT("JOY.CPL: Command line Device ID out of range!\n"));
  276. #endif
  277. nID = (NUMJOYDEVS<<1);
  278. return;
  279. }
  280. // Decrement to internal zero based ID
  281. nID--;
  282. // Don't parse what you don't have!
  283. if( *lpArgList == ',' )
  284. {
  285. *lpArgList++;
  286. // Lastly, parse for nStartPageDef!
  287. while( *lpArgList && (*lpArgList != ',') )
  288. {
  289. nStartPageDef *= 10;
  290. nStartPageDef += *lpArgList++ - '0';
  291. }
  292. }
  293. } else {
  294. nID = (NUMJOYDEVS<<1);
  295. }
  296. // Done with the parsing...
  297. // Time to get to work!
  298. // if we're not showing the CPL...
  299. if( !bShowCPL )
  300. {
  301. // check to make sure the next value is a 1
  302. // we may want to have further negative arguments :)
  303. switch( nStartPageCPL )
  304. {
  305. case 1:
  306. // Invalid ID...
  307. if( nID > NUMJOYDEVS ) return;
  308. LaunchExtention(hDlg);
  309. break;
  310. #ifdef WE_CAN_HAVE_CREDITS
  311. case 60:
  312. // If they ask for the splash, they don't get the CPL!
  313. DialogBox( ghInstance, (PTSTR)IDD_SPLASH, hDlg, SplashDialogProc );
  314. break;
  315. #endif
  316. }
  317. } else {
  318. DoProperties(NULL, nStartPageCPL);
  319. }
  320. }
  321. #ifdef WE_CAN_HAVE_CREDITS
  322. INT_PTR CALLBACK SplashDialogProc(HWND hDlg, ULONG uMsg, WPARAM wParam, LPARAM lParam)
  323. {
  324. static CCreditStatic *pStatic;
  325. switch( uMsg )
  326. {
  327. case WM_INITDIALOG:
  328. {
  329. pStatic = new (CCreditStatic);
  330. ASSERT (pStatic);
  331. CWnd *pCWnd = new (CWnd);
  332. ASSERT (pCWnd);
  333. pCWnd->Attach(hDlg);
  334. pStatic->SubclassDlgItem(IDC_MYSTATIC, pCWnd);
  335. if( pCWnd )
  336. {
  337. pCWnd->Detach();
  338. delete (pCWnd);
  339. pCWnd = 0;
  340. }
  341. LPTSTR lpStr = new (TCHAR[MAX_STR_LEN]);
  342. ASSERT (lpStr);
  343. // The Credits come in two lines!
  344. BYTE nStrLen = (BYTE)LoadString(ghInstance, IDS_SPLASH, lpStr, MAX_STR_LEN);
  345. LoadString(ghInstance, IDS_SPLASH1, &lpStr[nStrLen], MAX_STR_LEN-nStrLen);
  346. pStatic->SetCredits(lpStr);
  347. if( lpStr )
  348. {
  349. delete[] (lpStr);
  350. lpStr = 0;
  351. }
  352. pStatic->StartScrolling();
  353. }
  354. return(TRUE); // return TRUE unless you set the focus to a control
  355. // EXCEPTION: OCX Property Pages should return FALSE}
  356. case WM_COMMAND:
  357. switch( LOWORD(wParam) )
  358. {
  359. case IDOK:
  360. EndDialog(hDlg, LOWORD(wParam));
  361. break;
  362. }
  363. break;
  364. // case WM_TIMER:
  365. //SendDlgItemMessage(hDlg, IDC_STATIC, WM_TIMER, 0, 0);
  366. // pStatic->OnTimer(150); //DISPLAY_TIMER_ID
  367. // break;
  368. case WM_DESTROY:
  369. if( pStatic )
  370. {
  371. delete (pStatic);
  372. pStatic = 0;
  373. }
  374. break;
  375. }
  376. return(0);
  377. }
  378. #endif