⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 installdlg.cpp

📁 T3G的TD-SCDMA平台的驱动安装
💻 CPP
📖 第 1 页 / 共 2 页
字号:
// InstallDlg.cpp : implementation file
//

#include "stdafx.h"
#include "Install.h"
#include "InstallDlg.h"
#include "RegOperater.h"
#include <newdev.h> // for the API UpdateDriverForPlugAndPlayDevices().
#include <setupapi.h> // for SetupDiXxx functions.
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
typedef BOOL (WINAPI *UpdateDriverForPlugAndPlayDevicesProto)(HWND hwndParent,
															  LPCTSTR HardwareId,
															  LPCTSTR FullInfPath,
															  DWORD InstallFlags,
															  PBOOL bRebootRequired OPTIONAL
															  );
#define UPDATEDRIVERFORPLUGANDPLAYDEVICES "UpdateDriverForPlugAndPlayDevicesA"
/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About
#include "mmsystem.h"
//------------------------------------------------------------------------------
//	created:	2008-5=19  18:57
//	author:		xqzhou
//	
//  弹出光驱 	
//
//------------------------------------------------------------------------------
void ctrl_cdrom_door(LPCTSTR drivename ,bool fOpen)
{
	//	//drivename ,驱动器的名字如f:等.
	//	//fOpen,弹出时用true,弹入时用false
	TCHAR devstr[128], ctrlstr[128];
	wsprintf(devstr,_T("open %s type cdaudio alias mycd wait"),drivename);
	wsprintf(ctrlstr,_T("set mycd door %s wait"),fOpen?_T("open"):_T("closed"));
	mciSendString(devstr,NULL,0,NULL);
	mciSendString(ctrlstr,NULL,0,NULL);
	mciSendString(_T("close mycd wait"),NULL,0,NULL);
}

class CAboutDlg : public CDialog
{
public:
	CAboutDlg();
	
	// Dialog Data
	//{{AFX_DATA(CAboutDlg)
	enum { IDD = IDD_ABOUTBOX };
	//}}AFX_DATA
	
	// ClassWizard generated virtual function overrides
	//{{AFX_VIRTUAL(CAboutDlg)
protected:
	virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support
	//}}AFX_VIRTUAL
	
	// Implementation
protected:
	//{{AFX_MSG(CAboutDlg)
	//}}AFX_MSG
	DECLARE_MESSAGE_MAP()
};

CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
	//{{AFX_DATA_INIT(CAboutDlg)
	//}}AFX_DATA_INIT
}

void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CAboutDlg)
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
//{{AFX_MSG_MAP(CAboutDlg)
// No message handlers
//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CInstallDlg dialog

CInstallDlg::CInstallDlg(CWnd* pParent /*=NULL*/)
: CDialog(CInstallDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CInstallDlg)
	m_strInstallMessage = _T("");
	//}}AFX_DATA_INIT
	// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}

void CInstallDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CInstallDlg)
	DDX_Control(pDX, IDC_BUTTON_INSTALL, m_btInstall);
	DDX_Control(pDX, IDC_BUTTON_EWALK, m_btEwalk);
	DDX_Control(pDX, IDC_BUTTON_EJECT, m_btEject);
	DDX_Text(pDX, IDC_EDIT1, m_strInstallMessage);
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CInstallDlg, CDialog)
//{{AFX_MSG_MAP(CInstallDlg)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_BN_CLICKED(IDC_BUTTON_INSTALL, OnButtonInstall)
ON_BN_CLICKED(IDC_BUTTON_EJECT, OnButtonEject)
ON_BN_CLICKED(IDC_BUTTON_EWALK, OnButtonEwalk)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CInstallDlg message handlers

BOOL CInstallDlg::OnInitDialog()
{
	CDialog::OnInitDialog();
	
	// Add "About..." menu item to system menu.
	
	// IDM_ABOUTBOX must be in the system command range.
	ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
	ASSERT(IDM_ABOUTBOX < 0xF000);
	
	CMenu* pSysMenu = GetSystemMenu(FALSE);
	if (pSysMenu != NULL)
	{
		CString strAboutMenu;
		strAboutMenu.LoadString(IDS_ABOUTBOX);
		if (!strAboutMenu.IsEmpty())
		{
			pSysMenu->AppendMenu(MF_SEPARATOR);
			pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
		}
	}
	
	// Set the icon for this dialog.  The framework does this automatically
	//  when the application's main window is not a dialog
	SetIcon(m_hIcon, TRUE);			// Set big icon
	SetIcon(m_hIcon, FALSE);		// Set small icon
	
	// TODO: Add extra initialization here
	char path[MAX_PATH];         //MAX_PATH
	GetTempPath(MAX_PATH,   path);   
	m_strTempPath = path;
	
	m_strInstallMessage = "";
	//m_btInstall.EnableWindow(FALSE);
	//m_btEject.EnableWindow(FALSE);
	
	//UpdateData(FALSE);
	AutoRunEject();
	OnButtonEject();
	OnButtonEwalk();
	
	return TRUE;  // return TRUE  unless you set the focus to a control
}

void CInstallDlg::OnSysCommand(UINT nID, LPARAM lParam)
{
	if ((nID & 0xFFF0) == IDM_ABOUTBOX)
	{
		CAboutDlg dlgAbout;
		dlgAbout.DoModal();
	}
	else
	{
		CDialog::OnSysCommand(nID, lParam);
	}
}

// If you add a minimize button to your dialog, you will need the code below
//  to draw the icon.  For MFC applications using the document/view model,
//  this is automatically done for you by the framework.

void CInstallDlg::OnPaint() 
{
	if (IsIconic())
	{
		CPaintDC dc(this); // device context for painting
		
		SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);
		
		// Center icon in client rectangle
		int cxIcon = GetSystemMetrics(SM_CXICON);
		int cyIcon = GetSystemMetrics(SM_CYICON);
		CRect rect;
		GetClientRect(&rect);
		int x = (rect.Width() - cxIcon + 1) / 2;
		int y = (rect.Height() - cyIcon + 1) / 2;
		
		// Draw the icon
		dc.DrawIcon(x, y, m_hIcon);
	}
	else
	{
		CDialog::OnPaint();
	}
}

// The system calls this to obtain the cursor to display while the user drags
//  the minimized window.
HCURSOR CInstallDlg::OnQueryDragIcon()
{
	return (HCURSOR) m_hIcon;
}
//------------------------------------------------------------------------------
//	created:	2008-5=19  18:21
//	author:		xqzhou
//	安装驱动
//	
//------------------------------------------------------------------------------
void CInstallDlg::OnButtonInstall() 
{
	CRegOperate regOp; //定义一个注册表操作对象
	CRegOperate::err e; //定义一个错误枚举变量,用来标识注册表操作结果
	CString str = "";  //查询得到的注册表项的值
	//获取版本
	CString strTempVer = m_strDriverVersion;
	
	//m_strInstallMessage = "正在安装驱动...";
	//UpdateData(FALSE);

	//查询注册表项值
	e = regOp.GetStrValue((HKEY)regOp.DHKEY_LOCAL_MACHINE, "SOFTWARE\\WICOM\\eWalk\\", "InstallVersion", str);
	if(str.IsEmpty())
	{
		e = regOp.AddSubKey((HKEY)regOp.DHKEY_LOCAL_MACHINE, "SOFTWARE\\WICOM\\eWalk\\");
		//判断不成功
		if (e != CRegOperate::ERR_SUCCESS) { 
			MessageBox("创建子键失败");
			return;
		}
		/**/
		//设置识注册表项值
		e = regOp.SetStrValue((HKEY)regOp.DHKEY_LOCAL_MACHINE, "SOFTWARE\\WICOM\\eWalk\\", "InstallVersion", m_strDriverVersion);
		//当然错误信息还可以更加丰富
		if (e == CRegOperate::ERR_OPENREGKEY)
		{
			MessageBox("打开主键键失败");
			return;
		}
		else if (e == CRegOperate::ERR_SETREGVALUE)
		{
			MessageBox("设置注册表项值失败");
			return;
		}
		
		//安装驱动
		//WinExec("setup.exe", SW_SHOW); 
		Installdriver();
		
	}
	else
	{
		if(strTempVer > str)
		{
			//安装驱动
			//WinExec("setup.exe", SW_SHOW); 
			Installdriver();
			
		}
		else
		{
			CString strtmp = "已经安装V" + str + "版本的驱动";
			AfxMessageBox(strtmp);	
			Eject();
		}
	}
//	m_btEject.EnableWindow(TRUE);
	
	
}
//------------------------------------------------------------------------------
//	created:	2008-5=19  18:59
//	author:		xqzhou
//	弹出光驱	
//	
//------------------------------------------------------------------------------
void CInstallDlg::Eject() 
{
	_ULARGE_INTEGER result_freespace,result_totalspace,result_g;
	int free_space,total_space;
	
	CString strdir;
	CString disk;
	CString disk_space;
	
	int totalbulk=0;
	int freebulk=0;
	
	for(char cc='D';cc<='Z';cc++)
	{
		strdir.Format("%c:",cc);
		if(GetDriveType((LPCTSTR)strdir)==DRIVE_CDROM)
		{
			GetDiskFreeSpaceEx(strdir,&result_freespace,&result_totalspace,&result_g);
			free_space = result_freespace.QuadPart/1024/1024;
			total_space = result_totalspace.QuadPart/1024/1024;
			//TRACE(strdir);
			//TRACE("total_space:%dM\n", total_space);
			if( total_space == 67 )
			{
				ctrl_cdrom_door(strdir,true);				
			}
			
		}
	}
}

//------------------------------------------------------------------------------
//	created:	2008-5=19  19:26
//	author:		xqzhou
//	
//	
//------------------------------------------------------------------------------
void CInstallDlg::OnButtonEject() 
{
	//CopyFileToTempDir();
	//copy 文件覆盖
	CRegOperate regOp; //定义一个注册表操作对象
	CRegOperate::err e; //定义一个错误枚举变量,用来标识注册表操作结果
	CString str = "";  //查询得到的注册表项的值
	CString strFileName = "DeviceInfo.xml";
	//查询注册表项值
	e = regOp.GetStrValue((HKEY)regOp.DHKEY_LOCAL_MACHINE, "SOFTWARE\\China Mobile\\eWalk", "ExePath", str);
	if (str.GetLength() > 0) 
	{
		str = str + "\\" + strFileName;
		CopyFile(strFileName, str, FALSE);	
	}
	
	//
	Eject();
	CDialog::OnOK();
	/*	*/
}
//------------------------------------------------------------------------------
//	created:	2008-5-20  10:10
//	author:		xqzhou
//	
// 安装随e行	
//------------------------------------------------------------------------------
void CInstallDlg::OnButtonEwalk() 
{
	CRegOperate regOp; //定义一个注册表操作对象
	CRegOperate::err e; //定义一个错误枚举变量,用来标识注册表操作结果
	CString str = "";  //查询得到的注册表项的值
	//获取版本
	CString strTempVer = m_strEwalkVersion;
	//m_strInstallMessage = "正在安装随意行...";
	//UpdateData(FALSE);
	//查询注册表项值
	e = regOp.GetStrValue((HKEY)regOp.DHKEY_LOCAL_MACHINE, "SOFTWARE\\China Mobile\\eWalk", "version", str);
	if(e == CRegOperate::ERR_SUCCESS)
	{
		if(strTempVer > str)
		{
			//安装驱动
			CString strtmp = "已经安装V" + str + "版本的程序, 是否覆盖安装新版本的程序?";
			if( IDYES == AfxMessageBox(strtmp,MB_YESNO ))
			{
				CString strtmpFile;
				strtmpFile = m_strTempPath + "eWalk_Olympics.exe";
				WinExec(strtmpFile, SW_SHOW); 

			}
			else
			{
				//AfxMessageBox("");
				
			}
			
		}
		else

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -