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

📄 simtooldlg.cpp

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

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

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

#include <afxpriv.h>
/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About
extern CSIMTOOLApp theApp;

static UINT auIDStatusBar[] = 
{
	//ID_INDICATOR_COM,
	ID_INDICATOR_STATUS,
	ID_INDICATOR_ONLINELED,
	ID_INDICATOR_OFFLINELED
};

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()

/////////////////////////////////////////////////////////////////////////////
// CSIMTOOLDlg dialog

CSIMTOOLDlg::CSIMTOOLDlg(CWnd* pParent /*=NULL*/)
	: CDialogResize(CSIMTOOLDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CSIMTOOLDlg)
	//}}AFX_DATA_INIT
	// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
	m_bInitialized = FALSE;
}

void CSIMTOOLDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CSIMTOOLDlg)
	DDX_Control(pDX, IDC_INFOBAR, m_InfoBar);
	DDX_Control(pDX, IDC_OUTLOOKBAR, m_OutlookBar);
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CSIMTOOLDlg, CDialogResize)
	//{{AFX_MSG_MAP(CSIMTOOLDlg)
	ON_WM_SYSCOMMAND()
	ON_WM_PAINT()
	ON_WM_QUERYDRAGICON()
	ON_WM_SIZE()
	ON_NOTIFY(NM_CLICK, IDC_OUTLOOKBAR, OnClickOutlookbar)
	ON_WM_CLOSE()
	ON_COMMAND(ID_SYSEXIT, OnSysexit)
	ON_UPDATE_COMMAND_UI(ID_VIEW_PHONEBOOK, OnUpdateViewPhonebook)
	ON_UPDATE_COMMAND_UI(ID_VIEW_DIALUP, OnUpdateViewDialup)
	ON_UPDATE_COMMAND_UI(ID_VIEW_SMS, OnUpdateViewSms)
	ON_COMMAND(ID_VIEW_PHONEBOOK, OnViewPhonebook)
	ON_COMMAND(ID_VIEW_DIALUP, OnViewDialup)
	ON_COMMAND(ID_VIEW_SMS, OnViewSms)
	ON_COMMAND(ID_ABOUTBOX, OnAboutbox)
	ON_COMMAND(ID_VIEW_WRITESMS, OnViewWritesms)
	ON_UPDATE_COMMAND_UI(ID_VIEW_WRITESMS, OnUpdateViewWritesms)
	ON_COMMAND(ID_DIALUP, OnDialup)
	ON_COMMAND(ID_HANDUP, OnHandup)
	ON_COMMAND(ID_VIEW_CONNSTAT, OnViewConnstat)
	ON_UPDATE_COMMAND_UI(ID_VIEW_CONNSTAT, OnUpdateViewConnstat)
	ON_WM_TIMER()
	ON_COMMAND(ID_SHOW, OnShow)
	ON_UPDATE_COMMAND_UI(ID_DIALUP, OnUpdateDialup)
	ON_UPDATE_COMMAND_UI(ID_HANDUP, OnUpdateHandup)
	ON_COMMAND(ID_DIALUPPHONE, OnDialupphone)
	ON_UPDATE_COMMAND_UI(ID_DIALUPPHONE, OnUpdateDialupphone)
	ON_COMMAND(ID_COMMSET, OnCommset)
	ON_COMMAND(ID_HELPCONTENT, OnHelpcontent)
	ON_COMMAND(ID_VOLUME, OnVolume)
	//}}AFX_MSG_MAP
	ON_NOTIFY_EX_RANGE(TTN_NEEDTEXTW, 0, 0xFFFF, OnToolTipText)
	ON_NOTIFY_EX_RANGE(TTN_NEEDTEXTA, 0, 0xFFFF, OnToolTipText)
END_MESSAGE_MAP()

BEGIN_DLGRESIZE_MAP(CSIMTOOLDlg)
	DLGRESIZE_CONTROL(IDC_OUTLOOKBAR, DLSZ_SIZE_Y)
	DLGRESIZE_CONTROL(IDC_DIALOG_AREA, DLSZ_SIZE_X | DLSZ_SIZE_Y)
	DLGRESIZE_CONTROL(AFX_IDW_STATUS_BAR, DLSZ_MOVE_Y | DLSZ_SIZE_X)
	DLGRESIZE_CONTROL(AFX_IDW_TOOLBAR, DLSZ_SIZE_X)
	DLGRESIZE_CONTROL(IDC_STATIC1, DLSZ_SIZE_X)
	DLGRESIZE_CONTROL(IDC_INFOBAR, DLSZ_SIZE_X)
END_DLGRESIZE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CSIMTOOLDlg message handlers

BOOL CSIMTOOLDlg::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
	CString RetInfo, sDevComm, strCurPath, strVolume;
	char cText[100], comm_name[20], pCurPath[MAX_PATH], cInfPath[MAX_PATH], cVolume[5];

	memset(cText, 0, 100);
	memset(comm_name, 0, 20);
	memset(pCurPath, 0, MAX_PATH);
	memset(cInfPath, 0, MAX_PATH);
	memset(cVolume, 0, 5);
	// setup listview ctrl, so that it looks like the outbar control
	SetupOutlookBar();

	// Add statusbar to the dialog
    CreateStatusbar();

	CRect rect;
	GetDlgItem(IDC_STATIC1)->GetWindowRect(rect);
	ScreenToClient(rect);
	rect.right+=4;
	GetDlgItem(IDC_STATIC1)->MoveWindow(rect);
	
	InitResizing(FALSE);

	int s, t, b, r, l;

	if (AfxGetApp()->GetProfileInt("Settings", "SavePosition", 1))
	{
		// only restore if there is a previously saved position
		if ( -1 != (s = AfxGetApp()->GetProfileInt("Settings", "FrameStatus",   -1)) &&
			 -1 != (t = AfxGetApp()->GetProfileInt("Settings", "FrameTop",      -1)) &&
			 -1 != (l = AfxGetApp()->GetProfileInt("Settings", "FrameLeft",     -1)) &&
			 -1 != (b = AfxGetApp()->GetProfileInt("Settings", "FrameBottom",   -1)) &&
			 -1 != (r = AfxGetApp()->GetProfileInt("Settings", "FrameRight",    -1))
		   ) 
		{
			WINDOWPLACEMENT wp;
			
			// restore the window's status
			wp.showCmd = s;

			// restore the window's width and height
			wp.rcNormalPosition.bottom = b;
			wp.rcNormalPosition.right = r;

			// the following correction is needed when the taskbar is
			// at the left or top and it is not "auto-hidden"
			RECT workArea;
			SystemParametersInfo(SPI_GETWORKAREA, 0, &workArea, 0);
			l += workArea.left;
			t += workArea.top;

			// make sure the window is not completely out of sight
			int max_x = GetSystemMetrics(SM_CXSCREEN) -
							GetSystemMetrics(SM_CXICON);
			int max_y = GetSystemMetrics(SM_CYSCREEN) -
							GetSystemMetrics(SM_CYICON);
			wp.rcNormalPosition.top = min(t, max_y);
			wp.rcNormalPosition.left = min(l, max_x);

			SetWindowPlacement(&wp);
		}
	}

	// create property pages
	//m_LogPage.Create(IDD_PROPPAGE_LOG, this);
	m_PBPage.Create(IDD_PROPPAGE_PHONEBOOK, this);
	m_SMSPage.Create(IDD_PROPPAGE_SMS, this);
	m_DialupPage.Create(IDD_PROPPAGE_DIALUP, this);
	m_SendPage.Create(IDD_PROPPAGE_WRITESMS, this);
	//m_StatPage.Create(IDD_PROPPAGE_CONNSTAT, this);

	// activate main page 
	ActivatePage(0);

	// Set dev have not GPRS init
	theApp.SetGPRSInited(FALSE);

	// and finally, let's add some tooltips
	m_ToolTipCtrl.Create(this);
	m_ToolTipCtrl.Activate(TRUE);

	m_bInitialized = TRUE;

	m_sRecv = _T("0");
    m_sSent = _T("0");
    m_sSpeed = _T("0");
	m_sLastRecv = _T("0");
    m_sLastSent = _T("0");
	
	GetModuleFileName(NULL, pCurPath, MAX_PATH);
	strCurPath = pCurPath;
	sprintf(pCurPath, "%s", strCurPath.Left(strCurPath.ReverseFind('\\')+1));
	sprintf(cInfPath, "%sADBON.inf", pCurPath);
	
	// GPRS MODEM
	theApp.SetStatusText("正在寻找GPRS无线网络设备,请稍后...");
	sDevComm = theApp.ResearchDev(9600);
	if (sDevComm.GetLength() == 0)
	{
		theApp.SetStatusText("设备未被找到或端口未被初始化,正在尝试初始化...");
		sDevComm = theApp.MultiBautResearch();
		if (sDevComm.GetLength() == 0)
		{
			theApp.mobile.CloseComm();
			theApp.SetStatusText("没有找到设备或端口波特率不匹配,请确定设备是否连接...");
			MessageBox("没有找到设备或端口波特率不匹配!", "AWS");
			return FALSE;
		}
		else
		{
			theApp.SetStatusText("端口初始化完成,正在打开端口...");
			sDevComm = theApp.ResearchDev(9600);
		}
	}
	sprintf(comm_name, "%s", sDevComm);
	if (theApp.GetDevType() == "WAVECOM")
	{
		if (!RegSoft())
		{
			theApp.mobile.CloseComm();
			CDialog::OnOK();
			return FALSE;
		}

		theApp.SetStatusText("");
		sprintf(cText, "ADBON GPRS MODEM : %s/%d", sDevComm, 9600);
		theApp.SetDevText(cText);

		theApp.SetAppComm(comm_name);
		// 耳机音量设置
		strVolume = theApp.GetVolume();
		if (strVolume.GetLength() == 0)
		{
			theApp.mobile.CLVL(100);
			Sleep(10);
			RetInfo = theApp.mobile.ReceiveInfo();
		}
		else
		{
			sprintf(cVolume, "%s", strVolume);
			theApp.mobile.CLVL(atoi(cVolume));
			Sleep(10);
			RetInfo = theApp.mobile.ReceiveInfo();
		}
		// 将波特率设置为 auto
		theApp.mobile.IPR(0);
		Sleep(10);
		RetInfo = theApp.mobile.ReceiveInfo();
		// 设置短信参数
		theApp.mobile.CNMI(2,1,0,0,0);
		Sleep(10);
		RetInfo = theApp.mobile.ReceiveInfo();
		
		theApp.mobile.CSMP(17,169,0,0);
		Sleep(10);
		RetInfo = theApp.mobile.ReceiveInfo();
		
		theApp.mobile.CMGF("0");		// 短信格式: 0: PDU; 1: TEXT
		Sleep(10);
		RetInfo = theApp.mobile.ReceiveInfo();
		
		theApp.mobile.CPMS();			// 短信存储: default: SIM
		Sleep(10);
		RetInfo = theApp.mobile.ReceiveInfo();
		
		// 电话簿参数设置
		theApp.mobile.CPBSQ();
		Sleep(10);
		RetInfo = theApp.mobile.ReceiveInfo();

		theApp.mobile.CPBS("SM");
		Sleep(10);
		RetInfo = theApp.mobile.ReceiveInfo();
				
		theApp.mobile.CloseComm();

		theApp.CreateModem(comm_name, cInfPath);
	}

	if (theApp.GetDevType() == "BENQ")
	{
		if (!RegSoft())
		{
			theApp.mobile.CloseComm();
			CDialog::OnOK();
			return FALSE;
		}

		// 显示设备状态
		theApp.SetStatusText("");
		sprintf(cText, "ADBON GPRS MODEM : %s/%d", sDevComm, 9600);
		theApp.SetDevText(cText);

		theApp.SetAppComm(comm_name);
		// 耳机音量设置
		strVolume = theApp.GetVolume();
		if (strVolume.GetLength() == 0)
		{
			theApp.mobile.CLVL(100);
			Sleep(10);
			RetInfo = theApp.mobile.ReceiveInfo();
		}
		else
		{
			sprintf(cVolume, "%s", strVolume);
			theApp.mobile.CLVL(atoi(cVolume));
			Sleep(10);
			RetInfo = theApp.mobile.ReceiveInfo();
		}
		// 设置短信参数
		theApp.mobile.CNMI(2,1,0,0,0);
		Sleep(10);
		RetInfo = theApp.mobile.ReceiveInfo();

		theApp.mobile.CPMS();			// 短信存储: default: SIM
		Sleep(10);
		RetInfo = theApp.mobile.ReceiveInfo();
		
		// 电话簿参数设置
		theApp.mobile.CPBSQ();
		Sleep(10);
		RetInfo = theApp.mobile.ReceiveInfo();

		theApp.mobile.CPBS("\"SM\"");
		Sleep(10);
		RetInfo = theApp.mobile.ReceiveInfo();

		theApp.mobile.CSCS("\"UCS2\"");
		Sleep(10);
		RetInfo = theApp.mobile.ReceiveInfo();

		// 将波特率设置为 auto
		theApp.mobile.IPR(0);
		Sleep(10);
		RetInfo = theApp.mobile.ReceiveInfo();

		theApp.mobile.SendAT();
		Sleep(10);
		RetInfo = theApp.mobile.ReceiveInfo();

		theApp.mobile.CloseComm();

		theApp.CreateModem(comm_name, cInfPath);
	}

	if (theApp.GetDevType() == "SAGEM MO1xx")
	{
		theApp.SetAppComm(comm_name);
		theApp.mobile.SetModuleType("SAGEM MO1xx");
		MessageBox("SAGEM MO1xx", "AWS");
	}

	return TRUE;  // return TRUE  unless you set the focus to a control
}

void CSIMTOOLDlg::OnSysCommand(UINT nID, LPARAM lParam)
{
	switch(nID)
	{
		case SC_MINIMIZE:
			ShowWindow(SW_HIDE);
			break;
		case 61536:
			if (MessageBox("确定要退出此软件?", "AWS",MB_YESNO|MB_ICONQUESTION) == IDNO)
			{
				return;
			}
			//m_StatPage.SetInfo(m_ConnTime, m_sSpeed, m_sSent, m_sRecv);
			theApp.HandUpConn();
			SetConnStatus(FALSE);
			//SetStatusText("网络连接已断开");
			CDialog::OnClose();
			CDialog::OnOK();
			break;
		default:
			CDialog::OnSysCommand(nID, lParam);
			break;
	}
}

// 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 CSIMTOOLDlg::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 CSIMTOOLDlg::OnQueryDragIcon()
{
	return (HCURSOR) m_hIcon;
}

void CSIMTOOLDlg::SetupOutlookBar()
{
    // create Imagelist
	m_ImageList.Create(32, 32, ILC_COLOR16|ILC_MASK,1, 4);

    HICON hIcon = ::LoadIcon (AfxGetResourceHandle(), MAKEINTRESOURCE(IDI_LOG));
    m_ImageList.Add(hIcon);
    hIcon = ::LoadIcon (AfxGetResourceHandle(), MAKEINTRESOURCE(IDI_PHONEBOOK));
    m_ImageList.Add(hIcon);
    hIcon = ::LoadIcon (AfxGetResourceHandle(), MAKEINTRESOURCE(IDI_SMS));
    m_ImageList.Add(hIcon);
	hIcon = ::LoadIcon (AfxGetResourceHandle(), MAKEINTRESOURCE(IDI_WRITESMS));
    m_ImageList.Add(hIcon);
    hIcon = ::LoadIcon (AfxGetResourceHandle(), MAKEINTRESOURCE(IDI_DIALUP));
    m_ImageList.Add(hIcon);
	hIcon = ::LoadIcon (AfxGetResourceHandle(), MAKEINTRESOURCE(IDI_CONNSTAT));
    m_ImageList.Add(hIcon);

	m_OutlookBar.SetImageList(&m_ImageList, LVSIL_NORMAL);

	CRect rc;
	m_OutlookBar.GetClientRect(rc);
	
	// set new icon spacing
	m_OutlookBar.SetIconSpacing(rc.Width(), 64);

	// change colors
	m_OutlookBar.SetTextColor(RGB(255,255,255));
	m_OutlookBar.SetTextBkColor(RGB(128,128,128));
	m_OutlookBar.SetBkColor(RGB(128,128,128));	

	// insert items
	m_OutlookBar.InsertColumn(0, "OutlookBar");

	m_OutlookBar.InsertItem(0, "电话簿", 1);
	m_OutlookBar.InsertItem(1, "读短信息", 2);
	m_OutlookBar.InsertItem(2, "写短信息", 3);
	m_OutlookBar.InsertItem(3, "拨号上网", 4);
	//m_OutlookBar.InsertItem(4, "上网统计", 5);
}

BOOL CSIMTOOLDlg::CreateStatusbar()
{
	// Create the Toolbar and attach the resource
	if(!m_wndToolBar.Create(this) || !m_wndToolBar.LoadToolBar(IDR_TOOLBAR1))
	{
		TRACE0("Failed to Create Dialog Toolbar\n");
		return FALSE;
	}

	m_wndToolBar.SetBarStyle(m_wndToolBar.GetBarStyle() | CBRS_SIZE_DYNAMIC | CBRS_TOOLTIPS | CBRS_FLYBY);
	
	// Make it flat.
	m_wndToolBar.ModifyStyle(0, m_wndToolBar.GetStyle()|TBSTYLE_FLAT);

	// Create status bar at the bottom of the dialog window
	
	if (theApp.m_wndStatusBar.Create(this))
	{
		theApp.m_wndStatusBar.SetIndicators(auIDStatusBar, sizeof(auIDStatusBar)/sizeof(UINT));
		
		theApp.m_wndStatusBar.SetPaneText(0, "", TRUE);
		theApp.m_wndStatusBar.SetPaneInfo(0, theApp.m_wndStatusBar.GetItemID(0), SBPS_STRETCH, NULL);
		theApp.m_wndStatusBar.SetPaneInfo(1, theApp.m_wndStatusBar.GetItemID(1), SBPS_NORMAL, 180);

⌨️ 快捷键说明

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