📄 applicationinstallerdlg.cpp
字号:
/*
Filename : InstallerDlg.cpp
Part of : Application installer
Description : Implementation of application installers dialog class
Version : 3.2
This example is only to be used with PC Connectivity API version 3.2.
Compability ("as is") with future versions is not quaranteed.
Copyright (c) 2007 Nokia Corporation.
This material, including but not limited to documentation and any related
computer programs, is protected by intellectual property rights of Nokia
Corporation and/or its licensors.
All rights are reserved. Reproducing, modifying, translating, or
distributing any or all of this material requires the prior written consent
of Nokia Corporation. Nokia Corporation retains the right to make changes
to this material at any time without notice. A copyright license is hereby
granted to download and print a copy of this material for personal use only.
No other license to any other intellectual property rights is granted. The
material is provided "as is" without warranty of any kind, either express or
implied, including without limitation, any warranty of non-infringement,
merchantability and fitness for a particular purpose. In no event shall
Nokia Corporation be liable for any direct, indirect, special, incidental,
or consequential loss or damages, including but not limited to, lost profits
or revenue,loss of use, cost of substitute program, or loss of data or
equipment arising out of the use or inability to use the material, even if
Nokia Corporation has been advised of the likelihood of such damages occurring.
*/
#include "stdafx.h"
#include "ApplicationInstaller.h"
#include "ApplicationInstallerDlg.h"
#include "PCCSUtils.h"
#include "Shlwapi.h"
#include ".\ApplicationInstallerdlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
// Global variable to inform cancelling of install operation
BOOL g_bCancel = FALSE;
CApplicationInstallerDlg* g_pDlg = NULL;
//===================================================================
// Messagemap
//
//===================================================================
BEGIN_MESSAGE_MAP(CApplicationInstallerDlg, CDialog)
//{{AFX_MSG_MAP(CApplicationInstallerDlg)
ON_CBN_SELCHANGE(IDC_COMBO_PHONE, OnCbnSelchangeComboPhone)
ON_CBN_SELCHANGE(IDC_COMBO_TYPE, OnTypeSelected)
ON_BN_CLICKED(IDC_BUTTON_SIS, OnButtonSis)
ON_BN_CLICKED(IDC_BUTTON_JAR, OnButtonJar)
ON_BN_CLICKED(IDC_BUTTON_JAD, OnButtonJad)
ON_BN_CLICKED(IDC_BUTTON_NTH, OnBnClickedButtonNth)
ON_BN_CLICKED(IDC_BUTTON_N_GAGE, OnBnClickedButtonNGage)
ON_BN_CLICKED(ID_INSTALL, OnInstall)
ON_BN_CLICKED(ID_CANCEL, OnButtonCancel)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
//===================================================================
// DeviceNotifyCallback
//
// Callback function for device connection notifications
//
//===================================================================
static DWORD CALLBACK DeviceNotifyCallback(DWORD dwStatus, WCHAR* pstrSerialNumber)
{
switch( GET_CONAPI_CB_STATUS(dwStatus) )
{
case CONAPI_DEVICE_LIST_UPDATED:
TRACE(_T("DeviceNotifyCallback(CONAPI_DEVICE_LIST_UPDATED)\n"));
break;
case CONAPI_DEVICE_ADDED:
TRACE(_T("DeviceNotifyCallback(CONAPI_DEVICE_ADDED) %s\n"), pstrSerialNumber);
break;
case CONAPI_DEVICE_REMOVED:
TRACE(_T("DeviceNotifyCallback(CONAPI_DEVICE_REMOVED) %s\n"), pstrSerialNumber);
break;
case CONAPI_DEVICE_UPDATED:
TRACE(_T("DeviceNotifyCallback(CONAPI_DEVICE_UPDATED) %s\n"), pstrSerialNumber);
break;
default:
break;
}
// Get mainwindow and refresh phone list
if(g_pDlg) g_pDlg->RefreshPhoneList();
return CONA_OK;
}
//===================================================================
// FileOperationCallback
//
// Callback function for file transfer notifications
//
//===================================================================
static DWORD CALLBACK FileOperationCallback(DWORD dwFSFunction, DWORD dwState, DWORD dwTransferredBytes, DWORD dwAllBytes)
{
TRACE(_T("FileOperationCallback(0x%x,%i,%i,%i)\n"), dwFSFunction, dwState, dwTransferredBytes, dwAllBytes);
DWORD dwRetCallback = CONA_OK;
// Dispatch sent messages, perhaps Cancel button is pressed?
MSG msg;
while( ::PeekMessage(&msg, NULL, 0, 0, PM_NOREMOVE) )
AfxGetThread()->PumpMessage();
if( dwFSFunction == CONAInstallApplicationNtf && g_pDlg)
{
if( dwState == CONA_OK_BUT_USER_ACTION_NEEDED )
{
// Hide progressbar and show label stating that
// application installation is at waiting state
CProgressCtrl* pProgress = (CProgressCtrl*)g_pDlg->GetDlgItem(IDC_PROGRESS);
pProgress->ShowWindow(SW_HIDE);
CStatic* pStatic = (CStatic*)g_pDlg->GetDlgItem(IDC_STATIC_WAIT);
pStatic->ShowWindow(SW_SHOW);
}
else
{
// Set progressbar
if(g_pDlg) g_pDlg->SetProgress(dwState);
}
}
// Is application installation cancelled?
if( g_bCancel )
{
dwRetCallback = ECONA_CANCELLED;
g_bCancel = FALSE;
}
return dwRetCallback;
}
//===================================================================
// Constructor
//
//===================================================================
CApplicationInstallerDlg::CApplicationInstallerDlg(CWnd* pParent /*=NULL*/)
: CDialog(CApplicationInstallerDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CApplicationInstallerDlg)
// NOTE: the ClassWizard will add member initialization here
//}}AFX_DATA_INIT
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
m_hDMHandle = NULL;
}
//===================================================================
// Destructor
//
//===================================================================
CApplicationInstallerDlg::~CApplicationInstallerDlg()
{
// Unegister device notification callback function
DWORD dwRet = CONARegisterNotifyCallback(m_hDMHandle, API_UNREGISTER, (PFN_CONA_DEVICE_CALLBACK) DeviceNotifyCallback);
if (dwRet != CONA_OK) ErrorMessageDlg(_T("CONARegisterNotifyCallback"), dwRet);
// Close device management handle
dwRet = CONACloseDM(m_hDMHandle);
if(dwRet != CONA_OK) ErrorMessageDlg(_T("CONACloseDM"), dwRet);
}
//===================================================================
// DoDataExchange
//
//===================================================================
void CApplicationInstallerDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CApplicationInstallerDlg)
DDX_Control(pDX, ID_CANCEL, m_btnCancel);
DDX_Control(pDX, IDC_PROGRESS, m_progressBar);
DDX_Control(pDX, IDC_STATIC_WAIT, m_sWait);
DDX_Control(pDX, ID_INSTALL, m_btnInstall);
DDX_Control(pDX, IDC_BUTTON_JAD, m_btnJAD);
DDX_Control(pDX, IDC_BUTTON_JAR, m_btnJAR);
DDX_Control(pDX, IDC_BUTTON_SIS, m_btnSIS);
DDX_Control(pDX, IDC_EDIT_SIS, m_editSIS);
DDX_Control(pDX, IDC_EDIT_JAR, m_editJAR);
DDX_Control(pDX, IDC_EDIT_JAD, m_editJAD);
DDX_Control(pDX, IDC_EDIT_NTH, m_editNTH);
DDX_Control(pDX, IDC_BUTTON_NTH, m_btnNTH);
DDX_Control(pDX, IDC_EDIT_N_GAGE, m_editNGAGE);
DDX_Control(pDX, IDC_BUTTON_N_GAGE, m_btnNGAGE);
DDX_Control(pDX, IDC_COMBO_TYPE, m_comboTypes);
DDX_Control(pDX, IDC_COMBO_PHONE, m_comboPhones);
//}}AFX_DATA_MAP
}
//===================================================================
// OnInitDialog
//
// Initializes user interface and register device notify callback
//
//===================================================================
BOOL CApplicationInstallerDlg::OnInitDialog()
{
CDialog::OnInitDialog();
g_pDlg = this;
SetIcon(m_hIcon, TRUE);
SetIcon(m_hIcon, FALSE);
m_progressBar.SetRange(0, 100);
m_progressBar.SetPos(0);
m_comboTypes.SetCurSel(0);
m_btnCancel.EnableWindow(FALSE);
// Get Device management handle
DWORD dwRet = CONAOpenDM(&m_hDMHandle);
if(dwRet != CONA_OK) ErrorMessageDlg(_T("CONAOpenDM"), dwRet);
RefreshPhoneList(); // Get connected devices list
// Register device notification callback function
dwRet = CONARegisterNotifyCallback(m_hDMHandle, API_REGISTER, (PFN_CONA_DEVICE_CALLBACK) DeviceNotifyCallback);
if(dwRet != CONA_OK) ErrorMessageDlg(_T("CONARegisterNotifyCallback"), dwRet);
return TRUE;
}
//===================================================================
// OnCbnSelchangeComboPhone
//
// User has seleted phone from combobox
//
//===================================================================
void CApplicationInstallerDlg::OnCbnSelchangeComboPhone()
{
m_comboTypes.ResetContent();
if(m_dwConnectionCount > 0)
{
int iSelected = m_comboPhones.GetCurSel();
if(m_dwFileSystemSupport[iSelected] & CONAPI_FS_INSTALL_JAVA_APPLICATIONS)
{
int iItem = m_comboTypes.AddString(L"Java");
m_comboTypes.SetItemData(iItem, INSTALL_TYPE_JAVA);
}
if(m_dwFileSystemSupport[iSelected] & CONAPI_FS_INSTALL_SIS_APPLICATIONS)
{
int iItem = m_comboTypes.AddString(L"SIS");
m_comboTypes.SetItemData(iItem, INSTALL_TYPE_SIS);
}
if(m_dwType[iSelected] & CONAPI_SERIES40_DEVICE)
{
int iItem = m_comboTypes.AddString(L"Themes");
m_comboTypes.SetItemData(iItem, INSTALL_TYPE_THEMES);
}
int iItem = m_comboTypes.AddString(L"N-Gage");
m_comboTypes.SetItemData(iItem, INSTALL_TYPE_NGAGE);
m_comboTypes.SetCurSel(0);
}
}
//===================================================================
// OnTypeSelected
//
// User has changed installation type from combobox,
// so make some UI changes
//
//===================================================================
void CApplicationInstallerDlg::OnTypeSelected()
{
DWORD dwInstallType = (DWORD)m_comboTypes.GetItemData(m_comboTypes.GetCurSel());
BOOL bIsJava = (dwInstallType == INSTALL_TYPE_JAVA);
BOOL bIsSymbian = (dwInstallType == INSTALL_TYPE_SIS);
BOOL bIsThemes = (dwInstallType == INSTALL_TYPE_THEMES);
BOOL bIsNgage = (dwInstallType == INSTALL_TYPE_NGAGE);
m_editJAR.EnableWindow(bIsJava);
m_editJAD.EnableWindow(bIsJava);
m_btnJAR.EnableWindow(bIsJava);
m_btnJAD.EnableWindow(bIsJava);
m_editSIS.EnableWindow(bIsSymbian);
m_btnSIS.EnableWindow(bIsSymbian);
m_editNTH.EnableWindow(bIsThemes);
m_btnNTH.EnableWindow(bIsThemes);
m_editNGAGE.EnableWindow(bIsNgage);
m_btnNGAGE.EnableWindow(bIsNgage);
}
//===================================================================
// SetProgress
//
// Advances progressbar on application installation
//
//===================================================================
void CApplicationInstallerDlg::SetProgress(DWORD dwState)
{
m_progressBar.SetPos(dwState);
}
//===================================================================
// RefreshPhoneList
//
// Refresh phone list to combobox with all connection types
//
//===================================================================
void CApplicationInstallerDlg::RefreshPhoneList()
{
TRACE(_T("CApplicationInstallerDlg::RefreshPhoneList()\n"));
DWORD dwDeviceIndex = 0;
DWORD dwRet = CONA_OK;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -