📄 liveupdatedlg.cpp
字号:
}
else
{
dataStore.WriteString(_T("到指定服务器的连接建立失败..."));
return FALSE;
}
return TRUE;
}
void CLiveUpdateDlg::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 CLiveUpdateDlg::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 CLiveUpdateDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
// ---------------------------------------------------------
// 名称: OnOK
// 功能: 复制升级程序到目标目录中
// 变量: 无
// 返回: 无
// 编写: 徐景周,2003.5.13
// ---------------------------------------------------------
void CLiveUpdateDlg::OnOK()
{
UpdateData(TRUE);
if(m_TargetPath.IsEmpty())
{
AfxMessageBox("请先选择安装目录");
return;
}
CString strTmp;
CFileFind fFind;
BOOL bSuccess = FALSE;
int nProgress = 0;
int nAverage = 100/Vector_Name.size();
for(Iter_FileName = Vector_FileName.begin(),Iter_Name = Vector_Name.begin(); (Iter_FileName != Vector_FileName.end())&&(Iter_Name != Vector_Name.end()); Iter_FileName++,Iter_Name++)
{
strTmp = m_TargetPath + "\\" + *(Iter_Name);
// 判断路径下是否有对应文件
bSuccess=fFind.FindFile(strTmp);
if(!bSuccess)
{
CString str;
str.Format("安装目录中没有原始文件:%s,是否安装新的升级文件(Y/N)", *(Iter_Name));
if(IDYES == AfxMessageBox(str,MB_YESNO)) // 复制新文件
{
BOOL bSucced = CopyFile(*(Iter_FileName), strTmp, FALSE);
if(!bSucced)
{
AfxMessageBox("被升级的文件可能正在使用或为只读属性!");
return;
}
}
}
else
{
// 为防止被升级文件为只读等属性,先将置为正常属性再置回原属性
DWORD dwAttr = GetFileAttributes(strTmp);
SetFileAttributes(strTmp, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_NORMAL);
BOOL bSucced = CopyFile(*(Iter_FileName), strTmp, FALSE);
if(!bSucced)
{
AfxMessageBox("正被升级的文件可能正在使用!");
return;
}
SetFileAttributes(strTmp, dwAttr); // 恢复文件源属性
}
nProgress += nAverage;
m_Progress.SetPos(nProgress);
}
m_Progress.SetPos(100);
fFind.Close();
AfxMessageBox("升级成功!");
}
// ---------------------------------------------------------
// 名称: OnButtonBrowse
// 功能: 选择目标目录并进行判断操作
// 变量: 无
// 返回: 无
// 编写: 徐景周,2003.5.13
// ---------------------------------------------------------
void CLiveUpdateDlg::OnButtonBrowse()
{
CDirDialog dlg;
if (IDOK == dlg.DoBrowse(this))
{
// 设置选中路径
m_TargetPath = dlg.m_strPath;
UpdateData(FALSE);
}
}
// ---------------------------------------------------------
// 名称: OnReg
// 功能: 对控件、组件进行注册
// 变量: 无
// 返回: 无
// 编写: 徐景周,2003.5.13
// ---------------------------------------------------------
void CLiveUpdateDlg::OnReg()
{
CFileDialog fileDialog( TRUE,"*.OCX, *.DLL",NULL,NULL,"控件或组件文件(*.dll,*.ocx)|*.ocx;*.dll|所有文件(*.*)|*.*||");
if (IDOK == fileDialog.DoModal())
{
CString pszDllName = fileDialog.GetPathName();
//已选控件、组件名是否为空
if(pszDllName=="")
{
MessageBox("请先选择您需要注册的控件或组件名称!","提示",MB_OK);
return;
}
//装载控件或组件
HINSTANCE hLib = LoadLibrary(pszDllName);
if (hLib < (HINSTANCE)HINSTANCE_ERROR)
{
MessageBox("不能载入该控件或组件文件!","错误",MB_OK);
return;
}
//获取注册函数DllRegisterServer地址
FARPROC lpDllEntryPoint;
lpDllEntryPoint = GetProcAddress(hLib,_T("DllRegisterServer"));
//调用注册函数DllRegisterServer
if(lpDllEntryPoint!=NULL)
{
if(FAILED((*lpDllEntryPoint)()))
{
MessageBox("控件或组件注册失败!","错误",MB_OK);
FreeLibrary(hLib);
return;
}
MessageBox("控件或组件注册成功","注册提示",MB_OK);
}
else
MessageBox("控件或组件注册失败!","错误",MB_OK);
}
}
// ---------------------------------------------------------
// 名称: OnUnreg
// 功能: 对控件、组件进行注销
// 变量: 无
// 返回: 无
// 编写: 徐景周,2003.5.13
// ---------------------------------------------------------
void CLiveUpdateDlg::OnUnreg()
{
CFileDialog fileDialog( TRUE,"*.OCX, *.DLL",NULL,NULL,"组件和控件文件(*.dll,*.ocx)|*.ocx;*.dll|所有文件(*.*)|*.*||");
if (IDOK == fileDialog.DoModal())
{
CString pszDllName = fileDialog.GetPathName();
//已选控件、组件名是否为空
if(pszDllName=="")
{
MessageBox("请先选择您需要注销的控件或组件名称!","提示",MB_OK);
return;
}
//装载控件或组件
HINSTANCE hLib = LoadLibrary(pszDllName);
if (hLib < (HINSTANCE)HINSTANCE_ERROR)
{
MessageBox("不能载入该控件或组件文件!","错误",MB_OK);
return;
}
//获取注销函数DllUnregisterServerr地址
FARPROC lpDllEntryPoint;
lpDllEntryPoint = GetProcAddress(hLib,_T("DllUnregisterServer"));
//调用注销函数DllUnRegisterServer
if(lpDllEntryPoint!=NULL)
{
if(FAILED((*lpDllEntryPoint)()))
{
MessageBox("控件或组件注销失败!","错误",MB_OK);
FreeLibrary(hLib);
return;
}
MessageBox("控件或组件注销成功","注销提示",MB_OK);
}
else
MessageBox("控件或组件注销失败!","错误",MB_OK);
}
}
// ---------------------------------------------------------
// 名称: OnCtlColor
// 功能: 定制对话框控件颜色
// 变量: 无
// 返回: 无
// 编写: 徐景周,2003.5.13
// ---------------------------------------------------------
HBRUSH CLiveUpdateDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);
if(nCtlColor==CTLCOLOR_LISTBOX)
{
// pDC->SetBkMode(TRANSPARENT);
// pDC->SetTextColor(RGB(0,0,0));
// pDC->SetBkColor(RGB(233,233,220));
// HBRUSH b=CreateSolidBrush(RGB(233,233,220));
// return b;
}
else if(nCtlColor==CTLCOLOR_SCROLLBAR)
{
}
else if(nCtlColor==CTLCOLOR_EDIT)
{
}
else if(nCtlColor==CTLCOLOR_STATIC)
{
}
else if(nCtlColor==CTLCOLOR_DLG)
{
}
else if(nCtlColor==CTLCOLOR_MSGBOX)
{
}
return hbr;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -