📄 vcdemo3_1_5dlg.cpp
字号:
// VCDEMO3_1_5Dlg.cpp : implementation file
//
#include "stdafx.h"
#include "VCDEMO3_1_5.h"
#include "VCDEMO3_1_5Dlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
#include "./VCcomheader/postmsg30_i.c"
/////////////////////////////////////////////////////////////////////////////
// CVCDEMO3_1_5Dlg dialog
CVCDEMO3_1_5Dlg::CVCDEMO3_1_5Dlg(CWnd* pParent /*=NULL*/)
: CDialog(CVCDEMO3_1_5Dlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CVCDEMO3_1_5Dlg)
m_strAccount = _T("");
m_strContent = _T("");
m_strGatewayIP = _T("");
m_strMobile = _T("");
m_strNewPass = _T("");
m_strOutMsg = _T("");
m_strPassword = _T("");
m_strProxyIP = _T("");
m_strProxyPass = _T("");
m_strProxyUser = _T("");
m_strRmFee = _T("");
m_strScript = _T("");
m_strWsIP = _T("");
m_nGatewayPort = 0;
m_nProxyPort = 0;
m_nWsPort = 0;
m_nProxyType = -1;
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
void CVCDEMO3_1_5Dlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CVCDEMO3_1_5Dlg)
DDX_Text(pDX, IDC_EDT_ACCOUNT, m_strAccount);
DDX_Text(pDX, IDC_EDT_CONTENT, m_strContent);
DDX_Text(pDX, IDC_EDT_GATEWAYIP, m_strGatewayIP);
DDX_Text(pDX, IDC_EDT_MOBILE, m_strMobile);
DDX_Text(pDX, IDC_EDT_NEWPASS, m_strNewPass);
DDX_Text(pDX, IDC_EDT_OUTMSG, m_strOutMsg);
DDX_Text(pDX, IDC_EDT_PASSWORD, m_strPassword);
DDX_Text(pDX, IDC_EDT_PROXYIP, m_strProxyIP);
DDX_Text(pDX, IDC_EDT_PROXYPASS, m_strProxyPass);
DDX_Text(pDX, IDC_EDT_PROXYUSER, m_strProxyUser);
DDX_Text(pDX, IDC_EDT_RMFEE, m_strRmFee);
DDX_Text(pDX, IDC_EDT_SCRIPT, m_strScript);
DDX_Text(pDX, IDC_EDT_WSIP, m_strWsIP);
DDX_Text(pDX, IDC_EDT_GATEWAYPORT, m_nGatewayPort);
DDX_Text(pDX, IDC_EDT_PROXYPORT, m_nProxyPort);
DDX_Text(pDX, IDC_EDT_WSPORT, m_nWsPort);
DDX_Radio(pDX, IDC_RDO_DIRECT, m_nProxyType);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CVCDEMO3_1_5Dlg, CDialog)
//{{AFX_MSG_MAP(CVCDEMO3_1_5Dlg)
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_BN_CLICKED(IDC_GETSVRINFO, OnGetsvrinfo)
ON_BN_CLICKED(IDC_SETSVRINFO, OnSetsvrinfo)
ON_BN_CLICKED(IDC_GETPROXY, OnGetproxy)
ON_BN_CLICKED(IDC_SETPROXY, OnSetproxy)
ON_BN_CLICKED(IDC_MDFPASSWORD, OnMdfpassword)
ON_BN_CLICKED(IDC_GETRMFEE, OnGetrmfee)
ON_BN_CLICKED(IDC_GETCONFIG, OnGetconfig)
ON_BN_CLICKED(IDC_GETMOMSG, OnGetmomsg)
ON_BN_CLICKED(IDC_POST, OnPost)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CVCDEMO3_1_5Dlg message handlers
BOOL CVCDEMO3_1_5Dlg::OnInitDialog()
{
CDialog::OnInitDialog();
// 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
//
// 初始化组件
//
m_pIMsg = NULL;
m_pUnk = NULL;
HRESULT hr;
::CoInitialize( NULL );
hr = ::CoCreateInstance(
CLSID_msg,
NULL,
CLSCTX_INPROC_SERVER, // 以进程内组件 DLL 方式加载
IID_IUnknown, // 想取得 IUnknown 接口指针
(LPVOID *) &m_pUnk);
if(FAILED(hr)) // 组件没有注册
{
m_strOutMsg = "组件没有注册";
UpdateData(FALSE);
return TRUE;
}
hr = m_pUnk->QueryInterface( // 从 IUnknown 得到其它接口指针
IID_Imsg, // 想取得 IMsg 接口指针
(LPVOID *)&m_pIMsg);
if(FAILED(hr)) // 找不到IMsg接口
{
m_strOutMsg = "找不到IMsg接口";
UpdateData(FALSE);
return TRUE;
}
//
// 初始化对话框数据
//
long nResult;
// 获取网关参数
BSTR strAccount, strPassword, strGatewayIP, strWsIP, strScript;
hr = m_pIMsg->GetServerInfo(&strAccount,
&strPassword,
&strGatewayIP,
&m_nGatewayPort,
&strWsIP,
&m_nWsPort,
&strScript,
&nResult);
if(FAILED(hr)) // 调用GetServerInfo函数失败
{
m_strOutMsg = "调用GetServerInfo函数失败";
UpdateData(FALSE);
return TRUE;
}
if(nResult != 0) // 获取网关信息GetServerInfo失败
{
m_strOutMsg.Format("获取网关信息GetServerInfo失败: %ld", nResult);
UpdateData(FALSE);
return TRUE;
}
else
{
m_strAccount = strAccount;
m_strPassword = strPassword;
m_strGatewayIP = strGatewayIP;
m_strWsIP = strWsIP;
m_strScript = strScript;
}
// 获取代理服务器参数
BSTR strUseproxy, strProxyType, strProxyIP, strProxyUser, strProxyPass;
hr = m_pIMsg->GetProxyInfo( &strUseproxy,
&strProxyType,
&strProxyIP,
&m_nProxyPort,
&strProxyUser,
&strProxyPass,
&nResult);
if(FAILED(hr)) // 调用GetProxyInfo函数失败
{
m_strOutMsg = "调用GetProxyInfo函数失败";
UpdateData(FALSE);
return TRUE;
}
if(nResult != 0) // 获取代理服务器参数GetProxyInfo失败
{
m_strOutMsg.Format("获取代理服务器参数GetProxyInfo失败: %ld", nResult);
UpdateData(FALSE);
return TRUE;
}
if(CString(strUseproxy).CompareNoCase("off") == 0) // 没有使用代理服务器
{
m_nProxyType = 0;
m_strProxyIP = "";
m_nProxyPort = 0;
m_strProxyUser = "";
m_strProxyPass = "";
}
else // 使用代理服务器
{
if(CString(strProxyType).CompareNoCase("http") == 0) // 使用HTTP代理服务器
{
m_nProxyType = 1;
}
else if(CString(strProxyType).CompareNoCase("socks4") == 0) // 使用SOCKS4代理服务器
{
m_nProxyType = 2;
}
else if(CString(strProxyType).CompareNoCase("socks5") == 0) // 使用SOCKS5代理服务器
{
m_nProxyType = 3;
}
else
{
m_nProxyType = 0;
m_strOutMsg = "代理参数设置有误";
UpdateData(FALSE);
return TRUE;
}
m_strProxyIP = strProxyIP;
m_strProxyUser = strProxyUser;
m_strProxyPass = strProxyPass;
}
m_strOutMsg = "准备就绪......";
UpdateData(FALSE);
return TRUE; // return TRUE unless you set the focus to a control
}
// 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 CVCDEMO3_1_5Dlg::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 CVCDEMO3_1_5Dlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
void CVCDEMO3_1_5Dlg::OnCancel()
{
if(m_pUnk) m_pUnk->Release();
if(m_pIMsg) m_pIMsg->Release();
::CoUninitialize();
CDialog::OnCancel();
}
//
// 获取网关参数
//
void CVCDEMO3_1_5Dlg::OnGetsvrinfo()
{
UpdateData();
HRESULT hr;
BSTR strAccount, strPassword, strGatewayIP, strWsIP, strScript;
long nResult;
hr = m_pIMsg->GetServerInfo(&strAccount,
&strPassword,
&strGatewayIP,
&m_nGatewayPort,
&strWsIP,
&m_nWsPort,
&strScript,
&nResult);
if(FAILED(hr)) // 调用GetServerInfo函数失败
{
m_strOutMsg = "调用GetServerInfo函数失败";
UpdateData(FALSE);
return;
}
if(nResult != 0) // 获取网关信息GetServerInfo失败
{
m_strOutMsg.Format("获取网关信息GetServerInfo失败: %ld", nResult);
UpdateData(FALSE);
return;
}
else
{
m_strAccount = strAccount;
m_strPassword = strPassword;
m_strGatewayIP = strGatewayIP;
m_strWsIP = strWsIP;
m_strScript = strScript;
m_strOutMsg = "获取网关信息GetServerInfo成功";
UpdateData(FALSE);
}
}
//
// 设置网关参数
//
void CVCDEMO3_1_5Dlg::OnSetsvrinfo()
{
UpdateData();
HRESULT hr;
long nResult;
hr = m_pIMsg->SetServerInfo(m_strAccount.AllocSysString(),
m_strPassword.AllocSysString(),
m_strGatewayIP.AllocSysString(),
m_nGatewayPort,
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -