⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 statusdlg.cpp

📁 代码为windows下的无线猫的应用程序(对AT指令的操作)。
💻 CPP
字号:
// StatusDlg.cpp : implementation file
//

#include "stdafx.h"
#include "SIMTOOL.h"
#include "StatusDlg.h"
#include "SIMTOOLDlg.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CStatusDlg dialog
extern CSIMTOOLApp theApp;
DWORD WINAPI ThreadDialProc( LPVOID lpParameter);

CStatusDlg::CStatusDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CStatusDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CStatusDlg)
		// NOTE: the ClassWizard will add member initialization here
	//}}AFX_DATA_INIT
}


void CStatusDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CStatusDlg)
	DDX_Control(pDX, IDC_BTNEND, m_End);
	DDX_Control(pDX, ID_EXIT, m_Exit);
	DDX_Control(pDX, IDC_STATUS, m_Status);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CStatusDlg, CDialog)
	//{{AFX_MSG_MAP(CStatusDlg)
	ON_BN_CLICKED(ID_EXIT, OnExit)
	ON_WM_TIMER()
	ON_BN_CLICKED(IDC_BTNEND, OnBtnend)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CStatusDlg message handlers

void CStatusDlg::OnCancel() 
{
	// TODO: Add extra cleanup here
	CDialog::OnCancel();
	//DestroyWindow();
}

void CStatusDlg::CloseDlg()
{
	OnCancel();
}

BOOL CStatusDlg::OnInitDialog() 
{
	CDialog::OnInitDialog();
	
	// TODO: Add extra initialization here
	m_Exit.ShowWindow(TRUE);
	m_End.ShowWindow(FALSE);
	HANDLE hThread, hProc;

	ExitEvent=CreateEvent( NULL,    // no security
                           TRUE,    // explicit reset req
                           FALSE,   // initial event reset
                           NULL ) ; // no name
    ExitedEvent=CreateEvent( NULL,    // no security
                             TRUE,    // explicit reset req
                             FALSE,   // initial event reset
                             NULL ) ; // no name

	if ((hThread=CreateThread(NULL,0,ThreadDialProc,this,0,&ThreadId))==NULL){
		CloseHandle(ExitEvent);
		CloseHandle(ExitedEvent);
		MessageBox("创建通讯线程失败","错误信息",MB_OK);
		return FALSE;
	}

	hProc=GetCurrentProcess();
	SetPriorityClass(hProc,HIGH_PRIORITY_CLASS);
	SetThreadPriority(hThread,THREAD_PRIORITY_TIME_CRITICAL);

	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}

void CStatusDlg::SetStatus(CString strStatus)
{
	m_Status.SetWindowText(strStatus);
}

void CStatusDlg::OnExit() 
{
	// TODO: Add your control notification handler code here
	theApp.HandUpConn();
	SetEvent(ExitEvent);
    
    CloseHandle(ExitedEvent);
    CloseHandle(ExitEvent);

	OnCancel();
}

// 拨号线程
DWORD WINAPI ThreadDialProc( LPVOID lpParameter)
{
	CStatusDlg *pParentWnd;
	 
	pParentWnd = (CStatusDlg *) lpParameter;
	
	pParentWnd->ShowWindow(TRUE);
	theApp.SetUserCancel(FALSE);
	CString strEntry = "China Mobile GPRS";
	HRASCONN hrasConn;

	theApp.NewRAS();
	if(theApp.CreateDialUpEntry())
	{
		// GPRS MODEM
		
		pParentWnd->SetStatus("GPRS初始化...");
		
		if (!theApp.GPRSInit())
		{
			pParentWnd->SetStatus("GPRS初始化失败");
			theApp.DelRAS();
			return -1;
		}
				
		if(!theApp.GetRasConnection(strEntry, hrasConn))
		{
			if(!theApp.DialUpNetwork(pParentWnd))
			{
				theApp.DelRAS();
				return -1;
			}
			else
			{
				//pParentWnd->m_End.ShowWindow(TRUE);
				//pParentWnd->m_Exit.ShowWindow(FALSE);
				pParentWnd->CloseDlg();
				return 0;
			}
		}
	}

	return 0;
}

void CStatusDlg::OnTimer(UINT nIDEvent) 
{
	// TODO: Add your message handler code here and/or call default
	
	CDialog::OnTimer(nIDEvent);
}

void CStatusDlg::OnBtnend() 
{
	// TODO: Add your control notification handler code here
	SetEvent(ExitEvent);
    
    CloseHandle(ExitedEvent);
    CloseHandle(ExitEvent);
	OnCancel();
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -