📄 ppcrasdlg.cpp
字号:
// PPCRASDlg.cpp : implementation file
//
#include "stdafx.h"
#include "PPCRAS.h"
#include "PPCRASDlg.h"
#include "ras.h"
#include "connmgr.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#endif
#pragma comment(lib,"cellcore.lib")
// CPPCRASDlg dialog
CPPCRASDlg::CPPCRASDlg(CWnd* pParent /*=NULL*/)
: CDialog(CPPCRASDlg::IDD, pParent)
{
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
void CPPCRASDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
}
BEGIN_MESSAGE_MAP(CPPCRASDlg, CDialog)
#if defined(_DEVICE_RESOLUTION_AWARE) && !defined(WIN32_PLATFORM_WFSP)
ON_WM_SIZE()
#endif
//}}AFX_MSG_MAP
ON_BN_CLICKED(IDC_BUTTON1, &CPPCRASDlg::OnBnClickedButton1)
ON_BN_CLICKED(IDC_BUTTON2, &CPPCRASDlg::OnBnClickedButton2)
END_MESSAGE_MAP()
// CPPCRASDlg message handlers
BOOL CPPCRASDlg::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
return TRUE; // return TRUE unless you set the focus to a control
}
#if defined(_DEVICE_RESOLUTION_AWARE) && !defined(WIN32_PLATFORM_WFSP)
void CPPCRASDlg::OnSize(UINT /*nType*/, int /*cx*/, int /*cy*/)
{
DRA::RelayoutDialog(
AfxGetInstanceHandle(),
this->m_hWnd,
DRA::GetDisplayMode() != DRA::Portrait ?
MAKEINTRESOURCE(IDD_PPCRAS_DIALOG_WIDE) :
MAKEINTRESOURCE(IDD_PPCRAS_DIALOG));
}
#endif
BOOL fConnected=FALSE;
BOOL fLoop=TRUE;
HANDLE hConnection=NULL;
bool connDial(void)
{
TCHAR tchRemoteUrl[256]=TEXT("\0");
wsprintf(tchRemoteUrl,TEXT("http://www.baidu.com"));
GUID guidNetworkObject;
DWORD dwIndex=0;
if(ConnMgrMapURL(tchRemoteUrl,&guidNetworkObject,&dwIndex)==E_FAIL)
{
OutputDebugString(TEXT("Could not map the request to a network identifier"));
return FALSE;
}
CONNMGR_CONNECTIONINFO ccInfo;
memset(&ccInfo,0,sizeof(CONNMGR_CONNECTIONINFO));
ccInfo.cbSize =sizeof(CONNMGR_CONNECTIONINFO);
ccInfo.dwParams =CONNMGR_PARAM_GUIDDESTNET;
ccInfo.dwPriority =CONNMGR_PRIORITY_USERINTERACTIVE;
ccInfo.guidDestNet =guidNetworkObject;
//建立连接
if(ConnMgrEstablishConnection(&ccInfo,&hConnection)==E_FAIL)
return FALSE;
return TRUE;
}
UINT ThreadProc1(LPVOID pParam)
{
while(fLoop)
{
DWORD dwStatus=0;
if((FAILED(ConnMgrConnectionStatus(hConnection,&dwStatus))))
{
MessageBox(0,L"FAILED",L"CAPTION",0);
fLoop=FALSE;
break;
}
if(dwStatus & CONNMGR_STATUS_CONNECTED)
{
HWND h=::GetDlgItem(AfxGetApp()->m_pMainWnd ->m_hWnd ,IDC_EDIT1);
::SetWindowText (h,L"连接上");
// fLoop=FALSE;
fConnected=TRUE;
// break;
}
else if(dwStatus & CONNMGR_STATUS_WAITINGCONNECTION)
{
HWND h=::GetDlgItem(AfxGetApp()->m_pMainWnd ->m_hWnd ,IDC_EDIT1);
::SetWindowText (h,L"正在连接");
}
else if(dwStatus & CONNMGR_STATUS_DISCONNECTED)
{
HWND h=::GetDlgItem(AfxGetApp()->m_pMainWnd ->m_hWnd ,IDC_EDIT1);
::SetWindowText (h,L"不能连接");
connDial();
ThreadProc1(NULL);
}
else if(dwStatus & CONNMGR_STATUS_UNKNOWN)
{
HWND h=::GetDlgItem(AfxGetApp()->m_pMainWnd ->m_hWnd ,IDC_EDIT1);
::SetWindowText (h,L"不知");
// fLoop=FALSE;
}
else if(dwStatus & CONNMGR_STATUS_NOPATHTODESTINATION)
{
HWND h=::GetDlgItem(AfxGetApp()->m_pMainWnd ->m_hWnd ,IDC_EDIT1);
::SetWindowText (h,L"没有路径找到");
// fLoop=FALSE;
}
else if(dwStatus & CONNMGR_STATUS_CONNECTIONFAILED)
{
HWND h=::GetDlgItem(AfxGetApp()->m_pMainWnd ->m_hWnd ,IDC_EDIT1);
::SetWindowText (h,L"连接失败");
// fLoop=FALSE;
}
else if(dwStatus & CONNMGR_STATUS_CONNECTIONCANCELED)
{
HWND h=::GetDlgItem(AfxGetApp()->m_pMainWnd ->m_hWnd ,IDC_EDIT1);
::SetWindowText (h,L"放弃连接");
// fLoop=FALSE;
}
else if(dwStatus & CONNMGR_STATUS_CONNECTIONDISABLED)
{
HWND h=::GetDlgItem(AfxGetApp()->m_pMainWnd ->m_hWnd ,IDC_EDIT1);
::SetWindowText (h,L"连接取消");
// fLoop=FALSE;
}
else if(dwStatus & CONNMGR_STATUS_WAITINGFORPATH)
{
HWND h=::GetDlgItem(AfxGetApp()->m_pMainWnd ->m_hWnd ,IDC_EDIT1);
::SetWindowText (h,L"等待目标路径");
// fLoop=FALSE;
}
else if(dwStatus & CONNMGR_STATUS_WAITINGFORPHONE)
{
HWND h=::GetDlgItem(AfxGetApp()->m_pMainWnd ->m_hWnd ,IDC_EDIT1);
::SetWindowText (h,L"在通话中");
// fLoop=FALSE;
}
else if(dwStatus & CONNMGR_STATUS_WAITINGFORRESOURCE)
{
HWND h=::GetDlgItem(AfxGetApp()->m_pMainWnd ->m_hWnd ,IDC_EDIT1);
::SetWindowText (h,L"连接资源被占用 ");
// fLoop=FALSE;
}
else if(dwStatus & CONNMGR_STATUS_WAITINGFORNETWORK)
{
HWND h=::GetDlgItem(AfxGetApp()->m_pMainWnd ->m_hWnd ,IDC_EDIT1);
::SetWindowText (h,L"找不到目标网络");
// fLoop=FALSE;
}
else
{
HWND h=::GetDlgItem(AfxGetApp()->m_pMainWnd ->m_hWnd ,IDC_EDIT1);
::SetWindowText (h,L"其它原因断开");
}
}
return 1;
}
void CPPCRASDlg::OnBnClickedButton1()
{
// TODO: Add your control notification handler code here
connDial();
AfxBeginThread(ThreadProc1,NULL);
}
void CPPCRASDlg::OnBnClickedButton2()
{
// TODO: Add your control notification handler code here
if(hConnection)
{
if(ConnMgrReleaseConnection(hConnection,FALSE)==S_OK)
{
fLoop=FALSE;
hConnection=NULL;
fConnected=FALSE;
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -