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.

238 lines
5.7 KiB

  1. //****************************************************************************
  2. //
  3. // File: main.c
  4. // Content: main cpl control code
  5. // History:
  6. // Date By Reason
  7. // ==== == ======
  8. // 29-nov-94 craige initial implementation
  9. // 11-dec-94 craige added ShowJoyCPL
  10. //
  11. // Copyright (c) Microsoft Corporation 1994-1995
  12. //
  13. //****************************************************************************
  14. #include "joycpl.h"
  15. HINSTANCE hInstance = NULL;
  16. LPCTSTR cszHelpFile = TEXT("joy.hlp");
  17. #define JOYSTICK_CPL 0
  18. #define MAX_PAGES 16 /* maximum number of joysticks supported */
  19. #ifdef DEBUG
  20. void FAR cdecl dprintf(LPSTR szFormat, ...)
  21. {
  22. char str[256];
  23. wsprintf( str, "JOYCPL: " );
  24. wvsprintf( str+lstrlen( str ), szFormat, (LPVOID)(&szFormat+1) );
  25. OutputDebugString( str );
  26. }
  27. #endif
  28. /*
  29. * LibMain - main entry point for DLL
  30. */
  31. BOOL APIENTRY LibMain( HANDLE hDll, DWORD dwReason, LPVOID lpReserved )
  32. {
  33. switch( dwReason ) {
  34. case DLL_PROCESS_ATTACH:
  35. hInstance = hDll;
  36. DPF( "DLL_PROCESS_ATTACH: hInstance = %08lx\r\n" );
  37. break;
  38. case DLL_PROCESS_DETACH:
  39. DPF( "DLL_PROCESS_DETACH: hInstance = %08lx\r\n" );
  40. break;
  41. case DLL_THREAD_DETACH:
  42. DPF( "DLL_THREAD_DETACH: hInstance = %08lx\r\n" );
  43. break;
  44. case DLL_THREAD_ATTACH:
  45. DPF( "DLL_THREAD_DETACH: hInstance = %08lx\r\n" );
  46. break;
  47. default:
  48. break;
  49. }
  50. return TRUE;
  51. } /* LibMain */
  52. /*
  53. * startJoyCPL - start the joystick CPL
  54. */
  55. static void startJoyCPL( HWND hwnd )
  56. {
  57. PROPSHEETHEADER psh;
  58. char title[MAX_STR];
  59. PROPSHEETPAGE psp;
  60. LPJOYDATA pjd;
  61. #if defined( WANT_SHEETS )
  62. JOYDATAPTR jdp[MAX_PAGES];
  63. HPROPSHEETPAGE hpsp[MAX_PAGES];
  64. int numsheets;
  65. int i;
  66. char str[MAX_STR];
  67. #else
  68. JOYDATAPTR jdp;
  69. HPROPSHEETPAGE hpsp[1];
  70. #endif
  71. #if defined(WANT_SHEETS)
  72. numsheets = joyGetNumDevs();
  73. if( numsheets == 0 ) {
  74. return;
  75. }
  76. #endif
  77. InitCommonControls();
  78. LoadString( hInstance, IDS_JOY, title, sizeof(title));
  79. psh.dwSize = sizeof(PROPSHEETHEADER);
  80. psh.dwFlags = PSH_PROPTITLE;
  81. psh.hwndParent = hwnd;
  82. psh.hInstance = hInstance;
  83. psh.pszCaption = (LPSTR) MAKEINTRESOURCE( IDS_JOY );
  84. psh.nPages = 0;
  85. psh.nStartPage = 0;
  86. psh.phpage = hpsp;
  87. psp.dwSize = sizeof( PROPSHEETPAGE );
  88. psp.dwFlags = PSP_DEFAULT | PSP_USETITLE;
  89. psp.hInstance = hInstance;
  90. psp.pszTemplate = MAKEINTRESOURCE( IDD_JOYSTICK );
  91. psp.pszIcon = NULL;
  92. psp.pfnDlgProc = JoystickDlg;
  93. psp.pfnCallback = NULL;
  94. psp.pcRefParent = NULL;
  95. pjd = JoystickDataInit();
  96. #if defined(WANT_SHEETS)
  97. for( i=0;i<numsheets;i++ ) {
  98. wsprintf( str, "%s %d", title, i+1 );
  99. psp.pszTitle = str;
  100. jdp[i].pjd = pjd;
  101. jdp[i].iJoyId = i;
  102. psp.lParam = (LPARAM) &jdp[i];
  103. if( psh.phpage[ psh.nPages ] = CreatePropertySheetPage( &psp ) ) {
  104. psh.nPages++;
  105. DPF( "PropertySheetPage()\r\n" );
  106. }
  107. }
  108. #else
  109. psp.pszTitle = title;
  110. jdp.pjd = pjd;
  111. jdp.iJoyId = JOYSTICKID1;
  112. psp.lParam = (LPARAM) &jdp;
  113. if( psh.phpage[ psh.nPages ] = CreatePropertySheetPage( &psp ) ) {
  114. psh.nPages++;
  115. DPF( "PropertySheetPage()\r\n" );
  116. }
  117. #endif
  118. if( psh.nPages ) {
  119. PropertySheet( &psh );
  120. DPF( "PropertySheet()\r\n" );
  121. }
  122. JoystickDataFini( pjd );
  123. } /* startJoyCPL */
  124. /*
  125. * ShowJoyCPL - exported function to allow apps to show the joystick CPL
  126. */
  127. void WINAPI ShowJoyCPL( HWND hwnd )
  128. {
  129. HWND hwnd_parent;
  130. hwnd_parent = hwnd;
  131. if( hwnd != NULL ) {
  132. if( GetWindowLong( hwnd, GWL_EXSTYLE ) & WS_EX_TOPMOST ) {
  133. hwnd_parent = NULL;
  134. }
  135. }
  136. startJoyCPL( hwnd_parent );
  137. } /* ShowJoyCPL */
  138. /*
  139. * CPlApplet - applet manager
  140. */
  141. LONG WINAPI CPlApplet(HWND hwnd, UINT uMsg, LPARAM lParam1, LPARAM lParam2)
  142. {
  143. LPCPLINFO pcplinfo;
  144. LPNEWCPLINFO pnewcplinfo;
  145. switch( uMsg ) {
  146. case CPL_INIT:
  147. DPF( "CPL_INIT:\r\n" );
  148. // return TRUE; // (fall through to CPL_GETCOUNT--fail if no joysticks)
  149. case CPL_GETCOUNT:
  150. /*
  151. * number of applets in this DLL - 1 per device
  152. * no joystick devices installed (i.e., no CPL's to display)
  153. */
  154. if( joyGetNumDevs() ) {
  155. DPF( "CPL_GETCOUNT = 1\r\n" );
  156. return 1;
  157. } else {
  158. DPF( "CPL_GETCOUNT = 0\r\n" );
  159. return 0;
  160. }
  161. case CPL_INQUIRE:
  162. /*
  163. * Fill the CPLINFO with the pertinent information for each applet
  164. */
  165. DPF( "CPL_INQUIRE:\r\n" );
  166. pcplinfo = (LPCPLINFO) lParam2;
  167. switch( lParam1 ) {
  168. case JOYSTICK_CPL:
  169. pcplinfo->idIcon = CPL_DYNAMIC_RES;
  170. pcplinfo->idName = CPL_DYNAMIC_RES;
  171. pcplinfo->idInfo = CPL_DYNAMIC_RES;
  172. break;
  173. }
  174. pcplinfo->lData = 0L;
  175. return TRUE;
  176. case CPL_NEWINQUIRE:
  177. DPF( "CPL_NEWINQUIRE\r\n" );
  178. pnewcplinfo = (LPNEWCPLINFO) lParam2;
  179. switch( lParam1 ) {
  180. case JOYSTICK_CPL:
  181. pnewcplinfo->hIcon = LoadIcon( hInstance, MAKEINTRESOURCE(IDI_JOYSTICK));
  182. LoadString(hInstance, IDS_JOY, pnewcplinfo->szName,
  183. sizeof(pnewcplinfo->szName));
  184. LoadString( hInstance, IDS_JOYINFO, pnewcplinfo->szInfo,
  185. sizeof(pnewcplinfo->szInfo) );
  186. DPF( "hIcon = %04x\r\n", pnewcplinfo->hIcon );
  187. DPF( "szName = \"%s\"\r\n", pnewcplinfo->szName );
  188. DPF( "szInfo = \"%s\"\r\n", pnewcplinfo->szInfo );
  189. break;
  190. }
  191. pnewcplinfo->dwHelpContext = 0;
  192. pnewcplinfo->dwSize = sizeof( NEWCPLINFO );
  193. pnewcplinfo->lData = 0L;
  194. pnewcplinfo->szHelpFile[0] = 0;
  195. return TRUE;
  196. case CPL_DBLCLK:
  197. DPF( "CPL_DBLCLK\r\n" );
  198. switch( lParam1 ) {
  199. case JOYSTICK_CPL:
  200. startJoyCPL( hwnd );
  201. break;
  202. }
  203. break;
  204. case CPL_EXIT:
  205. DPF( "CPL_EXIT\r\n" );
  206. break;
  207. default:
  208. return 0L;
  209. }
  210. return 1L;
  211. } /* CPlApplet */