?? dialtestdlg.cpp
字號:
// DialTestDlg.cpp : implementation file
//
#include "stdafx.h"
#include "DialTest.h"
#include "ClientSocket.h"
#include "DialTestDlg.h"
#include "MsgCtrl.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()
/////////////////////////////////////////////////////////////////////////////
// CDialTestDlg dialog
CDialTestDlg::CDialTestDlg(CWnd* pParent /*=NULL*/)
: CDialog(CDialTestDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CDialTestDlg)
// 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_hRasConn = NULL;
m_pSocket = new CClientSocket(this);
// m_pSocket = new CSocket();
// m_strRasLocalIp = "10.214.128.144";
m_nOrderStep = 0;
}
CDialTestDlg::~CDialTestDlg()
{
if (m_hRasConn)
{
RasHangUp(m_hRasConn);
m_hRasConn = NULL;
}
if (m_pSocket)
{
m_pSocket->Close();
delete m_pSocket;
m_pSocket = NULL;
}
}
void CDialTestDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CDialTestDlg)
DDX_Control(pDX, IDC_EDIT_RECEIVE, m_editReceive);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CDialTestDlg, CDialog)
//{{AFX_MSG_MAP(CDialTestDlg)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_BN_CLICKED(IDC_BUTTON_SEND_SMS, OnButtonSendSms)
ON_BN_CLICKED(IDC_BUTTON_OPEN_COMM, OnButtonOpenComm)
ON_BN_CLICKED(IDC_BUTTON_CLOSE_COMM, OnButtonCloseComm)
ON_BN_CLICKED(IDC_BUTTON_GET_IMSI, OnButtonGetImsi)
ON_BN_CLICKED(IDC_BUTTON_GET_IMEI, OnButtonGetImei)
ON_BN_CLICKED(IDC_BUTTON_GET_CARDID, OnButtonGetCardid)
ON_BN_CLICKED(IDC_BUTTON_SET_CMNET, OnButtonSetCmnet)
ON_BN_CLICKED(IDC_BUTTON_SET_CMWAP, OnButtonSetCmwap)
ON_BN_CLICKED(IDC_BUTTON_DIALUP, OnButtonDialup)
ON_BN_CLICKED(IDC_BUTTON_HANGUP, OnButtonHangup)
ON_BN_CLICKED(IDC_BUTTON_CLEAR, OnButtonClear)
ON_BN_CLICKED(IDC_BUTTON_CONNECT_TEST, OnButtonConnectTest)
ON_BN_CLICKED(IDC_BUTTON_GETURL, OnButtonGeturl)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CDialTestDlg message handlers
BOOL CDialTestDlg::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
return TRUE; // return TRUE unless you set the focus to a control
}
void CDialTestDlg::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 CDialTestDlg::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 CDialTestDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
void CDialTestDlg::OnButtonSendSms()
{
// TODO: Add your control notification handler code here
if (!m_MsgCtrl.SendMsg("Test測試", "13570128606"))
{
MessageBox("發送短信失敗!");
}
}
void CDialTestDlg::OnButtonOpenComm()
{
// TODO: Add your control notification handler code here
if (!m_MsgCtrl.OpenCom("COM5"))
{
MessageBox("打開COM5失敗!");
}
}
void CDialTestDlg::OnButtonCloseComm()
{
// TODO: Add your control notification handler code here
m_MsgCtrl.CloseCom();
}
void CDialTestDlg::OnButtonGetImsi()
{
// TODO: Add your control notification handler code here
SetDlgItemText(IDC_EDIT_IMSI, "");
CString strImsi;
if (!m_MsgCtrl.SendAndGetReturn("AT+CIMI\r", strImsi, TRUE))
{
MessageBox("取IMSI失敗!");
return;
}
SetDlgItemText(IDC_EDIT_IMSI, strImsi);
}
void CDialTestDlg::OnButtonGetImei()
{
// TODO: Add your control notification handler code here
SetDlgItemText(IDC_EDIT_IMEI, "");
CString strImei;
if (!m_MsgCtrl.SendAndGetReturn("AT+CGSN\r", strImei, TRUE))
{
MessageBox("取IMEI失敗!");
return;
}
SetDlgItemText(IDC_EDIT_IMEI, strImei);
}
void CDialTestDlg::OnButtonGetCardid()
{
// TODO: Add your control notification handler code here
SetDlgItemText(IDC_EDIT_CARDID, "");
CString strCardID;
if (!m_MsgCtrl.SendAndGetReturn("AT+CCID\r", strCardID, TRUE))
{
MessageBox("取CardID失敗!");
return;
}
int nPos = strCardID.Find(" ");
if (nPos > 0)
{
strCardID = strCardID.Mid(nPos);
}
strCardID.TrimLeft(" \"");
strCardID.TrimRight(" \"");
SetDlgItemText(IDC_EDIT_CARDID, strCardID);
}
void CDialTestDlg::OnButtonSetCmnet()
{
// TODO: Add your control notification handler code here
CString strError;
if (!m_MsgCtrl.SetGPRSNet("CMNET", strError))
{
MessageBox(strError);
}
}
void CDialTestDlg::OnButtonSetCmwap()
{
// TODO: Add your control notification handler code here
CString strError;
if (!m_MsgCtrl.SetGPRSNet("CMWAP", strError))
{
MessageBox(strError);
}
}
void WINAPI RasDialFunc(UINT unMsg, RASCONNSTATE rasconnstate, DWORD dwError)
{
char szRasString[256]; // Buffer for storing the error string
CString strMsg;
if (dwError) // Error occurred
{
RasGetErrorString((UINT)dwError, szRasString, 256);
strMsg.Format("Error: %d - %s\n",dwError, szRasString);
// AfxMessageBox(strMsg);
// SetEvent(g_TerminalEvent);
return;
}
// Map each of the states of RasDial() and display on the screen
// the next state that RasDial() is entering
switch (rasconnstate)
{
// Running States
case RASCS_OpenPort:
strMsg.Format("Opening port...\n");
break;
case RASCS_PortOpened:
strMsg.Format("Port opened.\n");
break;
case RASCS_ConnectDevice:
strMsg.Format("Connecting device...\n");
break;
case RASCS_DeviceConnected:
strMsg.Format("Device connected.\n");
break;
case RASCS_AllDevicesConnected:
strMsg.Format("All devices connected.\n");
break;
case RASCS_Authenticate:
strMsg.Format("Authenticating...\n");
break;
case RASCS_AuthNotify:
strMsg.Format("Authentication notify.\n");
break;
case RASCS_AuthRetry:
strMsg.Format("Retrying authentication...\n");
break;
case RASCS_AuthCallback:
strMsg.Format("Authentication callback...\n");
break;
case RASCS_AuthChangePassword:
strMsg.Format("Change password...\n");
break;
case RASCS_AuthProject:
strMsg.Format("Projection phase started...\n");
break;
case RASCS_AuthLinkSpeed:
strMsg.Format("Negotiating speed...\n");
break;
case RASCS_AuthAck:
strMsg.Format("Authentication acknowledge...\n");
break;
case RASCS_ReAuthenticate:
strMsg.Format("Retrying Authentication...\n");
break;
case RASCS_Authenticated:
strMsg.Format("Authentication complete.\n");
break;
case RASCS_PrepareForCallback:
strMsg.Format("Preparing for callback...\n");
break;
case RASCS_WaitForModemReset:
strMsg.Format("Waiting for modem reset...\n");
break;
case RASCS_WaitForCallback:
strMsg.Format("Waiting for callback...\n");
break;
case RASCS_Projected:
strMsg.Format("Projection completed.\n");
break;
#if (WINVER >= 0x400)
case RASCS_StartAuthentication:
strMsg.Format("Starting authentication...\n");
break;
case RASCS_CallbackComplete:
strMsg.Format("Callback complete.\n");
break;
case RASCS_LogonNetwork:
strMsg.Format("Logon to the network.\n");
break;
#endif
case RASCS_SubEntryConnected:
strMsg.Format("Subentry connected.\n");
break;
case RASCS_SubEntryDisconnected:
strMsg.Format("Subentry disconnected.\n");
break;
// The RAS Paused States will not occur because
// we did not use the RASDIALEXTENSIONS structure
// to set the RDEOPT_PausedState option flag.
// The Paused States are:
// RASCS_RetryAuthentication:
// RASCS_CallbackSetByCaller:
// RASCS_PasswordExpired:
// Terminal States
case RASCS_Connected:
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -