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

  1. /*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  2.  
  3. Copyright (c) 1998 Microsoft Corporation
  4.  
  5. Module Name:
  6.  
  7.     appsink.cpp
  8.  
  9. Abstract:
  10.  
  11.     Keyboard Sample application sinks.  Implements two classes, 
  12.     CFormEventSink and CAppMessageSink.
  13.  
  14. Environment:
  15.  
  16.     AutoPC
  17.  
  18. -------------------------------------------------------------------*/
  19. // System specific includes
  20. #include <Windows.h>
  21. #include <asfc.h>
  22. #include <apcaudio.h>           
  23. #include <ascmnctl.h>  
  24. #include <keypad.h>
  25. #include <asstyles.h>
  26.  
  27. // Application specific includes
  28. #include "resource.h"
  29. #include "appsink.h"
  30. #include "app.h"
  31.  
  32. // Global Application object
  33. extern    CKeyboardApp* g_pApp;
  34.  
  35. /*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  36. Class:
  37.     CKeyboardApp
  38.  
  39. Description:
  40.     Main application class.
  41. -------------------------------------------------------------------*/
  42.  
  43. /*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  44. Function:
  45.     CKeybaordApp::CKeyboardApp
  46.  
  47. Description:
  48.     Constructor.  Initializes all member variables.
  49.  
  50. Parameters:
  51.     HINSTANCE - Applications instance handle.
  52.  
  53. Returns:
  54.     Nothing.
  55. -------------------------------------------------------------------*/
  56. CKeyboardApp::CKeyboardApp(HINSTANCE hInst)
  57. {
  58.     m_hInst                = hInst;
  59.     m_pFormEventSink    = NULL;
  60.     m_pAppMessageSink    = NULL;
  61.     m_pAppEventSink        = NULL;
  62.     m_bszAppName        = NULL;
  63.     m_pManage            = NULL;          
  64.     m_pFmSys            = NULL;              
  65.     m_hFC                = NULL;                
  66.     m_xres                = NULL;                
  67.     m_yres                = NULL;                
  68.     m_pForm                = NULL;
  69.     m_pLabelCodes        = NULL;
  70.     m_pLabelSystem        = NULL;
  71.  
  72.     m_idThread = GetCurrentThreadId();  // save the id of the main thread
  73. }
  74.  
  75. /*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  76. Function:
  77.     CKeybaordApp::CKeyboardApp
  78.  
  79. Description:
  80.     Destructor.  Releases form and forms manager interfaces.  Frees
  81.     all strings.
  82.  
  83. Parameters:
  84.     Nothing.
  85.  
  86. Returns:
  87.     Nothing.
  88. -------------------------------------------------------------------*/
  89. CKeyboardApp::~CKeyboardApp()
  90. {
  91.     if (m_pManage)
  92.     {
  93.         m_pManage->DeregisterStartedApplication(m_hFC, m_bszAppName);
  94.     }
  95.  
  96.     // Release all the controls
  97.     DeleteFormControls();
  98.  
  99.     if (m_pForm)
  100.     {
  101.         m_pForm->Close();    // Close form
  102.         m_pForm->Release();    // Release the form
  103.     }
  104.  
  105.     if (m_bszAppName) SysFreeString(m_bszAppName);
  106.     
  107.     if (m_pFmSys) m_pFmSys->Release();
  108.  
  109.     if (m_pManage){
  110.         m_pManage->Release();
  111.     }
  112.     
  113.     if (m_pFormEventSink){
  114.         m_pFormEventSink->Release();
  115.     } 
  116.         
  117.     if (m_pAppMessageSink){
  118.         m_pAppMessageSink->Release();
  119.     } 
  120.  
  121.     if (m_pAppEventSink){
  122.         m_pAppEventSink->Release();
  123.     } 
  124.  
  125.     UnInitASFormsManager(); // uninitialize the forms manager
  126.     CoUninitialize();       // uninitialize COM
  127. }
  128.  
  129. /*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  130. Function:
  131.     CKeybaordApp::Init
  132.  
  133. Description:
  134.     Main App initialization.  Creates sinks, forms manager, and form.
  135.  
  136. Parameters:
  137.     Nothing.
  138.  
  139. Returns:
  140.     TRUE on success, FALSE on failure.
  141. -------------------------------------------------------------------*/
  142. BOOL 
  143. CKeyboardApp::Init()
  144. {
  145.     HRESULT    hr;
  146.  
  147.     CoInitializeEx(NULL, COINIT_MULTITHREADED);    // Initialize COM
  148.  
  149.     hr = InitASFormsManager();                        // Initialize the forms manager
  150.     if(FAILED(hr))
  151.         return FALSE;
  152.  
  153.     // Load the App name from the resource script
  154.     if(!LoadBSTR(STR_APP_SHELL_NAME, &m_bszAppName))
  155.         return FALSE;
  156.  
  157.     hr = CreateSinks();
  158.     if(FAILED(hr))
  159.         return FALSE;
  160.  
  161.     hr = GetFormsManager();
  162.     if(FAILED(hr))
  163.         return FALSE;
  164.  
  165.     hr = CreateMainForm();
  166.     if(FAILED(hr)) 
  167.         return FALSE;
  168.  
  169.     return TRUE;
  170. }
  171.  
  172. /*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  173. Function:
  174.     CKeybaordApp::CreateMainForm
  175.  
  176. Description:
  177.     Creates the main form and adds all controls to it.
  178.  
  179. Parameters:
  180.     Nothing.
  181.  
  182. Returns:
  183.     Returns HR failure code or NOERROR on success.
  184. -------------------------------------------------------------------*/
  185. HRESULT
  186. CKeyboardApp::CreateMainForm()
  187. {
  188.     BSTR     bstr;
  189.     HRESULT hr;
  190.  
  191.     bstr = NULL;
  192.  
  193.     // Create the form
  194.     hr = CoCreateInstance(CLSID_ASFORM,    // COM object class identifier
  195.         NULL,                            // NOT part of an aggregate
  196.         CLSCTX_INPROC_SERVER,            // Create object in our process
  197.         IID_ASFORM,                        // Get the IASForm interface
  198.         (PVOID *) &m_pForm);            // Put pointer into this variable
  199.     if (FAILED(hr))
  200.         goto LReturn;
  201.  
  202.     // initialize the newly created form
  203.     hr = m_pForm->Init(ID_MAINFORM,        // Form ID
  204.         NULL,                            // Parent Control's IDispatch *
  205.         m_pFormEventSink);                // Event sink to attach to form
  206.     if(FAILED(hr))
  207.         goto LReturn;
  208.  
  209.     hr = m_pManage->Start(m_pForm);        // start the form
  210.     if(FAILED(hr))
  211.         goto LReturn;
  212.  
  213.     // Attach the app's ClassMsgSink sink and the EventSink to the forms manager.
  214.     hr = m_pManage->put_ClassMsgSink(m_pAppMessageSink);
  215.     if(FAILED(hr))
  216.         goto LReturn;
  217.  
  218.     hr = m_pManage->put_EventSink(m_pAppEventSink);
  219.     if(FAILED(hr))
  220.         goto LReturn;
  221.     
  222.     m_pForm->put_Visible(TRUE);
  223.  
  224.     hr = m_pForm->put_Caption(m_bszAppName);
  225.     if(FAILED(hr))
  226.         goto LReturn;
  227.  
  228.     // create the forms controls
  229.     hr = CreateFormControls();
  230.     if(FAILED(hr))
  231.         goto LReturn;
  232.  
  233.     // Register the application with the forms manager. 
  234.     hr = m_pManage->RegisterStartedApplication(m_hFC, m_bszAppName, 0, 0);
  235.     if (FAILED(hr))
  236.         goto LReturn;
  237.  
  238.     // Bring the app to the foreground (in case it wasn't started from shell)
  239.     hr = m_pManage->MoveAppToForeground(GetCurrentProcessId(),0,0);
  240.     if (FAILED(hr))
  241.         goto LReturn;
  242.     
  243.     return NOERROR;
  244.  
  245. LReturn:
  246.        // there was an error. Cleanup
  247.     if (m_pForm) 
  248.     {
  249.         m_pForm->Close();   // close the form
  250.         m_pForm->Release();
  251.         m_pForm = NULL;
  252.     }
  253.  
  254.     return hr;
  255. }
  256.  
  257. /*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  258. Function:
  259.     CKeybaordApp::LoadBSTR
  260.  
  261. Description:
  262.     Loads a resource string into a system allocated buffer.
  263.  
  264. Parameters:
  265.     UINT - Resource ID
  266.     BSTR * - New string put here
  267.  
  268. Returns:
  269.     TRUE on success, FALSE on failure.
  270. -------------------------------------------------------------------*/
  271. BOOL
  272. CKeyboardApp::LoadBSTR(UINT uID, BSTR* pBStr)
  273. {
  274.     if(!pBStr)
  275.         return FALSE;
  276.  
  277.     WCHAR wszTemp[128];
  278.     int iStringLen = 128;
  279.  
  280.     if((iStringLen = LoadStringW(m_hInst, uID, wszTemp, iStringLen)) == 0)
  281.         return(FALSE);    // Something went wrong
  282.     
  283.     *pBStr = SysAllocString(wszTemp);
  284.     if (!(*pBStr))
  285.         return(FALSE);    // Low memory probably
  286.  
  287.     return(TRUE);
  288. }
  289.  
  290. /*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  291. Function:
  292.     CKeybaordApp::CreateSinks
  293.  
  294. Description:
  295.     Creates a new CFormEventSink and CAppMessageSink object.  It then 
  296.     gets an IASEventSink pointer from CFormEventSink and IASEventSink 
  297.     IASClassMsgSink pointers from CAppMessageSink.
  298.  
  299. Parameters:
  300.     Nothing.
  301.  
  302. Returns:
  303.     Returns HR failure code or NOERROR on success.
  304. -------------------------------------------------------------------*/
  305. HRESULT    
  306. CKeyboardApp::CreateSinks()
  307. {
  308.     HRESULT             hr;
  309.     CFormEventSink *    pFormEventSink = NULL;
  310.     CAppMessageSink    *   pMessageSink = NULL;
  311.  
  312.     pFormEventSink = new CFormEventSink(m_idThread);    // create an event sink object
  313.  
  314.     if(!pFormEventSink) 
  315.         return E_OUTOFMEMORY;
  316.  
  317.     hr = pFormEventSink->QueryInterface(IID_ASEVENTSINK,    // Requested interface
  318.         (PVOID *) &m_pFormEventSink);                        // Place to put it
  319.     if(FAILED(hr))
  320.     {
  321.         delete pFormEventSink;
  322.         return E_FAIL;
  323.     }
  324.     
  325.     pMessageSink = new CAppMessageSink(m_idThread);        // create a message sink object
  326.     if(!pMessageSink) 
  327.         return E_OUTOFMEMORY;
  328.  
  329.     hr = pMessageSink->QueryInterface(IID_ASCLASSMSGSINK,    // Requested interface
  330.         (PVOID *) &m_pAppMessageSink);                        // Place to put it
  331.     if(FAILED(hr))
  332.     {
  333.         delete pMessageSink;
  334.         return E_FAIL;
  335.     }
  336.  
  337.     hr = pMessageSink->QueryInterface(IID_ASEVENTSINK,        // Requested interface
  338.         (PVOID *) &m_pAppEventSink);                        // Place to put it
  339.     if(FAILED(hr))
  340.     {
  341.         delete pMessageSink;
  342.         return E_FAIL;
  343.     }
  344.  
  345.     return NOERROR;
  346. }
  347.  
  348. /*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  349. Function:
  350.     CKeybaordApp::GetFormsManager
  351.  
  352. Description:
  353.     Creates the IfmManage COM interface.
  354.  
  355. Parameters:
  356.     Nothing.
  357.  
  358. Returns:
  359.     Returns HR failure code or NOERROR on success.
  360. -------------------------------------------------------------------*/
  361. HRESULT    
  362. CKeyboardApp::GetFormsManager()
  363. {
  364.        HRESULT hr;
  365.  
  366.     // Create the forms manager COM object
  367.     hr = CoCreateInstance(CLSID_FMMANAGE,    // Forms Manager Class ID
  368.         NULL,                                // Not part of an aggregate
  369.         CLSCTX_INPROC_SERVER,                // In our process
  370.         IID_FMMANAGE,                        // Request the IfmManage interface
  371.         (PVOID *) &m_pManage);                // Put it here
  372.     if(FAILED(hr))
  373.         return hr;
  374.  
  375.     // Forms Context Handle required to register application
  376.     hr = m_pManage->GetFormsContextHandle(&m_hFC);
  377.     if(FAILED(hr))
  378.         return hr;
  379.  
  380.     hr = m_pManage->QueryInterface(IID_FMSYSTEM, (PVOID *) &m_pFmSys);
  381.     if(FAILED(hr))
  382.         return hr;
  383.  
  384.     // Get some simple system metrics, x resolution and y resolution
  385.     hr = m_pFmSys->GetFormDisplayCaps(m_hFC, VERTRES, &m_yres);
  386.     if(FAILED(hr))
  387.         return hr;
  388.  
  389.     hr = m_pFmSys->GetFormDisplayCaps(m_hFC, HORZRES, &m_xres);
  390.     if(FAILED(hr))
  391.         return hr;
  392.  
  393.     return NOERROR;
  394. }
  395.  
  396. /*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  397. Function:
  398.     CKeybaordApp::DeleteFormControls
  399.  
  400. Description:
  401.     Releases all the form controls.
  402.  
  403. Parameters:
  404.     Nothing.
  405.  
  406. Returns:
  407.     Nothing.
  408. -------------------------------------------------------------------*/
  409. void
  410. CKeyboardApp::DeleteFormControls()
  411. {
  412.  
  413.     if (m_pLabelCodes)
  414.     {
  415.         m_pLabelCodes->Release();
  416.         m_pLabelCodes=NULL;
  417.     }
  418.  
  419.     if (m_pLabelSystem)
  420.     {
  421.         m_pLabelSystem->Release();
  422.         m_pLabelSystem=NULL;
  423.     }
  424.  
  425.     return;
  426. }
  427. /*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  428. Function:
  429.     CKeybaordApp::CreateFormControls
  430.  
  431. Description:
  432.     Creates all the controls on the main form.
  433.  
  434. Parameters:
  435.     Nothing.
  436.  
  437. Returns:
  438.     Returns HR failure code or NOERROR on success.
  439. -------------------------------------------------------------------*/
  440. HRESULT    
  441. CKeyboardApp::CreateFormControls()
  442. {
  443.     HRESULT hr;
  444.     BSTR bstr;
  445.  
  446.     // create the first label control
  447.     hr=CoCreateInstance(CLSID_ASLABEL,            // IASLabel class ID
  448.                         NULL,                    // Not part of an aggregate
  449.                         CLSCTX_INPROC_SERVER,    // In our process
  450.                         IID_ASLABEL,            // We request the IASLabel interface
  451.                         (PVOID *)&m_pLabelCodes);//Put the interface here.
  452.     if(FAILED(hr))
  453.         return hr;
  454.  
  455.     // create the second label control
  456.     hr=CoCreateInstance(CLSID_ASLABEL,            // IASLabel class ID
  457.                         NULL,                    // Not part of an aggregate
  458.                         CLSCTX_INPROC_SERVER,    // In our process
  459.                         IID_ASLABEL,            // We request the IASLabel interface
  460.                         (PVOID *)&m_pLabelSystem);// put the interface here
  461.     if(FAILED(hr)) 
  462.         return hr;
  463.     
  464.     // Set some of the properties of the first label; placement, alignment, and ForeColor
  465.     m_pLabelCodes->SetBounds(10,20,240,40);
  466.     m_pLabelCodes->put_Format(ASFC_ALIGN_LEFT | ASFC_ALIGN_WORDBREAK);
  467.     m_pLabelCodes->put_ForeColor(RGB(255,0,0));
  468.     
  469.     // Get blank text string and set label text
  470.     if(LoadBSTR(IDS_NULL, &bstr))
  471.     {
  472.         m_pLabelCodes->put_Caption(bstr);
  473.         SysFreeString(bstr);
  474.     }
  475.  
  476.     // Set some of the properties of the second label; placement, alignment, and ForeColor
  477.     m_pLabelSystem->SetBounds(10,40,240,60);
  478.     m_pLabelSystem->put_Format(ASFC_ALIGN_LEFT | ASFC_ALIGN_WORDBREAK);
  479.     m_pLabelSystem->put_ForeColor(RGB(0,0,255));
  480.  
  481.     // Get blank text string and set label text
  482.     if(LoadBSTR(IDS_NULL, &bstr))
  483.     {
  484.         m_pLabelSystem->put_Caption(bstr);
  485.         SysFreeString(bstr);
  486.     }
  487.  
  488.     // Add the two new controls to the form
  489.     hr = m_pForm->Add(m_pLabelCodes, IDC_LABELCODES);
  490.     if(FAILED(hr))
  491.         return hr;
  492.     hr = m_pForm->Add(m_pLabelSystem, IDC_LABELSYSTEM);
  493.     if(FAILED(hr))
  494.         return hr;
  495.  
  496.     return NOERROR;
  497. }
  498.  
  499. /*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  500. Function:
  501.     CKeybaordApp::ProcessMessage
  502.  
  503. Description:
  504.     This function is called from the IASClassMsgSink attached to the
  505.     forms manager. 
  506.  
  507. Parameters:
  508.     long - Win32 Message
  509.     long - Parameter
  510.     long - Parameter
  511.  
  512. Returns:
  513.     Nothing.
  514. -------------------------------------------------------------------*/
  515. void
  516. CKeyboardApp::ProcessMessage(long uMsg, long wParam, long lParam)
  517. {
  518.     WCHAR wtext[80];    // Buffer used later to set text labels
  519.  
  520.     switch (uMsg)
  521.     {
  522.     default:
  523.         break;
  524.  
  525.     // Each message we want to display has a case block that displays 
  526.     // the message (or calls a function that displays the message)
  527.     case WM_REMOTE_KEYDOWN:                // Key pressed down
  528.     case WM_REMOTE_KEYUP:                // Key lifted
  529.         UpdateKeyString(uMsg, wParam, lParam);
  530.         break;
  531.  
  532.     case WM_HIBERNATE:                    // Application asked to hibernate
  533.         UpdateSystemLabel(TEXT("WM_HIBERNATE"));
  534.         break;
  535.  
  536.     case WM_APCSYSMSG_VOLUMECHANGED:    // System volume changed
  537.         UpdateSystemLabel(TEXT("Vol Changed"));
  538.         break;
  539.  
  540.     case WM_APCSYSMSG_MUTE:                // Mute turned on/off
  541.         wsprintf(wtext, TEXT("Mute %s"), lParam ? TEXT("on") : TEXT("off"));
  542.         UpdateSystemLabel(wtext);
  543.         UpdateKeyLabel(TEXT(""));
  544.         break;
  545.  
  546.     case WM_APCSYSMSG_POWERSTATECHANGE:    // Power State changed
  547.         lstrcpy(wtext, TEXT(""));
  548.         switch (wParam)
  549.         {
  550.         default:
  551.             break;
  552.  
  553.         case APC_PWRNOTIFYTYPE_USER:    
  554.             lstrcpy(wtext, TEXT("User Power "));
  555.             break;
  556.  
  557.         case APC_PWRNOTIFYTYPE_ELECTRICAL:
  558.             lstrcpy(wtext, TEXT("System Power "));
  559.             break;
  560.         } 
  561.         lstrcat(wtext, lParam ? TEXT("on") : TEXT("off"));
  562.         UpdateSystemLabel(wtext);
  563.         UpdateKeyLabel(TEXT("")); 
  564.         break;
  565.  
  566.     case WM_APCSYSMSG_MEDIASTATECHANGE:    // CD insterted/ejected
  567.         lstrcpy(wtext, TEXT(""));
  568.         switch (HIWORD(wParam))
  569.         {
  570.         case APC_MEDIATYPE_CD:
  571.             switch (HIWORD (lParam))
  572.             {
  573.             default:
  574.                 break;
  575.  
  576.             case AAM_SRC_CD:  
  577.                 lstrcat(wtext, TEXT("Dash CD "));
  578.                 break;
  579.  
  580.             case AAM_SRC_CDCHANGER:
  581.                 lstrcat(wtext, TEXT("CD Chngr "));
  582.                 break;
  583.  
  584.             }
  585.             break;
  586.         }
  587.         lstrcat (wtext , (LOWORD(wParam) & APC_FLG_MEDIAINSERT) ? TEXT("Insert ") : TEXT("Eject "));
  588.         lstrcat (wtext , (LOWORD(wParam) & APC_FLG_MEDIAHASAUDIO) ? TEXT("Audio ") : TEXT(""));
  589.         lstrcat (wtext , (LOWORD(wParam) & APC_FLG_MEDIAHASDATA) ? TEXT("Data ") : TEXT(""));
  590.         UpdateSystemLabel(wtext);
  591.         break;
  592.  
  593.     case WM_SETTINGCHANGE:                // System setting changed by another app
  594.         lstrcpy(wtext, TEXT("Setting Change "));
  595.         switch (wParam)
  596.         {
  597.         default:
  598.             lstrcat(wtext, TEXT("Unknown"));
  599.             break;
  600.  
  601.         case SPI_SETAPCSHELL:      
  602.             lstrcat(wtext, TEXT("Shell"));
  603.             break;
  604.  
  605.         case SPI_SETAPCSCREENSAVER:
  606.             lstrcat(wtext, TEXT("Screen Saver"));
  607.             break;
  608.  
  609.         case SPI_SETAPCAUDIO:      
  610.             lstrcat(wtext, TEXT("Audio"));
  611.             break;
  612.  
  613.         case SPI_SETAPCLOCALE:     
  614.             lstrcat(wtext, TEXT("Locale"));
  615.             break;
  616.         }
  617.         UpdateSystemLabel(wtext);
  618.         break;
  619.     }
  620. }
  621.  
  622. /*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  623. Function:
  624.     CKeybaordApp::ProcessMessage
  625.  
  626. Description:
  627.     This function is called from ProcessMessage whenever a Keyup/Down
  628.     message is received.
  629.  
  630. Parameters:
  631.     long - Win32 Message
  632.     long - Parameter
  633.     long - Parameter
  634.  
  635. Returns:
  636.     Nothing.
  637. -------------------------------------------------------------------*/
  638. void 
  639. CKeyboardApp::UpdateKeyString(long uMsg, long wParam, long lParam)
  640. {
  641.     WCHAR wsztemp[80];
  642.  
  643.     // first interpret the key up or down
  644.     switch (uMsg)
  645.     {
  646.         case WM_REMOTE_KEYDOWN:
  647.             lstrcpy(wsztemp, TEXT("Keydown "));
  648.             break;
  649.         case WM_REMOTE_KEYUP:
  650.             lstrcpy(wsztemp, TEXT("Keyup "));
  651.             break;
  652.  
  653.         default:
  654.             return;
  655.     }
  656.  
  657.     if((LOWORD(wParam)<='9') && (LOWORD(wParam)>='0'))
  658.     {
  659.         // interpret the numerical codes from the number pad
  660.         WCHAR wsznum[6];
  661.         wsprintf(wsznum, TEXT("%c "), LOWORD(wParam));
  662.         lstrcat(wsztemp, wsznum);
  663.     } 
  664.     else 
  665.     {
  666.         // interpret the other keys from the face plate
  667.         BOOL bClearSystemLabel=FALSE;
  668.         
  669.         switch (LOWORD(wParam))    
  670.         {
  671.         case VK_ESCAPE:
  672.             lstrcat(wsztemp, TEXT("Escape "));
  673.             break;
  674.         
  675.         case VK_LEFT:
  676.             lstrcat(wsztemp, TEXT("Left" ));
  677.             bClearSystemLabel=TRUE;
  678.             break;
  679.         
  680.         case VK_UP:  
  681.             lstrcat(wsztemp, TEXT("Up "));
  682.             bClearSystemLabel=TRUE;
  683.             break;
  684.         
  685.         case VK_RIGHT:
  686.             lstrcat(wsztemp, TEXT("Right "));
  687.             bClearSystemLabel=TRUE;
  688.             break;
  689.         
  690.         case VK_DOWN:
  691.             lstrcat(wsztemp, TEXT("Down "));
  692.             bClearSystemLabel=TRUE;
  693.             break;
  694.         
  695.         case VK_STAR:
  696.             lstrcat(wsztemp, TEXT("* "));
  697.             break;
  698.         
  699.         case VK_POUND:
  700.             lstrcat(wsztemp, TEXT("# "));
  701.             break;
  702.         
  703.         case VK_VOLUMEDOWN:
  704.             lstrcat(wsztemp, TEXT("VolDown "));
  705.             break;
  706.         
  707.         case VK_VOLUMEUP:
  708.             lstrcat(wsztemp, TEXT("VolUp "));
  709.             break;
  710.         
  711.         case VK_RETURN:
  712.             lstrcat(wsztemp, TEXT("Enter "));
  713.             break;
  714.         
  715.         case VK_MENU:
  716.             lstrcat(wsztemp, TEXT("Menu "));
  717.             bClearSystemLabel=TRUE;
  718.             break;
  719.         
  720.         case VK_HELP:
  721.             lstrcat(wsztemp, TEXT("Help "));
  722.             bClearSystemLabel=TRUE;
  723.             break;
  724.         
  725.         default:
  726.             break;
  727.         }
  728.  
  729.         if (bClearSystemLabel)
  730.             UpdateSystemLabel(TEXT(""));    // we know we don't get notifications
  731.                                             // for the system label so empty it for
  732.                                             // neatness
  733.     } 
  734.             
  735.     UpdateKeyLabel(wsztemp);
  736. }
  737.  
  738. /*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  739. Function:
  740.     CKeybaordApp::UpdateKeyLabel
  741.  
  742. Description:
  743.     This function changes the text on the first label to whatever
  744.     string is passed.
  745.  
  746. Parameters:
  747.     LPWSTR - String to display in label.
  748.  
  749. Returns:
  750.     Nothing.
  751. -------------------------------------------------------------------*/
  752. void 
  753. CKeyboardApp::UpdateKeyLabel(LPWSTR lpwstrText)
  754. {
  755.     if (!m_pLabelCodes || !lpwstrText) // Make sure we have an interface pointer and text
  756.         return;
  757.     
  758.     BSTR bstr=SysAllocString(lpwstrText);
  759.     if (bstr)
  760.     {
  761.         m_pLabelCodes->put_Caption(bstr);
  762.         SysFreeString(bstr);
  763.     } // endif
  764. }
  765.  
  766. /*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  767. Function:
  768.     CKeybaordApp::UpdateSystemLabel
  769.  
  770. Description:
  771.     This function changes the text on the second label to whatever
  772.     string is passed.
  773.  
  774. Parameters:
  775.     LPWSTR - String to display in label.
  776.  
  777. Returns:
  778.     Nothing.
  779. -------------------------------------------------------------------*/
  780. void CKeyboardApp::UpdateSystemLabel(LPWSTR lpwstrText)
  781. {
  782.     if (!m_pLabelSystem || !lpwstrText) 
  783.         return;
  784.     
  785.     BSTR bstr=SysAllocString(lpwstrText);
  786.     if (bstr){
  787.         m_pLabelSystem->put_Caption(bstr);
  788.         SysFreeString(bstr);
  789.     } // endif
  790. }
  791.