home *** CD-ROM | disk | FTP | other *** search
- /*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
-
- Copyright (c) 1998 Microsoft Corporation
-
- Module Name:
-
- tuneit.cpp
-
- Abstract:
-
- TuneIt AutoPC Sample main application implementation.
- This application highlights the use of Tuner API and the
- Audio Manager API, as well as constraint based resource scripts
- and advanced UI elements.
-
- Environment:
-
- AutoPC
-
- -------------------------------------------------------------------*/
-
- // Auto PC specific includes
- #include <windows.h>
- #include <olectl.h>
- #include <asfc.h> // AutoPC Forms Manager
- #include <ascmnctl.h> // AutoPC Common Controls
- #include <keypad.h> // Defs for VK_*, WM_REMOTE_KEYDOWN, etc.
- #include <tunerapi.h> // Tuner API
- #include <apcaudio.h> // Audio Manager API
-
- #define APCDBG_INIT "tuner"
- #include <apcdebug.h>
-
- // Application specific includes
- #include "resource.h"
- #include "tunesink.h"
- #include "tuneit.h"
-
-
- //global
- extern CTuneitApp * g_pApp;
-
- /*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- Class:
- CTuneitApp
-
- Description:
- Main App class. Creates main form and manager, initializes and
- works with Tuner and Audio APIs.
- -------------------------------------------------------------------*/
-
- /*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- Function:
- CTuneitApp::CTuneitApp
-
- Description:
- Constructor. Initializes all member variables.
-
- Parameters:
- HINSTANCE - Instance handle of application. (Constructor saves
- this to a member variable)
-
- Returns:
- Nothing.
- -------------------------------------------------------------------*/
- CTuneitApp::CTuneitApp(HINSTANCE hInst)
- {
- //Forms, sinks, and managers
- m_pManage = NULL; // Forms manager
- m_pFormRadio = NULL; // Main Form (only form)
- m_pEventSink = NULL; // Event Sink (attached to Form
- m_pClassMsgSink = NULL; // ClassMsgSink attached to forms manager
-
- //Controls
- m_pVolume = NULL; // Label showing Volume
- m_pBand = NULL; // Label showing Band (AM/FM)
- m_pFrequency = NULL; // Label showing current Frequency
- m_pEditPreset = NULL; // Edit Control. Displays preset name and edits it
- m_pHertz = NULL; // Label showing Mhz or Khz
- m_pMenuSettings = NULL; // Settings PowerListBox
-
- //Menu items
- m_pItemBand = NULL; // StringSpinner - Band
- m_pItemBass = NULL; // IntSpinner - Bass level
- m_pItemTreble = NULL; // IntSpinner - Treble level
- m_pItemFade = NULL; // IntSpinner - Fade setting
- m_pItemBalance = NULL; // IntSpinner - Balance setting
-
- //handles
- m_oh = NULL; // Forms context handle
- m_hInst = hInst; // Application instance handle
- m_hTuner = NULL; // Tuner handle
- m_idThread = NULL; // Process thread ID
-
- //Strings (BSTR)
- m_bstrAppName = NULL; // Application Name (used to register)
- m_bstrTuneitMain = NULL; // Caption text "Tuneit - Main"
- m_bstrTuneitSettings= NULL; // Caption text "Tuneit - Settings"
- m_bstrBandFM = NULL; // Text "FM"
- m_bstrBandAM = NULL; // Text "AM"
- m_bstrFrequency = NULL; // Text Buffer used to store current frequency
- m_bstrVolume = NULL; // Text Buffer used to store current volume
- m_bstrMhz = NULL; // Text "Mhz"
- m_bstrKhz = NULL; // Text "Khz"
-
- //Tuner info
- m_iCurrentPreset[FM]= NO_PRESET; // Current Preset on FM band (NO_PRESET means not set yet)
- m_iCurrentPreset[AM]= NO_PRESET; // Current Preset on AM band (NO_PRESET means not set yet)
- m_dwCurrentFreq[FM] = 107700; // Current Freq on FM band
- m_dwCurrentFreq[AM] = 950; // Current Freq on AM band
- m_dwCurrentBand = FM; // Current Band
- m_dwFreqFloor = NULL; // Floor (lowest) freq on current band
- m_dwFreqCeiling = NULL; // Ceiling (max) freq on current band
- m_dwFreqSteps = NULL; // Freq Step on current band
- m_dwfAudioCaps = NULL; // Capabilities of audio system (flags used are in resource.h)
-
- //State info
- m_State = PRIMARY; // Current state (enumeration in tuneit.h)
- }
-
- /*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- Function:
- CTuneitApp::~CTuneitApp
-
- Description:
- Destructor. Does nothing. All clean done in the CleanUp function.
-
- Parameters:
- Nothing.
-
- Returns:
- Nothing.
- -------------------------------------------------------------------*/
- CTuneitApp::~CTuneitApp()
- {
-
- }
-
- /*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- Function:
- CTuneitApp::LoadBSTR
-
- Description:
- Loads a string resource and allocates a BSTR for it. Strings can't
- be longer than 255 chars.
-
- Parameters:
- UINT - Resource ID to load.
-
- Returns:
- BSTR - String allocated.
- -------------------------------------------------------------------*/
- BSTR
- CTuneitApp::LoadBSTR(UINT uID)
- {
- WCHAR wszTemp[256]; // Buffer (we only hand 255 chars)
- int iStringLen = 255;
-
- if((iStringLen = LoadStringW(m_hInst, uID, wszTemp, iStringLen)) == 0 )
- {
- return NULL;
- }
-
- return SysAllocString(wszTemp);
- }
-
- /*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- Function:
- CTuneitApp::Init
-
- Description:
- Loads all strings, initializes tuner and audio manager.
-
- Parameters:
- Nothing.
-
- Returns:
- HRESULT - NOERROR on success. E_FAIL on failure.
- -------------------------------------------------------------------*/
- HRESULT
- CTuneitApp::Init()
- {
- m_idThread = GetCurrentThreadId(); // Save the Thread ID (used to send WM_QUIT message
- // to application with PostThreadMsg)
-
- //Allocate all the strings we are going to use.
- m_bstrAppName = LoadBSTR(STR_APP_SHELL_NAME);
- if(!m_bstrAppName) return E_FAIL;
-
- m_bstrTuneitMain = LoadBSTR(IDS_TUNEIT_MAIN);
- if(!m_bstrTuneitMain) return E_FAIL;
-
- m_bstrTuneitSettings = LoadBSTR(IDS_TUNEIT_SETTINGS);
- if(!m_bstrTuneitSettings) return E_FAIL;
-
- m_bstrBandFM = LoadBSTR(IDS_BAND_FM);
- if(!m_bstrBandFM) return E_FAIL;
-
- m_bstrBandAM = LoadBSTR(IDS_BAND_AM);
- if(!m_bstrBandAM) return E_FAIL;
-
- m_bstrMhz = LoadBSTR(IDS_MHZ);
- if(!m_bstrMhz) return E_FAIL;
-
- m_bstrKhz = LoadBSTR(IDS_KHZ);
- if(!m_bstrKhz) return E_FAIL;
-
- m_bstrNoPreset = LoadBSTR(IDS_NOPRESET);
- if(!m_bstrNoPreset) return E_FAIL;
-
- m_bstrStatus = SysAllocStringLen(NULL, 100);
- if(!m_bstrStatus) return E_FAIL;
-
- m_bstrFrequency = SysAllocStringLen(NULL, 15);
- if(!m_bstrFrequency) return E_FAIL;
-
- m_bstrVolume = SysAllocStringLen(NULL, 15);
- if(!m_bstrVolume) return E_FAIL;
-
-
- if(FAILED(InitAudioManager())) return E_FAIL; // Call AudioManager init
- if(FAILED(CreateEventSink())) return E_FAIL; // Creates IASEventSink and IASClassMsgSink from CAppEventSink
- if(FAILED(GetFormsManager())) return E_FAIL; // Creates IfmManage
- if(FAILED(CreateFormRadio())) return E_FAIL; // Creates Main (only) form
- if(FAILED(InitTuner())) return E_FAIL; // Call Tuner init
- if(FAILED(BuildSettingsMenu())) return E_FAIL; // Create the Settings menu from resource
- // and set its item bounds
-
- // If application isn't started from shell, it won't be visible. So we move it
- // to the foreground.
- HRESULT hr = m_pManage->MoveAppToForeground(GetCurrentProcessId(), 0, 0);
- if(FAILED(hr)) return E_FAIL;
-
- return NOERROR;
- }
-
- /*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- Function:
- CTuneitApp::CleanUp
-
- Description:
- Frees all strings and releases all interfaces.
-
- Parameters:
- Nothing.
-
- Returns:
- Nothing.
- -------------------------------------------------------------------*/
- void
- CTuneitApp::CleanUp()
- {
- // Free any non-null string pointers
-
- if(m_bstrTuneitMain) SysFreeString(m_bstrTuneitMain);
- if(m_bstrTuneitSettings) SysFreeString(m_bstrTuneitSettings);
- if(m_bstrBandFM) SysFreeString(m_bstrBandFM);
- if(m_bstrBandAM) SysFreeString(m_bstrBandAM);
- if(m_bstrFrequency) SysFreeString(m_bstrFrequency);
- if(m_bstrVolume) SysFreeString(m_bstrVolume);
- if(m_bstrMhz) SysFreeString(m_bstrMhz);
- if(m_bstrKhz) SysFreeString(m_bstrKhz);
- if(m_bstrNoPreset) SysFreeString(m_bstrNoPreset);
-
- // Release all Conrol interfaces
- if(m_pBand) m_pBand->Release();
- if(m_pFrequency) m_pFrequency->Release();
- if(m_pEditPreset) m_pEditPreset->Release();
- if(m_pVolume) m_pVolume->Release();
- if(m_pHertz) m_pHertz->Release();
- if(m_pMenuSettings) m_pMenuSettings->Release();
-
- // Release all the Settings menu items
- if(m_pItemBand) m_pItemBand->Release();
- if(m_pItemBass) m_pItemBass->Release();
- if(m_pItemTreble) m_pItemTreble->Release();
- if(m_pItemFade) m_pItemFade->Release();
- if(m_pItemBalance) m_pItemBalance->Release();
-
- // Release Forms, sinks, Manager (DeRegisterApp as well)
- if(m_pFormRadio) m_pFormRadio->Close();
- if(m_pFormRadio) m_pFormRadio->Release();
- if(m_pEventSink) m_pEventSink->Release();
- if(m_pClassMsgSink) m_pClassMsgSink->Release();
- if(m_pManage) m_pManage->DeregisterStartedApplication(m_oh, m_bstrAppName);
- if(m_bstrAppName) SysFreeString(m_bstrAppName);
-
- if(m_pManage) m_pManage->Release();
- }
-
- /*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- Function:
- CTuneitApp::CreateFormRadio
-
- Description:
- Creates the one and only form. Loads it from a form resource, then
- gets all the interfaces that we will need during the Apps lifetime.
-
- Parameters:
- Nothing.
-
- Returns:
- HRESULT - NOERROR on success. E_FAIL on failure.
- -------------------------------------------------------------------*/
- HRESULT
- CTuneitApp::CreateFormRadio()
- {
- HRESULT hr;
-
- IDispatch* pDispForm = NULL;
- //LoadFormResource() creates the form for us as long as m_pFormRadio is NULL
- hr = m_pManage->LoadFormResource(
- (OLE_HANDLE)m_hInst, // Application instance handle
- IDF_MAIN, // Resource ID of form resource
- (IDispatch **)&pDispForm, // Target to put interface
- m_pEventSink ); // EventSink to attached to form
- if(FAILED(hr)) return E_FAIL;
-
- hr = pDispForm->QueryInterface(IID_ASFORM, (PVOID *)&m_pFormRadio);
- if(FAILED(hr)) return E_FAIL;
-
- pDispForm->Release();
-
- IDispatch* pDisp;
- //Get Interface Pointers to controls we will need to access
- hr = m_pFormRadio->ItemFromID(IDC_BAND, (IDispatch **)&pDisp);
- if(FAILED(hr)) return E_FAIL;
- hr = pDisp->QueryInterface(IID_ASLABEL, (PVOID *)&m_pBand);
- if(FAILED(hr)) return E_FAIL;
- pDisp->Release();
-
- hr = m_pFormRadio->ItemFromID(IDC_FREQUENCY, (IDispatch **)&pDisp);
- if(FAILED(hr)) return E_FAIL;
- hr = pDisp->QueryInterface(IID_ASLABEL, (PVOID *)&m_pFrequency);
- if(FAILED(hr)) return E_FAIL;
- pDisp->Release();
-
- hr = m_pFormRadio->ItemFromID(IDC_VOLUME, (IDispatch **)&pDisp);
- if(FAILED(hr)) return E_FAIL;
- hr = pDisp->QueryInterface(IID_ASLABEL, (PVOID *)&m_pVolume);
- if(FAILED(hr)) return E_FAIL;
- pDisp->Release();
-
- hr = m_pFormRadio->ItemFromID(IDC_HERTZ, (IDispatch **)&pDisp);
- if(FAILED(hr)) return E_FAIL;
- hr = pDisp->QueryInterface(IID_ASLABEL, (PVOID *)&m_pHertz);
- if(FAILED(hr)) return E_FAIL;
- pDisp->Release();
-
- hr = m_pFormRadio->ItemFromID(IDC_EDIT_PRESET, (IDispatch **)&pDisp);
- if(FAILED(hr)) return E_FAIL;
- hr = pDisp->QueryInterface(IID_ASEDITBOX, (PVOID *)&m_pEditPreset);
- if(FAILED(hr)) return E_FAIL;
- pDisp->Release();
-
- hr = m_pFormRadio->ItemFromID(IDC_SETTINGS, (IDispatch **)&pDisp);
- if(FAILED(hr)) return E_FAIL;
- hr = pDisp->QueryInterface(IID_ASPOWERLISTBOX, (PVOID *)&m_pMenuSettings);
- if(FAILED(hr)) return E_FAIL;
- pDisp->Release();
-
- // now we have to start it
- hr = m_pManage->Start(m_pFormRadio);
- if(FAILED(hr)) return E_FAIL;
-
- // Hide the Menu settings PowerListBox
- m_pMenuSettings->put_Visible(FALSE);
- m_pEditPreset->put_MaxChars(20);
-
- // Put focus on Preset Edit control, so when enter pressed, this control handles
- // it and allows the user to edit the name
- m_pFormRadio->SetFocus(m_pEditPreset);
-
-
- return NOERROR;
- }
-
- /*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- Function:
- CTuneitApp::BuildSettingsMenu
-
- Description:
- Loads menu from resource. Gets an interface to each item and
- sets its Min,Max, and current Value from variables populated
- by InitAudioManager.
-
- Parameters:
- Nothing.
-
- Returns:
- HRESULT - NOERROR on success. E_FAIL on failure.
- -------------------------------------------------------------------*/
- HRESULT
- CTuneitApp::BuildSettingsMenu()
- {
- HRESULT hr;
-
- // Set up menu
- hr = m_pMenuSettings->AddItemsFromResource(
- m_hInst, // Application instance handle (required for all resource loads)
- MAKEINTRESOURCE(IDM_SETTINGS), // Menu Name (converted using MAKEINTRESOURCE macro)
- m_dwfAudioCaps); // Menu State. Audio Capabilities flags tell which menu options are valid
- if(FAILED(hr)) return E_FAIL;
-
- IDispatch* pDisp;
-
- // Get an interface to each of the items in the menu
- hr = m_pMenuSettings->Item(ID_BAND, &pDisp);
- if(FAILED(hr)) return E_FAIL;
- hr = pDisp->QueryInterface(IID_ASPOWERLISTBOXSTRINGSPINNER, (PVOID *)&m_pItemBand);
- if(FAILED(hr)) return E_FAIL;
- pDisp->Release();
-
- hr = m_pMenuSettings->Item(ID_BASS, &pDisp);
- if(FAILED(hr)) return E_FAIL;
- hr = pDisp->QueryInterface(IID_ASPOWERLISTBOXINTSPINNER, (PVOID *)&m_pItemBass);
- if(FAILED(hr)) return E_FAIL;
- pDisp->Release();
-
- hr = m_pMenuSettings->Item(ID_TREBLE, &pDisp);
- if(FAILED(hr)) return E_FAIL;
- hr = pDisp->QueryInterface(IID_ASPOWERLISTBOXINTSPINNER, (PVOID *)&m_pItemTreble);
- if(FAILED(hr)) return E_FAIL;
- pDisp->Release();
-
- hr = m_pMenuSettings->Item(ID_FADE, &pDisp);
- if(FAILED(hr)) return E_FAIL;
- hr = pDisp->QueryInterface(IID_ASPOWERLISTBOXINTSPINNER, (PVOID *)&m_pItemFade);
- if(FAILED(hr)) return E_FAIL;
- pDisp->Release();
-
- hr = m_pMenuSettings->Item(ID_BALANCE, &pDisp);
- if(FAILED(hr)) return E_FAIL;
- hr = pDisp->QueryInterface(IID_ASPOWERLISTBOXINTSPINNER, (PVOID *)&m_pItemBalance);
- if(FAILED(hr)) return E_FAIL;
- pDisp->Release();
-
- // Set bounds for all the valid intspinners
- // BASS
- if(m_dwfAudioCaps & FLAG_BASS)
- {
- m_pItemBass->put_Min(m_lSettingMin[BASS]);
- m_pItemBass->put_Max(m_lSettingMax[BASS]);
- m_pItemBass->put_Value(m_lSetting[BASS]);
- }
-
- // BALANCE
- if(m_dwfAudioCaps & FLAG_BALANCE)
- {
- m_pItemBalance->put_Min(m_lSettingMin[BALANCE]);
- m_pItemBalance->put_Max(m_lSettingMax[BALANCE]);
- m_pItemBalance->put_Value(m_lSetting[BALANCE]);
- }
-
- // FADE
- if(m_dwfAudioCaps & FLAG_FADE)
- {
- m_pItemFade->put_Min(m_lSettingMin[FADE]);
- m_pItemFade->put_Max(m_lSettingMax[FADE]);
- m_pItemFade->put_Value(m_lSetting[FADE]);
- }
-
- // TREBLE
- if(m_dwfAudioCaps & FLAG_TREBLE)
- {
- m_pItemTreble->put_Min(m_lSettingMin[TREBLE]);
- m_pItemTreble->put_Max(m_lSettingMax[TREBLE]);
- m_pItemTreble->put_Value(m_lSetting[TREBLE]);
- }
-
- return NOERROR;
- }
-
- /*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- Function:
- CTuneitApp::CreateEventSink
-
- Description:
- Creates a new CAppEventSink object, then requests IASEventSink
- and IASClassMsgSink interfaces from it.
-
- Parameters:
- Nothing.
-
- Returns:
- HRESULT - NOERROR on success. E_FAIL on failure.
- -------------------------------------------------------------------*/
- HRESULT
- CTuneitApp::CreateEventSink()
- {
- HRESULT hr;
- CAppEventSink * pSink;
- pSink = new CAppEventSink;
-
- // Get the IASEventSink interface to attach to form
- hr = pSink->QueryInterface(IID_ASEVENTSINK, (PVOID *) &m_pEventSink);
- if(FAILED(hr)) return E_FAIL;
-
- // Get the IASClassMsgSink interface to attach to forms manager
- hr = pSink->QueryInterface(IID_ASCLASSMSGSINK, (PVOID *) &m_pClassMsgSink);
- if(FAILED(hr)) return E_FAIL;
-
- return NOERROR;
- }
-
- /*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- Function:
- CTuneitApp::GetFormsManager
-
- Description:
- Gets a forms manager interface and registers our application.
-
- Parameters:
- Nothing.
-
- Returns:
- HRESULT - NOERROR on success. E_FAIL on failure.
- -------------------------------------------------------------------*/
- HRESULT
- CTuneitApp::GetFormsManager()
- {
- HRESULT hr;
-
- hr = CoCreateInstance(
- CLSID_FMMANAGE, // Create a fmManage Class COM object
- NULL, // Not aggregate from anything
- CLSCTX_INPROC_SERVER, // Runs in our process
- IID_FMMANAGE, // Return the IfmManage interface
- (PVOID *) &m_pManage); // Interface Target
- if(FAILED(hr)) return E_FAIL;
-
- // Get form context handle. Required to RegisterStartedApplication
- hr = m_pManage->GetFormsContextHandle(&m_oh);
- if(FAILED(hr)) return E_FAIL;
-
- // Attach a class message sink to the forms manager
- hr = m_pManage->put_ClassMsgSink(m_pClassMsgSink);
- if(FAILED(hr)) return E_FAIL;
-
- // Register our application as started with the forms manager
- hr = m_pManage->RegisterStartedApplication(m_oh, m_bstrAppName, 0, 0);
- if(FAILED(hr)) return E_FAIL;
-
- return NOERROR;
- }
-
- /*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- Function:
- CTuneitApp::InitTuner
-
- Description:
- Initializes tuner. Allocates memory for and clears preset-related variables.
- Opens tuner and makes sure it can handle AM and FM.
-
- Parameters:
- Nothing.
-
- Returns:
- HRESULT - NOERROR on success. E_FAIL on failure.
- -------------------------------------------------------------------*/
- HRESULT
- CTuneitApp::InitTuner()
- {
- HRESULT hr;
- TUNERDEVCAPS CapTuner;
-
- // Set up the presets
- for(int i=0; i<10; i++)
- {
- m_Presets[FM][i].dwFreqValue = NO_PRESET;
- m_bstrPresets[FM][i] = SysAllocStringLen(NULL, 30);
- if(!m_bstrPresets[FM][i]) return E_FAIL;
-
- m_Presets[AM][i].dwFreqValue = NO_PRESET;
- m_bstrPresets[AM][i] = SysAllocStringLen(NULL, 30);
- if(!m_bstrPresets[AM][i]) return E_FAIL;
- }
-
- // Get tuner's Device capabilities. We are using Tuner Device 1
- if(!TunerGetDevCaps(1, &CapTuner))
- {
- return FALSE;
- }
-
- // Make sure it supports both AM and FM
- if((CapTuner.dwTunerCaps&(BAND_AM|BAND_FM)) != (BAND_AM|BAND_FM))
- {
- return FALSE;
- }
-
- // Open the Tuner. We are using Tuner Device 1
- m_hTuner = TunerOpen(1);
- if(m_hTuner == INVALID_HANDLE_VALUE) return E_FAIL; //No tuner I guess
-
- hr = SetBand(m_dwCurrentBand);
- if(FAILED(hr)) return E_FAIL;
-
- return NOERROR;
- }
-
- /*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- Function:
- CTuneitApp::SetBand
-
- Description:
- Sets the current Band.
-
- Parameters:
- DWORD - Band (AM or FM, defined in tuneit.h)
-
- Returns:
- HRESULT - NOERROR on success. E_FAIL on failure.
- -------------------------------------------------------------------*/
- HRESULT
- CTuneitApp::SetBand(DWORD dwBand)
- {
- TUNERBANDINFO tbInfo;
- TUNERCONFIG tc;
- DWORD dwBufSize;
- DWORD band;
-
- // We convert our application specific dwBand parameter to tuner API
- // friendly BAND_FM or BAND_AM
- if(dwBand == FM) band = BAND_FM;
- else band = BAND_AM;
-
- m_dwCurrentBand = dwBand;
-
- // Use TunerGetBandInfo to get the frequency range of our new band
- if(!TunerGetBandInfo(1, band, &tbInfo, sizeof(tbInfo), &dwBufSize))
- return E_FAIL;
- m_dwFreqFloor = tbInfo.RangeLow.dwFreqValue;
- m_dwFreqCeiling = tbInfo.RangeHigh.dwFreqValue;
-
- // Set frequency steps. If FM, also check to make sure our floor and ceiling frequencies
- // land on things like 89.1, 107.9, and not 108.0 or 90.0
- if(m_dwCurrentBand == FM)
- {
- m_dwFreqSteps = 200;
- if(!(m_dwFreqFloor%200)) m_dwFreqFloor += 100;
- if(!(m_dwFreqCeiling%200)) m_dwFreqCeiling -= 100;
- }
- else // Band is AM
- {
- m_dwFreqSteps = 10;
- }
-
- //Set the Band by getting the current tuner config;
- if(!TunerGetConfig(m_hTuner, &tc))
- return E_FAIL;
- //Changing a couple things;
- tc.dwBand = band;
- tc.CurrentFreq.dwFreqValue = m_dwCurrentFreq[m_dwCurrentBand];
- tc.SeekStep.dwFreqValue = m_dwFreqSteps;
- tc.dwState = STEREO_ON;
- //And setting the new tuner config.
- if(!TunerSetConfig(m_hTuner, &tc))
- return E_FAIL;
-
- // update the radio's display
- UpdateRadio();
-
- return NOERROR;
- }
-
- /*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- Function:
- CTuneitApp::SetBass
-
- Description:
- Sets the Bass level.
-
- Parameters:
- long - Bass level
-
- Returns:
- Nothing.
- -------------------------------------------------------------------*/
- void
- CTuneitApp::SetBass(long lBass)
- {
- AAM_EQPreset(AAM_FLAG_BASS | AAM_FLAG_SET, &lBass);
- }
-
- /*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- Function:
- CTuneitApp::SetTreble
-
- Description:
- Sets the Treble level.
-
- Parameters:
- long - Treble level
-
- Returns:
- Nothing.
- -------------------------------------------------------------------*/
- void
- CTuneitApp::SetTreble(long lTreble)
- {
- AAM_EQPreset(AAM_FLAG_TREBLE | AAM_FLAG_SET, &lTreble);
- }
-
- /*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- Function:
- CTuneitApp::SetFade
-
- Description:
- Sets the Fade level.
-
- Parameters:
- long - Fade level
-
- Returns:
- Nothing.
- -------------------------------------------------------------------*/
- void
- CTuneitApp::SetFade(long lFade)
- {
- AAM_VolumeControl(AAM_FLAG_FADE | AAM_FLAG_SET, &lFade);
- }
-
- /*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- Function:
- CTuneitApp::SetBalance
-
- Description:
- Sets the Balance level.
-
- Parameters:
- long - Balance level
-
- Returns:
- Nothing.
- -------------------------------------------------------------------*/
- void
- CTuneitApp::SetBalance(long lBalance)
- {
- AAM_VolumeControl(AAM_FLAG_BALANCE | AAM_FLAG_SET, &lBalance);
- }
-
- /*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- Function:
- CTuneitApp::InitAudioManager
-
- Description:
- Initializes the audio manager. Gets EQ Capabilities and saves
- them in m_dwfAudioCaps using application defined flags (in resource.h)
- Also gets the min/max/current level of the Balance, Fade, Bass, and Treble
- settings.
-
- Parameters:
- Nothing.
-
- Returns:
- HRESULT - NOERROR on success. E_FAIL on failure.
- -------------------------------------------------------------------*/
- HRESULT
- CTuneitApp::InitAudioManager()
- {
- long lRet;
- long bMute = FALSE;
- DWORD dwEQCaps = NULL;
-
- // Check support for Bass/Treble
- if(AAM_GetEQCaps(&dwEQCaps))
- {
- return E_FAIL;
- }
- // Set our local audio manager capability storage variables using
- // our local flags that are understood by the resource script
- // menu loading function
- if(dwEQCaps & AAM_FLAG_BASS) m_dwfAudioCaps |= FLAG_BASS;
- if(dwEQCaps & AAM_FLAG_TREBLE) m_dwfAudioCaps |= FLAG_TREBLE;
-
- // Check if we can get the fade/balance values,
- // set our local
- if(!AAM_VolumeControl(AAM_FLAG_BALANCE | AAM_FLAG_GET, &lRet))
- m_dwfAudioCaps |= FLAG_BALANCE;
-
- if(!AAM_VolumeControl(AAM_FLAG_FADE | AAM_FLAG_GET, &lRet))
- m_dwfAudioCaps |= FLAG_FADE;
-
- //Get Vol min/max/current
- if(!AAM_VolumeControl(AAM_FLAG_VOLUME | AAM_FLAG_RANGE | AAM_FLAG_GET, &lRet))
- {
- m_lVolMin = HIWORD(lRet);
- m_lVolMax = LOWORD(lRet);
-
- //get current volume
- AAM_VolumeControl(AAM_FLAG_VOLUME | AAM_FLAG_GET, &lRet);
- m_lVolume = lRet;
- }
-
- // Get Balance min/max/current
- if(!AAM_VolumeControl(AAM_FLAG_BALANCE | AAM_FLAG_GET, &lRet))
- {
- m_lSetting[BALANCE] = lRet;
- AAM_VolumeControl(AAM_FLAG_BALANCE | AAM_FLAG_GET | AAM_FLAG_RANGE, &lRet);
- m_lSettingMin[BALANCE] = -LOWORD(lRet);
- m_lSettingMax[BALANCE] = LOWORD(lRet);
- }
-
- // Get Fade min/max/current
- if(!AAM_VolumeControl(AAM_FLAG_FADE | AAM_FLAG_GET, &lRet))
- {
- m_lSetting[FADE] = lRet;
- AAM_VolumeControl(AAM_FLAG_FADE | AAM_FLAG_GET | AAM_FLAG_RANGE, &lRet);
- m_lSettingMin[FADE] = -LOWORD(lRet);
- m_lSettingMax[FADE] = LOWORD(lRet);
- }
-
- // Get Bass min/max/current
- if(!AAM_EQPreset(AAM_FLAG_BASS | AAM_FLAG_GET, &lRet))
- {
- m_lSetting[BASS] = lRet;
- AAM_EQPreset(AAM_FLAG_BASS | AAM_FLAG_GET | AAM_FLAG_RANGE, &lRet);
- m_lSettingMin[BASS] = -LOWORD(lRet);
- m_lSettingMax[BASS] = LOWORD(lRet);
- }
-
- // Get Treble min/max/current
- if(!AAM_EQPreset(AAM_FLAG_TREBLE | AAM_FLAG_GET, &lRet))
- {
- m_lSetting[TREBLE] = lRet;
- AAM_EQPreset(AAM_FLAG_TREBLE | AAM_FLAG_GET | AAM_FLAG_RANGE, &lRet);
- m_lSettingMin[TREBLE] = -LOWORD(lRet);
- m_lSettingMax[TREBLE] = LOWORD(lRet);
- }
-
- //Turn mute off
- AAM_VolumeControl(AAM_FLAG_MUTE | AAM_FLAG_SET, &bMute);
-
- //Set the source to radio
- AAM_SelectSource(AAM_SRC_TUNER);
-
- return NOERROR;
- }
-
- /*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- Function:
- CTuneitApp::UpdateRadio
-
- Description:
- Updates all labels on the radio form.
-
- Parameters:
- Nothing.
-
- Returns:
- Nothing.
- -------------------------------------------------------------------*/
- void
- CTuneitApp::UpdateRadio()
- {
- // If the we are on a preset, put that presets text into the edit
- // box. If we aren't on a preset, put No Preset text into edit box.
- if(m_iCurrentPreset[m_dwCurrentBand] != NO_PRESET)
- {
- m_pEditPreset->put_Text(m_bstrPresets[m_dwCurrentBand][m_iCurrentPreset[m_dwCurrentBand]]);
- }
- else m_pEditPreset->put_Text(m_bstrNoPreset);
-
- // Update band, freq, and khz/mhz
- if(m_dwCurrentBand == FM)
- {
- m_pBand->put_Caption(m_bstrBandFM); // Set BAND text to "FM"
-
- // Print the frequency to a string in the right format.
- swprintf(m_bstrFrequency, L"%.1f", ((float)m_dwCurrentFreq[m_dwCurrentBand])/1000);
- m_pFrequency->put_Caption(m_bstrFrequency); // Set text on frequency label control
- m_pHertz->put_Caption(m_bstrMhz); // Set text on Mhz/Khz label control
- }
- else
- {
- m_pBand->put_Caption(m_bstrBandAM); // Set BAND text to "AM"
-
- // Print the frequency to a string. Weird formatting necessary.
- swprintf(m_bstrFrequency, L"%d", m_dwCurrentFreq[m_dwCurrentBand]);
- m_pFrequency->put_Caption(m_bstrFrequency); // Set text on frequency label control
- m_pHertz->put_Caption(m_bstrKhz); // Set text on Mhz/Khz lavel control
- }
-
- // Update Volume (PrintF to a string, then set text on volume label control.
- // The volume displayed is actually volume max - current volume, becuase
- // volume actually means volume attenuation, so lower is louder
- swprintf(m_bstrVolume, L"%d", (m_lVolMax - m_lVolume) );
- m_pVolume->put_Caption(m_bstrVolume);
-
- }
-
- /*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- Function:
- CTuneitApp::TuneToPreset
-
- Description:
- Tunes the radio to the preset in the current band. Uses
- TunerGetConfig and TunerSetConfig, not any of the Seek functions.
-
- Parameters:
- Nothing.
-
- Returns:
- Nothing.
- -------------------------------------------------------------------*/
- void
- CTuneitApp::TuneToPreset()
- {
- // Set our local storage of the current frequency to the current
- // presets frequency
- m_dwCurrentFreq[m_dwCurrentBand] =
- m_Presets[m_dwCurrentBand][m_iCurrentPreset[m_dwCurrentBand]].dwFreqValue;
-
- TUNERCONFIG tc;
-
- // Get initial configuration (since we only want to change the frequency
- TunerGetConfig(m_hTuner, &tc);
-
- // Update the frequency the tuner was configured on
- tc.CurrentFreq.dwFreqValue = m_dwCurrentFreq[m_dwCurrentBand];
-
- // Set the new tuner config
- TunerSetConfig(m_hTuner, &tc);
-
- // Update the radios visual display to reflect the new information
- UpdateRadio();
- }
-
- /*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- Function:
- CTuneitApp::TuneUp
-
- Description:
- Tunes the radio up one frequency step. Uses TunerGetConfig and
- TunerSetConfig, not any of the Seek functions.
-
- Parameters:
- Nothing.
-
- Returns:
- Nothing.
- -------------------------------------------------------------------*/
- void
- CTuneitApp::TuneUp()
- {
- TUNERCONFIG tc;
-
- m_dwCurrentFreq[m_dwCurrentBand] += m_dwFreqSteps; // Increase Freq by a step
-
- // Make sure the step is within bounds, if not, flip around to the
- // floor (lowest) frequency in this band.
- if(m_dwCurrentFreq[m_dwCurrentBand] > m_dwFreqCeiling)
- {
- m_dwCurrentFreq[m_dwCurrentBand] = m_dwFreqFloor;
- }
-
- // Check to see if the new freq is a preset. Go through each preset and
- // see if it is equal to the new current freq.
- m_iCurrentPreset[m_dwCurrentBand] = NO_PRESET;
- for(int i=0; i<10; i++)
- {
- if(m_Presets[m_dwCurrentBand][i].dwFreqValue == m_dwCurrentFreq[m_dwCurrentBand])
- {
- // If new frequency is a preset, save the preset number in a variable
- m_iCurrentPreset[m_dwCurrentBand] = i;
- break;
- }
- }
-
- // Tune to the new freq now!
- // Get Current config
- TunerGetConfig(m_hTuner, &tc);
-
- // Change the frequency tuner is configured to
- tc.CurrentFreq.dwFreqValue = m_dwCurrentFreq[m_dwCurrentBand];
-
- // Send the new configuration to the tuner
- TunerSetConfig(m_hTuner, &tc);
-
- // Update the radio form to reflect new frequency and/or new preset
- UpdateRadio();
- }
-
- /*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- Function:
- CTuneitApp::TuneDown
-
- Description:
- Tunes the radio down one frequency step. Uses TunerGetConfig and
- TunerSetConfig, not any of the Seek functions.
-
- Parameters:
- Nothing.
-
- Returns:
- Nothing.
- -------------------------------------------------------------------*/
- void
- CTuneitApp::TuneDown()
- {
- TUNERCONFIG tc;
-
- // Decrease the current frequency by one step
- m_dwCurrentFreq[m_dwCurrentBand] -= m_dwFreqSteps;
-
- // Make sure we didn't fall below the minimum frequency for the band.
- // If we did, wrap around by setting current frequency to max freq.
- if(m_dwCurrentFreq[m_dwCurrentBand] < m_dwFreqFloor)
- {
- m_dwCurrentFreq[m_dwCurrentBand] = m_dwFreqCeiling;
- }
-
- // Check to see if the new freq is a preset. Go through each preset and
- // see if it is equal to the new current freq.
- m_iCurrentPreset[m_dwCurrentBand] = NO_PRESET;
- for(int i=0; i<10; i++)
- {
- if(m_Presets[m_dwCurrentBand][i].dwFreqValue == m_dwCurrentFreq[m_dwCurrentBand])
- {
- // If new frequency is a preset, save the preset number in a variable
- m_iCurrentPreset[m_dwCurrentBand] = i;
- break;
- }
- }
-
- // Tune to the new freq now!
- // Get current configuration
- TunerGetConfig(m_hTuner, &tc);
-
- // Change just the frequency configured to
- tc.CurrentFreq.dwFreqValue = m_dwCurrentFreq[m_dwCurrentBand];
-
- // Set the tuner to the new configuration
- TunerSetConfig(m_hTuner, &tc);
-
- // Update the radio form's display
- UpdateRadio();
- }
-
- /*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- Function:
- CTuneitApp::PreviousPreset
-
- Description:
- Moves to the previous preset in the list. If we aren't currently on a
- valid preset frequency, it goes to the last preset in the list. If we
- are on the first preset in the list, we go to the last preset.
-
- Parameters:
- Nothing.
-
- Returns:
- Nothing.
- -------------------------------------------------------------------*/
- void
- CTuneitApp::PreviousPreset()
- {
- // If the lowest preset in the preset list is not valid, then
- // none of the other presets in the list are valid, so we just return
- // without doing anything.
- if(m_Presets[m_dwCurrentBand][0].dwFreqValue == NO_PRESET)
- {
- return;
- }
-
- // If we are currently not on a preset, we start at the top
- // of the preset list and work down till we find the last valid preset
- // in the list, then we tune to that.
- if(m_iCurrentPreset[m_dwCurrentBand] == NO_PRESET)
- {
- for(int i=9; i >= 0; i--)
- { // Find last
- if(m_Presets[m_dwCurrentBand][i].dwFreqValue != NO_PRESET)
- {
- // Found a filled preset, set CurrentPreset to it and call
- // TuneToPreset which tunes to whatever preset is set in CurrentPreset
- m_iCurrentPreset[m_dwCurrentBand] = i;
- TuneToPreset();
- return;
- }
- }
- }
- else
- {
- // In the normal case, we are on a preset, and hit back, we go to the
- // Previous preset
- m_iCurrentPreset[m_dwCurrentBand]--;
-
- // If we are at the beginning of the preset list, we loop and find the
- // last preset in the list
- if(m_iCurrentPreset[m_dwCurrentBand] < 0)
- { // Find last
- for(int i=9; i >= 0; i--)
- {
- if(m_Presets[m_dwCurrentBand][i].dwFreqValue != NO_PRESET)
- {
- // Found a filled preset, Tune to it
- m_iCurrentPreset[m_dwCurrentBand] = i;
- TuneToPreset();
- return;
- }
- }
- }
-
- // If we didn't have to search through the list, we just Tune to the
- // new preset
- else TuneToPreset();
- }
- }
-
- /*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- Function:
- CTuneitApp::NextPreset
-
- Description:
- Moves to the next preset in the preset list. If we are currently not
- on any preset, we go to the first preset in the list. If we go
- to the end of the list, we loop back to the first preset.
-
- Parameters:
- Nothing.
-
- Returns:
- Nothing.
- -------------------------------------------------------------------*/
- void
- CTuneitApp::NextPreset()
- {
-
- // If the lowest preset in the preset list is not valid, then
- // none of the other presets in the list are valid, so we just return
- // without doing anything.
- if(m_Presets[m_dwCurrentBand][0].dwFreqValue == NO_PRESET)
- {
- return;
- }
-
- // Move to next preset
- m_iCurrentPreset[m_dwCurrentBand]++;
-
- // If the new preset we are on isn't valid (meaning we are at the end of the list),
- // we go back to the first preset in the list. (preset 0)
- if(m_Presets[m_dwCurrentBand][m_iCurrentPreset[m_dwCurrentBand]].dwFreqValue == NO_PRESET)
- {
- m_iCurrentPreset[m_dwCurrentBand] = 0;
- }
-
- // Tune to the new preset we are on
- TuneToPreset();
- }
-
- /*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- Function:
- CTuneitApp::PreSetPreset
-
- Description:
- This function gets called before the edit box turns into editing
- mode. We set the new state we are going to be in, and set blank
- the text in the edit box to null if we aren't on a preset.
-
- Parameters:
- Nothing.
-
- Returns:
- Nothing.
- -------------------------------------------------------------------*/
- void
- CTuneitApp::PreSetPreset()
- {
- m_State = SET_PRESET;
-
- if(m_iCurrentPreset[m_dwCurrentBand] == NO_PRESET)
- {
- m_pEditPreset->put_Text(NULL);
- }
- }
-
- /*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- Function:
- CTuneitApp::DoneSetPreset
-
- Description:
- This function gets called after we commit a change to the preset
- name, or if we exit from the edit box editing mode.
-
- Parameters:
- BOOL - TRUE saves into a preset slot, FALSE just sets things back
- to our primary state.
-
- Returns:
- Nothing.
- -------------------------------------------------------------------*/
- void
- CTuneitApp::DoneSetPreset(BOOL bSave)
- {
- // Sets our state variable telling that we are in the main view
- m_State = PRIMARY;
-
- // If we aren't going to save into a preset slot set text to "No Preset"
- // if we weren't on a preset and update radio display.
- if(bSave == FALSE)
- {
- if(m_iCurrentPreset[m_dwCurrentBand] == NO_PRESET)
- {
- m_pEditPreset->put_Text(m_bstrNoPreset);
- }
- UpdateRadio();
- return;
- }
-
- // Make sure they didn't enter something of length 0
- short nc;
- m_pEditPreset->get_NumChars(&nc);
- if(nc == 0) // If they entered something of 0 length
- {
- UpdateRadio();
- return;
- }
-
- int i;
-
- // If we aren't currently on a preset, save it in the next available preset slot.
- if(m_iCurrentPreset[m_dwCurrentBand] == NO_PRESET)
- { // New preset
- for(i=0; i<10; i++)
- {
- if(wcslen(m_bstrPresets[m_dwCurrentBand][i]) == 0)
- {
- m_pEditPreset->get_Text(&m_bstrPresets[m_dwCurrentBand][i]);
- m_Presets[m_dwCurrentBand][i].dwFreqValue = m_dwCurrentFreq[m_dwCurrentBand];
- m_iCurrentPreset[m_dwCurrentBand] = i;
- break;
- }
- }
- }
- else
- { // We were already on a preset just save the name
- m_pEditPreset->get_Text(&m_bstrPresets[m_dwCurrentBand][m_iCurrentPreset[m_dwCurrentBand]]);
- }
- UpdateRadio();
- }
-
- /*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- Function:
- CTuneitApp::DoneSettings
-
- Description:
- This function gets called after the settings menu is exited.
- It sets everything back to the primary state's normals.
-
- Parameters:
- Nothing.
-
- Returns:
- Nothing.
- -------------------------------------------------------------------*/
- void
- CTuneitApp::DoneSettings()
- {
- // Keep track of state change
- m_State = PRIMARY;
-
- // Hide the menu settings PowerListBox
- m_pMenuSettings->put_Visible(FALSE);
-
- // Change the form caption (titlebar) to show we're now in main view
- m_pFormRadio->put_Caption(m_bstrTuneitMain);
-
- // Set focus on Edit control
- m_pFormRadio->SetFocus(m_pEditPreset);
-
- // Update the radio view
- UpdateRadio();
- }
-
- /*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- Function:
- CTuneitApp::VolumeUp
-
- Description:
- Increase the audio volume one step. Actually lowers the volume variable,
- becuase on the Auto PC we speak of volume attenuation, so lower volume
- level is actually louder.
-
- Parameters:
- Nothing.
-
- Returns:
- Nothing.
- -------------------------------------------------------------------*/
- void CTuneitApp::VolumeUp()
- {
- if (m_lVolume > m_lVolMin) m_lVolume--;
- AAM_VolumeControl(AAM_FLAG_VOLUME | AAM_FLAG_SET, &m_lVolume);
-
- // Update view
- UpdateRadio();
- }
-
- /*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- Function:
- CTuneitApp::VolumeUp
-
- Description:
- Decreases the audio volume one step. Actually increases the volume variable,
- becuase on the Auto PC we speak of volume attenuation, so the higher the
- volume level set, the quiter the audio actually is.
-
- Parameters:
- Nothing.
-
- Returns:
- Nothing.
- -------------------------------------------------------------------*/
- void CTuneitApp::VolumeDown()
- {
- if (m_lVolume < m_lVolMax) m_lVolume++;
- AAM_VolumeControl(AAM_FLAG_VOLUME | AAM_FLAG_SET, &m_lVolume);
-
- UpdateRadio();
- }
-
- /*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- Function:
- CTuneitApp::Is*
-
- Description:
- State functions just return TRUE/FALSE if they are in that state
- or not. Used by message sinks since same message needs to be handled
- differently in different states. The states are PRIMARY (main view),
- SET_PRESET (edit box in editing mode), and SETTINGS (Settings menu up).
-
- Parameters:
- Nothing.
-
- Returns:
- BOOL - TRUE, in that state. FLASE, not in that state.
- -------------------------------------------------------------------*/
-
- BOOL
- CTuneitApp::IsPrimary()
- {
- if(m_State == PRIMARY) return TRUE;
- else return FALSE;
- }
-
- BOOL
- CTuneitApp::IsSetPreset()
- {
- if(m_State == SET_PRESET) return TRUE;
- else return FALSE;
- }
-
- BOOL
- CTuneitApp::IsSettings()
- {
- if(m_State == SETTINGS) return TRUE;
- else return FALSE;
- }
-
- /*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- Function:
- CTuneitApp::OnMenu
-
- Description:
- Function called when menu key pressed. Sets the Settings Menu to
- visible and changes the caption on the titlebar.
-
- Parameters:
- Nothing.
-
- Returns:
- Nothing.
- -------------------------------------------------------------------*/
- void
- CTuneitApp::OnMenu()
- {
- m_State = SETTINGS;
-
- m_pFormRadio->put_Caption(m_bstrTuneitSettings);
-
- m_pMenuSettings->put_Visible(TRUE);
- m_pFormRadio->SetFocus(m_pMenuSettings);
- }
-
- /*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- Function:
- WinMain
-
- Description:
- Standard Windows entry point.
-
- Parameters:
- Standard Win32 CE parameters
- -------------------------------------------------------------------*/
- int APIENTRY WinMain(HINSTANCE hInst,
- HINSTANCE hPrevInst,
- LPWSTR wszCmd,
- int nCmdShow)
- {
- MSG msg;
-
- g_pApp = new CTuneitApp(hInst); // Allocate our new App Class object
-
- CoInitializeEx( NULL, COINIT_MULTITHREADED ); // Initialize COM
- HRESULT hr = InitASFormsManager(); // Initialize the forms manager
- if(FAILED(hr))
- {
- CoUninitialize();
- return FALSE;
- }
-
- if(SUCCEEDED(g_pApp->Init()))
- {
- while (GetMessage(&msg, NULL, 0, 0)) // loop until the application quits
- {
- if(msg.hwnd) DispatchMessage(&msg);
- else g_pApp->m_pEventSink->ReceiveMsg(msg.message, msg.wParam, msg.lParam);
- }
- }
- g_pApp->CleanUp();
- delete g_pApp;
-
- UnInitASFormsManager(); // uninitialize the forms manager
- CoUninitialize(); // uninitialize COM
-
- return TRUE;
- }
-
-