📄 mirsfdlg.cpp
字号:
// MirSFDlg.cpp : implementation file
//
#include "stdafx.h"
#include "MirSF.h"
#include "MirSFDlg.h"
#include "Ping.h"
#include "Browse.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()
/////////////////////////////////////////////////////////////////////////////
// CMirSFDlg dialog
CMirSFDlg::CMirSFDlg(CWnd* pParent /*=NULL*/)
: CDialog(CMirSFDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CMirSFDlg)
// NOTE: the ClassWizard will add member initialization here
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
m_browse = new CBrowse;
}
void CMirSFDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CMirSFDlg)
DDX_Control(pDX, IDC_UPDATE, m_update);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CMirSFDlg, CDialog)
//{{AFX_MSG_MAP(CMirSFDlg)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_BN_CLICKED(IDC_UPDATE, OnUpdate)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CMirSFDlg message handlers
BOOL CMirSFDlg::OnInitDialog()
{
CDialog::OnInitDialog();
SetIcon(m_hIcon, TRUE); // Set big icon
SetIcon(m_hIcon, FALSE); // Set small icon
// TODO: Add extra initialization here
m_browse->Create(NULL, NULL, WS_CHILD | WS_VISIBLE,
CRect(0,0,320,208), this, 10001);
m_browse->ShowScrollBar(SB_BOTH,FALSE);
m_browse->SetOwner(this);
m_browse->Navigate2("http://www.ray77.com/game/mir/update.html");
return TRUE; // return TRUE unless you set the focus to a control
}
void CMirSFDlg::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 CMirSFDlg::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 CMirSFDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
void CMirSFDlg::OnOK()
{
if (SrvStat == 0)
{
MessageBox("请先检测服务器状态!");
return;
}
if (SrvStat == -1)
{
MessageBox("服务器关闭,无法登陆!");
return;
}
if (SetConfig())
{
WinExec(_T("xjpkclient.dat"),SW_SHOWNORMAL);
}
else
{
MessageBox("启动失败!");
}
}
BOOL CMirSFDlg::SetConfig()
{
CString filename;
char path[1000];
memset((void*)path,0,sizeof(char)*1000);
if(!GetCurrentDirectory(1000,path))return FALSE;
//ftp.ini
filename=path;
filename+='\\';
filename+=MIRFTP;
if(!WritePrivateProfileString("setup","site",Srvip,filename))return FALSE;
if(!WritePrivateProfileString("Server","server1caption","碎梦之路",filename))return FALSE;
if(!WritePrivateProfileString("Server","server1name","碎梦之路",filename))return FALSE;
//mir.ini
filename.Empty();
filename=path;
filename+='\\';
filename+=MIRINI;
if(!WritePrivateProfileString("setup","FontName","宋体",filename))return FALSE;
if(!WritePrivateProfileString("setup","ServerAddr",Srvip,filename))return FALSE;
if(!WritePrivateProfileString("setup","Param1",Srvip,filename))return FALSE;
if(!WritePrivateProfileString("setup","Param2","7000",filename))return FALSE;
return TRUE;
}
BOOL CMirSFDlg::CheckSrvStart()
{
struct hostent FAR *lpHostEnt=gethostbyname("rock77.3322.org");
if(!lpHostEnt)
{
return FALSE;
}
LPSTR lpaddr = lpHostEnt->h_addr_list[0];
if(lpaddr)
{
struct in_addr inAddr;
memmove (&inAddr,lpaddr, 4);
Srvip=inet_ntoa(inAddr);
if(Srvip.IsEmpty())
return FALSE;
}
// MessageBox(Srvip);
return PingMain();
}
void CMirSFDlg::OnUpdate()
{
m_update.SetWindowText("☆ 检测中… ☆");
if (CheckSrvStart())
{
m_update.SetWindowText("☆ 服务器状态: 开启 ☆");
SrvStat = 1;
}
else
{
m_update.SetWindowText("☆ 服务器状态: 关闭 ☆");
SrvStat = -1;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -