📄 kukuupdatedlg.cpp
字号:
// kukuupdateDlg.cpp : implementation file
//
#include "stdafx.h"
#include "kukuupdate.h"
#include "kukuupdateDlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About
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()
/////////////////////////////////////////////////////////////////////////////
// CKukuupdateDlg dialog
CKukuupdateDlg::CKukuupdateDlg(CWnd* pParent /*=NULL*/)
: CDialog(CKukuupdateDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CKukuupdateDlg)
m_show = _T("");
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
void CKukuupdateDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CKukuupdateDlg)
DDX_Text(pDX, IDC_EDIT1, m_show);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CKukuupdateDlg, CDialog)
//{{AFX_MSG_MAP(CKukuupdateDlg)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_WM_TIMER()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CKukuupdateDlg message handlers
BOOL CKukuupdateDlg::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
::SetTimer(m_hWnd,1,1000,NULL);
return TRUE; // return TRUE unless you set the focus to a control
}
void CKukuupdateDlg::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 CKukuupdateDlg::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 CKukuupdateDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
// 获取下载路径
CString CKukuupdateDlg::GetDownloadPath(void)
{
char szTemp[255];
GetTempPath(255,szTemp);
return (LPCSTR)szTemp;
}
void CKukuupdateDlg::OnTimer(UINT nIDEvent)
{
// TODO: Add your message handler code here and/or call default
::KillTimer(m_hWnd,1); // 停止定时器的调用
m_show = "正在连接升级服务...";
UpdateData(FALSE);
int Ret = URLDownloadToFile(NULL,"http://www.3kuku.com/version.txt",(GetDownloadPath() + "version.txt"),0,NULL);
if (Ret == S_OK)
{
// 下载成功
m_show = "下载更新信息成功,正在解析更新信息...";
UpdateData(FALSE);
// 解析文件,获取版本信息
char m_RmtVerion[10];
char m_DownldUrl[255];
char m_newSoft[50];
int m_RemoteVersion = 0;
CString m_DownLoadUrl = "";
CString m_SoftName ="";
int m_localVersion = 0;
GetPrivateProfileString("AutoUpdate","NewVerion",NULL,m_RmtVerion,10,GetDownloadPath()+"version.txt");
m_RemoteVersion = atoi(m_RmtVerion);
GetPrivateProfileString("AutoUpdate","NewSoft",NULL,m_newSoft,50,GetDownloadPath()+"version.txt");
m_SoftName = (LPCSTR)m_newSoft;
GetPrivateProfileString("AutoUpdate","Url",NULL,m_DownldUrl,255,GetDownloadPath()+"version.txt");
m_DownLoadUrl = (LPCSTR)m_DownldUrl;
// 获取本地版本号
m_localVersion = GetLocalVersion();
// 判断是否需要更新
if (m_localVersion < m_RemoteVersion)
{
// 需要升级,下载远程文件
int RetR = URLDownloadToFile(NULL,m_DownLoadUrl,(GetDownloadPath()+ m_SoftName),0,NULL);
if (RetR == S_OK)
{
ShellExecute(m_hWnd,"open",(GetDownloadPath()+ m_SoftName),NULL,NULL,SW_SHOWNORMAL);
this->SendMessage(WM_CLOSE);
}
else
{
AfxMessageBox("下载远程升级文件失败!");
ShellExecute(m_hWnd,"open","KUKU.EXE",NULL,NULL,SW_SHOWNORMAL);
}
}
else if (m_localVersion == m_RemoteVersion)
{
m_show = "你的版本是最新版,不需要更新!";
UpdateData(FALSE);
}
}
else
{
// 下载失败
AfxMessageBox("请检查网络连接!");
ShellExecute(m_hWnd,"open","KUKU.EXE",NULL,NULL,SW_SHOWNORMAL);
}
CDialog::OnTimer(nIDEvent);
}
CString CKukuupdateDlg::GetIniFilePath(void)
{
char szPathName[255];
CString szTemp;
if(GetModuleFileName(NULL, szPathName, MAX_PATH) == 0)
{
TRACE(_T("获取配置文件路径错误!\r\n"));
}
szTemp = (LPCSTR)szPathName;
szTemp.Replace("kukuupdate.exe","SYSCONF.INF");
return szTemp;
}
int CKukuupdateDlg::GetLocalVersion()
{
char localv[10];
GetPrivateProfileString("version","localverion",NULL,localv,10,GetIniFilePath());
TRACE("%s\r\n",localv);
return atoi(localv);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -