home *** CD-ROM | disk | FTP | other *** search
/ Team Palmtops 7 / Palmtops_numero07.iso / WinCE / SDKWindowsCE / AutoPC / apcsdk10.exe / data1.cab / Win32_Samples / win32 / sysinfo / sysmain.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1999-05-13  |  7.1 KB  |  241 lines

  1. /*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  2.  
  3. Copyright (c) 1998 Microsoft Corporation
  4.  
  5. Module Name:
  6.  
  7.     sysmain.cpp
  8.  
  9. Abstract:
  10.  
  11.     System Information AutoPC Sample control panel applet.
  12.     This file is the applet's main entry point.
  13.  
  14.     When the module is loaded by the control panel applet loader, 
  15.     DllMain is called to do some main initialization of the applet.
  16.  
  17.     After that, the CPl loader sends messages to the CPlApplet
  18.     function to get information about the CPl, and to tell the CPl
  19.     when to actually run. 
  20.  
  21.     Message            Meaning
  22.     -------            -------
  23.  
  24.     CPL_INIT        Sent to a Control Panel applet to prompt 
  25.                     it to perform global initialization, especially 
  26.                     memory allocation.  Return 1 on success.
  27.  
  28.     CPL_GETCOUNT    Sent to a Control Panel application to retrieve 
  29.                     the number of applets supported by the application.
  30.                     Return the number of applets.
  31.  
  32.     CPL_NEWINQUIRE    Sent to a Control Panel application to request 
  33.                     information about a dialog box that the application supports.
  34.                     
  35.                     (UINT) lParam1;         // application number 
  36.                     (LPNEWCPLINFO) lParam2; // structure for appl. info. 
  37.                 
  38.                     NEWCPLINFO same as Window CE, except:
  39.  
  40.                     dwFlags - Set CPL_DISPLAY_FACEPLATE if this applet supports the
  41.                         AutoPC faceplate. All V1.00 applets should support this.
  42.                         Set CPL_DISPLAY_NOVGA is this aplet does NOT support the
  43.                         VGA screen.
  44.  
  45.     CPL_APCINQUIRE  New to AutoPC, this asks for AutoPC specific data from 
  46.                     the applet.
  47.  
  48.                     (UINT) lParam1;         // application number 
  49.                     (LPAPCCPLINFO) lParam2; // structure for APC specific info. 
  50.  
  51.                     APCCPLINFO structure elements:
  52.                     DWORD   dwSize            -    Size of this structure. Must be 
  53.                                                 filled in by the applet.
  54.                     WCHAR   szTTSName[32]    -    Text-to-speech name of this applet.
  55.                     WCHAR   szAlertName[32]    -    Alert name name of this applet.
  56.  
  57.  
  58.     CPL_DBLCLK        Sent to a Control Panel application when the user 
  59.                     double-clicks the icon in the control panel explorer.
  60.  
  61.     CPL_STOP        Sent once for each applet when the application controlling 
  62.                     the Control Panel application closes.
  63.  
  64.     CPL_EXIT        Sent once to a Control Panel application before the controlling 
  65.                     application releases the DLL containing the application. 
  66.  
  67. Environment:
  68.  
  69.     AutoPC
  70.  
  71. -------------------------------------------------------------------*/
  72. // Auto PC includes
  73. #include <windows.h>
  74. #include <olectl.h>
  75. #include <asfc.h>           
  76. #include <ascmnctl.h>       
  77. #include <keypad.h>
  78. #include <apccpl.h>        // Header for CPl applets
  79.  
  80. // Directives used to help debugging
  81. #define APCDBG_INIT "SysInfo"
  82. #include <apcdebug.h>
  83.  
  84. #include "SysInfo.h" 
  85. #include "resource.h"
  86.  
  87.  
  88. HINSTANCE    g_hInst;
  89. CSysInfoApp * g_pApp;
  90.  
  91. /*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  92. Function:
  93.     DllMain
  94.  
  95. Description:
  96.     Dll initialization function.  See Win32 documentation.
  97.  
  98. Parameters:
  99.     HANDLE hInstance    - Application's instance handle
  100.     ULONG ulReason        - Reason called (See Win32 docs)
  101.     LPVOID pctx            - Reserved
  102.  
  103. Returns:
  104.     BOOL - TRUE on success.
  105. -------------------------------------------------------------------*/
  106. BOOL WINAPI DllMain(HANDLE hmod, DWORD ulReason, LPVOID pctx)
  107. {
  108.     DEBUGMSG(ZONE_FUNCTION,(TEXT("DllMain(0x%x, %lu, 0x%x)\r\n"), hmod, ulReason, pctx));
  109.  
  110.     BOOL fr = TRUE;
  111.  
  112.     if (ulReason == DLL_PROCESS_ATTACH)
  113.     {
  114.         g_hInst = (HINSTANCE)hmod;
  115.     }
  116.  
  117.     DEBUGMSG(ZONE_FUNCTION,(TEXT("-DllMain(%lu)\r\n"), fr));
  118.  
  119.     return fr;
  120. }
  121.  
  122. /*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  123. Function:
  124.     DllMain
  125.  
  126. Description:
  127.     Dll initialization function.  See Win32 documentation.
  128.  
  129. Parameters:
  130.     HWND hwndCPl - Handle to Control Panel window  
  131.     UINT uMsg    - Message sent from main control panel application
  132.       LONG lParam1 - First message parameter
  133.       LONG lParam2 - Second message parameter
  134.  
  135. Returns:
  136.     BOOL - TRUE on success.
  137. -------------------------------------------------------------------*/
  138. LONG CALLBACK CPlApplet(HWND hwndCPL, UINT uMsg, LONG lParam1, LONG lParam2)
  139. {
  140.     DEBUGMSG(ZONE_FUNCTION,(TEXT("+CPlApplet(0x%x, 0x%x, 0x%x, 0x%x)\r\n"), hwndCPL, uMsg, lParam1, lParam2));
  141.  
  142.     int iStringLen;
  143.     NEWCPLINFO* pCPLInfo;
  144.     APCCPLINFO* pAPCInfo;
  145.  
  146.     switch (uMsg) 
  147.     {
  148.     case CPL_INIT:              // First message we receive from Control Panel exe, sent once
  149.         return TRUE;            // return Success.
  150.  
  151.     case CPL_GETCOUNT:          // Second message, sent once
  152.         return 1;                 // Only one applet in this DLL.
  153.  
  154.     case CPL_NEWINQUIRE:        // Query for information on our applet
  155.         pCPLInfo = (NEWCPLINFO*) lParam2;                // Location to put inquiry info
  156.         memset(pCPLInfo, NULL, sizeof(NEWCPLINFO));    // Clear out inquiry structure 
  157.  
  158.         // Fill NEWCPLINFO with required information
  159.         pCPLInfo->dwSize  = (DWORD) sizeof(NEWCPLINFO);
  160.  
  161.         // The display cpl supports faceplate, but no vga screen.
  162.         pCPLInfo->dwFlags = CPL_DISPLAY_FACEPLATE | CPL_DISPLAY_NOVGA;
  163.  
  164.         // Load the icon control panel would use
  165.         pCPLInfo->hIcon   = LoadIcon(g_hInst, (LPWSTR)MAKEINTRESOURCE(ICON_APP_SHELL));
  166.         
  167.         // Load Application name into NEWCPLINFO.szName (max 32 Chars)
  168.         iStringLen = 32;  
  169.         LoadString(g_hInst, STR_APP_SHELL_NAME, pCPLInfo->szName, iStringLen );
  170.  
  171.         if( pCPLInfo->hIcon == NULL || pCPLInfo->szName == NULL ) 
  172.         {
  173.               DEBUGCHK(0);
  174.             return E_FAIL;    //Error state.
  175.         }
  176.         return NOERROR;
  177.  
  178.     case CPL_APCINQUIRE:
  179.         pAPCInfo = (APCCPLINFO*) lParam2;
  180.  
  181.         // Fill APCINQUIRE with required info
  182.         pAPCInfo->dwSize = (DWORD) sizeof(APCCPLINFO);
  183.  
  184.         // Load Application name into APCCPLINFO.szTTSName (max 32 Chars)
  185.         iStringLen = 32;  
  186.         LoadString(g_hInst, STR_APP_SHELL_NAME, pAPCInfo->szTTSName, iStringLen );
  187.     
  188.         // This sample doesn't use the alert feature so we don't fill in that member
  189.         return NOERROR;
  190.  
  191.  
  192.     /**********************************************************************************
  193.     *    CPL_DBLCLK message
  194.     *        Applet should act here just as it would in a winmain.  Create message loop, 
  195.     *        forms manager, form, etc.  
  196.     ---------------------------------------------------------------------------------*/
  197.     case CPL_DBLCLK:    
  198.         MSG     msg;
  199.  
  200.         // Create new Application Class instance
  201.         g_pApp = new CSysInfoApp(g_hInst);
  202.         if( g_pApp == NULL ) 
  203.         {
  204.             DEBUGCHK(0);
  205.             return FALSE;    
  206.         }
  207.  
  208.         if(FAILED(g_pApp->Init())) 
  209.         {
  210.             DEBUGCHK(0);
  211.               delete g_pApp;    
  212.             return FALSE;
  213.         }
  214.  
  215.         // Start message loop
  216.         while (GetMessage(&msg, NULL, 0, 0)) 
  217.         {
  218.             if (msg.hwnd) 
  219.             {
  220.                 DispatchMessage(&msg);
  221.             }
  222.         }
  223.     
  224.         delete g_pApp;
  225.         return TRUE;
  226.  
  227.     case CPL_STOP:              // sent once per app. before CPL_EXIT
  228.         break;
  229.  
  230.     case CPL_EXIT:              // sent once before FreeLibrary called
  231.         break;
  232.  
  233.     default:
  234.         break;
  235.     }
  236.  
  237.     DEBUGMSG(ZONE_FUNCTION,(TEXT("-CPlApplet(0x%x)\r\n")));
  238.  
  239.     return TRUE;
  240. }
  241.