home *** CD-ROM | disk | FTP | other *** search
- /*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
-
- Copyright (c) 1998 Microsoft Corporation
-
- Module Name:
-
- sysmain.cpp
-
- Abstract:
-
- System Information AutoPC Sample control panel applet.
- This file is the applet's main entry point.
-
- When the module is loaded by the control panel applet loader,
- DllMain is called to do some main initialization of the applet.
-
- After that, the CPl loader sends messages to the CPlApplet
- function to get information about the CPl, and to tell the CPl
- when to actually run.
-
- Message Meaning
- ------- -------
-
- CPL_INIT Sent to a Control Panel applet to prompt
- it to perform global initialization, especially
- memory allocation. Return 1 on success.
-
- CPL_GETCOUNT Sent to a Control Panel application to retrieve
- the number of applets supported by the application.
- Return the number of applets.
-
- CPL_NEWINQUIRE Sent to a Control Panel application to request
- information about a dialog box that the application supports.
-
- (UINT) lParam1; // application number
- (LPNEWCPLINFO) lParam2; // structure for appl. info.
-
- NEWCPLINFO same as Window CE, except:
-
- dwFlags - Set CPL_DISPLAY_FACEPLATE if this applet supports the
- AutoPC faceplate. All V1.00 applets should support this.
- Set CPL_DISPLAY_NOVGA is this aplet does NOT support the
- VGA screen.
-
- CPL_APCINQUIRE New to AutoPC, this asks for AutoPC specific data from
- the applet.
-
- (UINT) lParam1; // application number
- (LPAPCCPLINFO) lParam2; // structure for APC specific info.
-
- APCCPLINFO structure elements:
- DWORD dwSize - Size of this structure. Must be
- filled in by the applet.
- WCHAR szTTSName[32] - Text-to-speech name of this applet.
- WCHAR szAlertName[32] - Alert name name of this applet.
-
-
- CPL_DBLCLK Sent to a Control Panel application when the user
- double-clicks the icon in the control panel explorer.
-
- CPL_STOP Sent once for each applet when the application controlling
- the Control Panel application closes.
-
- CPL_EXIT Sent once to a Control Panel application before the controlling
- application releases the DLL containing the application.
-
- Environment:
-
- AutoPC
-
- -------------------------------------------------------------------*/
- // Auto PC includes
- #include <windows.h>
- #include <olectl.h>
- #include <asfc.h>
- #include <ascmnctl.h>
- #include <keypad.h>
- #include <apccpl.h> // Header for CPl applets
-
- // Directives used to help debugging
- #define APCDBG_INIT "SysInfo"
- #include <apcdebug.h>
-
- #include "SysInfo.h"
- #include "resource.h"
-
-
- HINSTANCE g_hInst;
- CSysInfoApp * g_pApp;
-
- /*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- Function:
- DllMain
-
- Description:
- Dll initialization function. See Win32 documentation.
-
- Parameters:
- HANDLE hInstance - Application's instance handle
- ULONG ulReason - Reason called (See Win32 docs)
- LPVOID pctx - Reserved
-
- Returns:
- BOOL - TRUE on success.
- -------------------------------------------------------------------*/
- BOOL WINAPI DllMain(HANDLE hmod, DWORD ulReason, LPVOID pctx)
- {
- DEBUGMSG(ZONE_FUNCTION,(TEXT("DllMain(0x%x, %lu, 0x%x)\r\n"), hmod, ulReason, pctx));
-
- BOOL fr = TRUE;
-
- if (ulReason == DLL_PROCESS_ATTACH)
- {
- g_hInst = (HINSTANCE)hmod;
- }
-
- DEBUGMSG(ZONE_FUNCTION,(TEXT("-DllMain(%lu)\r\n"), fr));
-
- return fr;
- }
-
- /*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- Function:
- DllMain
-
- Description:
- Dll initialization function. See Win32 documentation.
-
- Parameters:
- HWND hwndCPl - Handle to Control Panel window
- UINT uMsg - Message sent from main control panel application
- LONG lParam1 - First message parameter
- LONG lParam2 - Second message parameter
-
- Returns:
- BOOL - TRUE on success.
- -------------------------------------------------------------------*/
- LONG CALLBACK CPlApplet(HWND hwndCPL, UINT uMsg, LONG lParam1, LONG lParam2)
- {
- DEBUGMSG(ZONE_FUNCTION,(TEXT("+CPlApplet(0x%x, 0x%x, 0x%x, 0x%x)\r\n"), hwndCPL, uMsg, lParam1, lParam2));
-
- int iStringLen;
- NEWCPLINFO* pCPLInfo;
- APCCPLINFO* pAPCInfo;
-
- switch (uMsg)
- {
- case CPL_INIT: // First message we receive from Control Panel exe, sent once
- return TRUE; // return Success.
-
- case CPL_GETCOUNT: // Second message, sent once
- return 1; // Only one applet in this DLL.
-
- case CPL_NEWINQUIRE: // Query for information on our applet
- pCPLInfo = (NEWCPLINFO*) lParam2; // Location to put inquiry info
- memset(pCPLInfo, NULL, sizeof(NEWCPLINFO)); // Clear out inquiry structure
-
- // Fill NEWCPLINFO with required information
- pCPLInfo->dwSize = (DWORD) sizeof(NEWCPLINFO);
-
- // The display cpl supports faceplate, but no vga screen.
- pCPLInfo->dwFlags = CPL_DISPLAY_FACEPLATE | CPL_DISPLAY_NOVGA;
-
- // Load the icon control panel would use
- pCPLInfo->hIcon = LoadIcon(g_hInst, (LPWSTR)MAKEINTRESOURCE(ICON_APP_SHELL));
-
- // Load Application name into NEWCPLINFO.szName (max 32 Chars)
- iStringLen = 32;
- LoadString(g_hInst, STR_APP_SHELL_NAME, pCPLInfo->szName, iStringLen );
-
- if( pCPLInfo->hIcon == NULL || pCPLInfo->szName == NULL )
- {
- DEBUGCHK(0);
- return E_FAIL; //Error state.
- }
- return NOERROR;
-
- case CPL_APCINQUIRE:
- pAPCInfo = (APCCPLINFO*) lParam2;
-
- // Fill APCINQUIRE with required info
- pAPCInfo->dwSize = (DWORD) sizeof(APCCPLINFO);
-
- // Load Application name into APCCPLINFO.szTTSName (max 32 Chars)
- iStringLen = 32;
- LoadString(g_hInst, STR_APP_SHELL_NAME, pAPCInfo->szTTSName, iStringLen );
-
- // This sample doesn't use the alert feature so we don't fill in that member
- return NOERROR;
-
-
- /**********************************************************************************
- * CPL_DBLCLK message
- * Applet should act here just as it would in a winmain. Create message loop,
- * forms manager, form, etc.
- ---------------------------------------------------------------------------------*/
- case CPL_DBLCLK:
- MSG msg;
-
- // Create new Application Class instance
- g_pApp = new CSysInfoApp(g_hInst);
- if( g_pApp == NULL )
- {
- DEBUGCHK(0);
- return FALSE;
- }
-
- if(FAILED(g_pApp->Init()))
- {
- DEBUGCHK(0);
- delete g_pApp;
- return FALSE;
- }
-
- // Start message loop
- while (GetMessage(&msg, NULL, 0, 0))
- {
- if (msg.hwnd)
- {
- DispatchMessage(&msg);
- }
- }
-
- delete g_pApp;
- return TRUE;
-
- case CPL_STOP: // sent once per app. before CPL_EXIT
- break;
-
- case CPL_EXIT: // sent once before FreeLibrary called
- break;
-
- default:
- break;
- }
-
- DEBUGMSG(ZONE_FUNCTION,(TEXT("-CPlApplet(0x%x)\r\n")));
-
- return TRUE;
- }
-