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.

195 lines
4.0 KiB

  1. // The CPL basics
  2. #include "precomp.h"
  3. // Prototypes
  4. LONG OnCPlInit();
  5. LONG OnCPlGetCount();
  6. LONG OnCPlInquire( int i, CPLINFO * pci );
  7. LONG OnCPlDblClk( int i, HWND hwndParent, LPTSTR pszCmdLine );
  8. LONG OnCPlStop( int i, LPARAM lData );
  9. LONG OnCPlExit();
  10. void DisplayDialingRulesPropertyPage(HWND hwndCPl, int iTab);
  11. // Global Variables
  12. HINSTANCE g_hInst;
  13. // DllMain
  14. //
  15. // This is the DLL entry point, called whenever the DLL is loaded.
  16. extern "C" BOOL WINAPI DllMain( HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpReserved )
  17. {
  18. // Perform actions based on the reason for calling.
  19. switch( fdwReason )
  20. {
  21. case DLL_PROCESS_ATTACH:
  22. g_hInst = hinstDLL;
  23. break;
  24. case DLL_THREAD_ATTACH:
  25. // Do thread-specific initialization.
  26. break;
  27. case DLL_THREAD_DETACH:
  28. // Do thread-specific cleanup.
  29. break;
  30. case DLL_PROCESS_DETACH:
  31. // Perform any necessary cleanup.
  32. break;
  33. default:
  34. break;
  35. }
  36. return TRUE; // Successful DLL_PROCESS_ATTACH.
  37. }
  38. // CPlApplet
  39. //
  40. // This is the main entry point for a CPl applet. This exported function
  41. // is called by the control panel.
  42. LONG APIENTRY CPlApplet(
  43. HWND hwndCPl,
  44. UINT uMsg,
  45. LPARAM lParam1,
  46. LPARAM lParam2
  47. )
  48. {
  49. switch (uMsg )
  50. {
  51. case CPL_INIT:
  52. return OnCPlInit();
  53. case CPL_GETCOUNT:
  54. return OnCPlGetCount();
  55. case CPL_INQUIRE:
  56. return OnCPlInquire((int)lParam1, (CPLINFO*)lParam2);
  57. case CPL_DBLCLK:
  58. lParam2 = 0;
  59. //fall through
  60. case CPL_STARTWPARMS:
  61. return OnCPlDblClk((int)lParam1, hwndCPl, (LPTSTR)lParam2);
  62. case CPL_STOP:
  63. return OnCPlStop((int)lParam1, lParam2);
  64. case CPL_EXIT:
  65. return OnCPlExit();
  66. }
  67. return 0;
  68. }
  69. // OnCPlInit
  70. //
  71. // Before any required initialization.
  72. // Return zero to abort the CPl and non-zero on successful initialization.
  73. LONG OnCPlInit()
  74. {
  75. return (0 == GetSystemMetrics (SM_CLEANBOOT))?TRUE:FALSE;
  76. }
  77. // OnCPlGetCount
  78. //
  79. // Returns the number of CPl dialogs implemented by this DLL.
  80. LONG OnCPlGetCount()
  81. {
  82. return 1;
  83. }
  84. // OnCPlInquire
  85. //
  86. // Fills out a CPLINFO structure with information about the CPl dialog.
  87. // This information includes the name, icon, and description.
  88. LONG OnCPlInquire( int i, CPLINFO * pci )
  89. {
  90. pci->idIcon = IDI_TELEPHONE;
  91. pci->idName = IDS_NAME;
  92. pci->idInfo = IDS_DESCRIPTION;
  93. pci->lData = 0;
  94. return 0;
  95. }
  96. // OnCPlDblClk
  97. //
  98. // This message is sent whenever our CPl is selected. In response we display
  99. // our UI and handle input. This is also used when we are started with parameters
  100. // in which case we get passed a command line.
  101. LONG OnCPlDblClk( int i, HWND hwndCPl, LPTSTR pszCmdLine )
  102. {
  103. int iTab = 0;
  104. if ( pszCmdLine )
  105. {
  106. iTab = *pszCmdLine - TEXT('0');
  107. if ( (iTab < 0) || (iTab > 2) )
  108. {
  109. iTab = 0;
  110. }
  111. }
  112. DisplayDialingRulesPropertyPage(hwndCPl, iTab);
  113. return TRUE;
  114. }
  115. // OnCPlStop
  116. //
  117. // Any resource allocated on a per-dialog basis in OnCPlInquire should be
  118. // freed in this function. The lData member of the CPLINFO structure that
  119. // was initialized in OnCPlInit is passed to this function.
  120. LONG OnCPlStop( int i, LPARAM lData )
  121. {
  122. return 0;
  123. }
  124. // OnCPlExit
  125. //
  126. // This is the final message we recieve. Any memory that was allocated in
  127. // OnCPlInit should be freed here. Release any resources we are holding.
  128. LONG OnCPlExit()
  129. {
  130. return 0;
  131. }
  132. typedef LONG (WINAPI *CONFIGPROC)(HWND, PWSTR, INT, DWORD);
  133. void DisplayDialingRulesPropertyPage(HWND hwndCPl, int iTab)
  134. {
  135. // Load tapi32 and call InternalConfig of something like that
  136. HINSTANCE hTapi = LoadLibrary(TEXT("TAPI32.DLL"));
  137. if ( hTapi )
  138. {
  139. CONFIGPROC pfnInternalConfig = (CONFIGPROC)GetProcAddress(hTapi, "internalConfig");
  140. if ( pfnInternalConfig )
  141. {
  142. pfnInternalConfig( hwndCPl, NULL, iTab, TAPI_CURRENT_VERSION );
  143. return;
  144. }
  145. }
  146. // TODO: Show some sort of error dialog? Maybe something that says "your
  147. // tapi32.dll is missing or corrupt, please reinstall."
  148. }