?? setupdlg.cpp
字號:
// SetupDlg.cpp : implementation file
//
#include "stdafx.h"
#include "Setup.h"
#include "SetupDlg.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()
/////////////////////////////////////////////////////////////////////////////
// CSetupDlg dialog
CSetupDlg::CSetupDlg(CWnd* pParent /*=NULL*/)
: CDialog(CSetupDlg::IDD, pParent)
{
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
void CSetupDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
}
BEGIN_MESSAGE_MAP(CSetupDlg, CDialog)
//{{AFX_MSG_MAP(CSetupDlg)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CSetupDlg message handlers
BOOL CSetupDlg::OnInitDialog()
{
CDialog::OnInitDialog();
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);
}
}
SetIcon(m_hIcon, TRUE);
SetIcon(m_hIcon, FALSE);
InstallFile();
return TRUE;
}
void CSetupDlg::OnSysCommand(UINT nID, LPARAM lParam)
{
if ((nID & 0xFFF0) == IDM_ABOUTBOX)
{
CAboutDlg dlgAbout;
dlgAbout.DoModal();
}
else
{
CDialog::OnSysCommand(nID, lParam);
}
}
void CSetupDlg::OnPaint()
{
if (IsIconic())
{
CPaintDC dc(this); // device context for painting
SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);
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;
dc.DrawIcon(x, y, m_hIcon);
}
else
{
CDialog::OnPaint();
}
}
HCURSOR CSetupDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
CString CSetupDlg::GetPath(char * Ver)
{
CString Path = "";
HKEY hKey;
char *SubKey;
if(strcmp(Ver, "組態王5.1") == 0)
SubKey = "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\App Paths\\組態王5.1";
else if(strcmp(Ver, "組態王6.0") == 0)
SubKey = "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\App Paths\\組態王6.0";
else
return Path;
//打開注冊表
if(RegOpenKeyEx(HKEY_LOCAL_MACHINE,SubKey,0,KEY_ALL_ACCESS,&hKey) != ERROR_SUCCESS)
return Path;
unsigned char buffer[200];
buffer[0]='\0';
unsigned long size = sizeof(buffer);
unsigned long ValueType = NULL;
//檢索鍵值
if(RegQueryValueEx(hKey,"Path",NULL,&ValueType,buffer,&size) != ERROR_SUCCESS)
return Path;
Path = buffer;
RegCloseKey(hKey);
return Path;
}
//////////////////////////////////////////////////////////////////////////////////
void CSetupDlg::InstallFile()
{
char * Ver = "組態王5.1";
((CSetupApp *)AfxGetApp())->AppPath = GetPath(Ver);
if(strcmp(((CSetupApp *)AfxGetApp())->AppPath,"") == 0)
{
Ver = "組態王6.0";
((CSetupApp *)AfxGetApp())->AppPath = GetPath(Ver);
if(strcmp(((CSetupApp *)AfxGetApp())->AppPath,"") == 0)
{
AfxMessageBox(" 沒有安裝組態王5.1 或組態王6.0,請退出本程序安裝組態王5.1或組態王6.0 ",MB_OK);
OnOK();
PostMessage(WM_QUIT);
return;
}
/*
// AfxMessageBox(" 沒有安裝組態王5.1,請退出本程序安裝組態王5.1 ",MB_OK);
AfxMessageBox(" 沒有安裝組態王6.0 或組態王6.0,請退出本程序安裝組態王5.1或組態王6.0 ",MB_OK);
OnOK();
PostMessage(WM_QUIT);
return;
*/
}
CString Path = ((CSetupApp *)AfxGetApp())->AppPath;
/* Path += "\\DevLst.dat";
if(!CopyFile("DevLst.dat",Path,FALSE))
{
if(AfxMessageBox(" 復制文件到" + Path + "失敗 ",MB_ICONHAND | MB_ICONSTOP | MB_ICONERROR | MB_ABORTRETRYIGNORE) != IDIGNORE)
{
OnOK();
PostMessage(WM_QUIT);
return;
}
}
*/
//請在這里修改代碼,加入要安裝的驅動程序名
//**************************************************************
Path = ((CSetupApp *)AfxGetApp())->AppPath ;
Path += "\\Devlst.dat"; //請修改這里的文件名
if(!CopyFile("Devlst.dat",Path,FALSE)) //請修改這里的文件名
{
if(AfxMessageBox(" 復制文件到" + Path + "失敗 ",MB_ICONHAND | MB_ICONSTOP | MB_ICONERROR | MB_ABORTRETRYIGNORE) != IDIGNORE)
{
OnOK();
PostMessage(WM_QUIT);
return;
}
}
Path = ((CSetupApp *)AfxGetApp())->AppPath + "\\Driver";
Path += "\\MelsFx2.dll"; //請修改這里的文件名
if(!CopyFile("MelsFx2.dll",Path,FALSE)) //請修改這里的文件名
{
if(AfxMessageBox(" 復制文件到" + Path + "失敗 ",MB_ICONHAND | MB_ICONSTOP | MB_ICONERROR | MB_ABORTRETRYIGNORE) != IDIGNORE)
{
OnOK();
PostMessage(WM_QUIT);
return;
}
}
//************************************************************
Path = "\"" + Path;
Path += "\"";
CString Command = "regsvr32 " + Path;
if(WinExec(Command,SW_SHOW) <= 31)
{
AfxMessageBox(" 注冊" + Path + "失敗 ",MB_ICONHAND | MB_ICONSTOP | MB_ICONERROR | MB_ABORTRETRYIGNORE);
AfxMessageBox(" 安裝失敗 ",MB_OK);
OnOK();
PostMessage(WM_QUIT);
return;
}
//請在這里修改代碼,加入要安裝的驅動程序名
// Path = ((CSetupApp *)AfxGetApp())->AppPath + "\\Driver";
// Path += "\\FBFCC5000.DLL"; //請修改這里的文件名
/* if(!CopyFile("Siepcom.vxd","c:\\windows\\system\\Siepcom.vxd",FALSE)) //請修改這里的文件名
{
if(AfxMessageBox(" 復制文件到 c:\windows\system 失敗 ",MB_ICONHAND | MB_ICONSTOP | MB_ICONERROR | MB_ABORTRETRYIGNORE) != IDIGNORE)
{
OnOK();
PostMessage(WM_QUIT);
return;
}
}
//************************************************************
/* Path = "\"" + Path;
Path += "\"";
Command = "regsvr32 " + Path;
if(WinExec(Command,SW_SHOW) <= 31)
{
AfxMessageBox(" 注冊" + Path + "失敗 ",MB_ICONHAND | MB_ICONSTOP | MB_ICONERROR | MB_ABORTRETRYIGNORE);
AfxMessageBox(" 安裝失敗 ",MB_OK);
OnOK();
PostMessage(WM_QUIT);
return;
}
*/ Sleep(100);
OnOK();
if(strcmp(Ver, "組態王5.1") == 0)
{
if((AfxMessageBox(" 已經成功安裝了組態王5.1的驅動程序!\n 如果你使用的是祖態王6.0,請卸載組態王5.1 ",MB_OK|MB_ICONASTERISK | MB_ICONINFORMATION)==IDOK))
PostMessage(WM_QUIT);
else
return;
}
else if(strcmp(Ver, "組態王6.0") == 0)
{
if((AfxMessageBox(" 已經成功安裝了組態王6.0驅動程序! ",MB_OK|MB_ICONASTERISK | MB_ICONINFORMATION)==IDOK))
PostMessage(WM_QUIT);
else
return;
}
else return;
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -