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

📄 phonebookpage.cpp

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

		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,ExportPBProc,this,0,&ThreadId))==NULL) {
			CloseHandle(ExitEvent);
			CloseHandle(ExitedEvent);
			MessageBox("创建通讯线程失败","错误信息",MB_OK);
			return;
		}
		hProc=GetCurrentProcess();
		SetPriorityClass(hProc,HIGH_PRIORITY_CLASS);
		SetThreadPriority(hThread,THREAD_PRIORITY_TIME_CRITICAL);
	}

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

void CPhoneBookPage::OnBtnimport() 
{
	// TODO: Add your control notification handler code here
	char cText[100], comm[20];
	HANDLE hThread, hProc;
	CString RetInfo, sDevComm, sStatus, sAppComm;
	int itemcount;

	memset(comm, 0, 20);
	memset(cText, 0, 100);

	sAppComm = theApp.GetAppComm();
	sprintf(comm, "%s", sAppComm);
	theApp.SetStatusText("正在寻找GPRS无线网络设备,请稍后...");
	theApp.SetDevText("");
	sDevComm = theApp.OpenDev(comm, 9600);
	if (sDevComm.GetLength() == 0)
	{
		theApp.SetStatusText("设备未被找到或端口未被初始化,正在尝试初始化...");
		sDevComm = theApp.MultiBautOpenDev(comm);
		if (sDevComm.GetLength() == 0)
		{
			theApp.mobile.CloseComm();
			theApp.SetStatusText("没有找到设备或端口波特率不匹配,请确定设备是否连接...");
			MessageBox("没有找到设备或端口波特率不匹配!", "AWS");
			return;
		}
		else
		{
			theApp.SetStatusText("端口初始化完成,正在打开端口...");
			sDevComm = theApp.OpenDev(comm, 9600);
		}
	}

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

		itemcount = GetItemCount();

		if (itemcount == 0)
		{
			theApp.mobile.CloseComm();
			MessageBox("没有可以保存的电话簿数据", "AWS");
			return;
		}

		m_ProgDlg.Create(IDD_PROGDLG);

		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,ImportPBProc,this,0,&ThreadId))==NULL) {
			CloseHandle(ExitEvent);
			CloseHandle(ExitedEvent);
			MessageBox("创建通讯线程失败","错误信息",MB_OK);
			return;
		}

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

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

		itemcount = GetItemCount();

		if (itemcount == 0)
		{
			theApp.mobile.CloseComm();
			MessageBox("没有可以保存的电话簿数据", "AWS");
			return;
		}

		m_ProgDlg.Create(IDD_PROGDLG);

		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,ImportPBProc,this,0,&ThreadId))==NULL) {
			CloseHandle(ExitEvent);
			CloseHandle(ExitedEvent);
			MessageBox("创建通讯线程失败","错误信息",MB_OK);
			return;
		}

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

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

void CPhoneBookPage::ShowPhoneBookList(CString RetPhoneBook, int index)
{
	CIVStringSet m_setstrings;
	int nWord, front, back, i(0), nDstLength;
	CString tmp1, tmp2, phoneid, phname;
	char phoneindex[5], phonenum[20], name[50], usc2code[50], buf[50];
	
	memset(phoneindex,0,5);
	memset(phonenum, 0, 20);
	memset(name, 0, 50);
	memset(usc2code, 0, 50);
	memset(buf, 0, 50);
	
	if (index<10)
	{
		tmp1 = RetPhoneBook.Left(RetPhoneBook.Find("+CPBR:")+8);
		phoneid = tmp1.Right(1);
	}
	if (index>=10 && index <100)
	{
		tmp1 = RetPhoneBook.Left(RetPhoneBook.Find("+CPBR:")+9);
		phoneid = tmp1.Right(2);
	}
	if (index == 100)
	{
		tmp1 = RetPhoneBook.Left(RetPhoneBook.Find("+CPBR:")+10);
		phoneid = tmp1.Right(3);
	}

	sprintf(phoneindex, "%s", phoneid);
	m_setstrings.Add("\"");

	UINT nPos = m_setstrings.FindFirstIn(RetPhoneBook, nWord);
    if (nPos != 0xFFFFFFFF)
    {
        do
        {
			front = nPos;
			nPos = m_setstrings.FindNext(nWord);
			back = nPos;
			tmp1 = RetPhoneBook.Left(back);
			tmp2 = tmp1.Right(tmp1.GetLength() - front - 1);
			if (i == 0)
			{	
				sprintf(phonenum, "%s", tmp2);
			}
			else
			{
				if (i == 1)
				{
					sprintf(name, "%s", tmp2);
					phname = name;
				}
			}
			// 插入list
			i++;
			nPos = m_setstrings.FindNext(nWord);
        } while (nPos != 0xFFFFFFFF);
    }

	//if (phname.Left(2) == "80" && phname.Right(4) == "FFFF")
	//{
	//tmp1 = phname.Left(phname.GetLength()-4);
	//tmp2 = tmp1.Right(tmp1.GetLength()-2);
	sprintf(usc2code, "%s", name);
	nDstLength = theApp.mobile.gsmString2Bytes(usc2code, (unsigned char *)buf, strlen(usc2code)/**2*/);
	theApp.mobile.gsmDecodeUcs2((unsigned char *)buf, name, nDstLength);
	//sprintf(name, "%s", phname);
	//}
	// 转化中文
	InsertPhoneBook(8,phoneindex,name,phonenum);
}

void CPhoneBookPage::WritePhoneBook(CString index, CString num, CString name)
{
	CString RetInfo, usc2;
	char buf[100];
	unsigned char cUsc2[200];
	int head, iLen;

	memset(cUsc2, 0, 200);
	memset(buf, 0, 100);
	sprintf(buf, "%s", name);
	head = buf[0];
	/*
	if (head > 0)
	{
		theApp.mobile.CPBW(index, num, "129", name);
	}
	else
	{
	*/
	//usc2 = theApp.mobile.AsciiToUsc2(name);
	iLen = strlen(buf);
	theApp.mobile.gsmEncodeUcs2(buf, cUsc2, iLen);
	theApp.mobile.gsmBytes2String(cUsc2, buf, iLen*2);
	theApp.mobile.CPBW(index, num, "129", buf);
	//}
	Sleep(10);
	RetInfo = theApp.mobile.ReceiveInfo();
}

void CPhoneBookPage::OnRclickPhonebook(NMHDR* pNMHDR, LRESULT* pResult) 
{
	// TODO: Add your control notification handler code here
	int nIndex = m_pblist.GetNextItem(-1, LVNI_ALL | LVNI_SELECTED); 
	iCurrIndex = nIndex;
    
    *pResult = 0;
}

void CPhoneBookPage::OnContextMenu(CWnd* pWnd, CPoint point) 
{
	// TODO: Add your message handler code here
	MousePoint = point;
	if(iCurrIndex == -1)
        return;

	menu.GetSubMenu(0)->TrackPopupMenu(TPM_LEFTBUTTON, MousePoint.x, MousePoint.y, this, NULL);
}

void CPhoneBookPage::OnDialnum()
{
	// TODO: Add your command handler code here
	CString sName, sNum;
	sName = m_pblist.GetItemText(iCurrIndex, 1);
	sNum = m_pblist.GetItemText(iCurrIndex, 2);

	m_InfoDlg.InfoCreate(sName, sNum, IDD_DIALINFODLG);
}

DWORD WINAPI ExportPBProc(LPVOID lpParameter)
{
	CPhoneBookPage * pParentWnd;
	CString RetInfo;
	int i;
	
	pParentWnd=(CPhoneBookPage *) lpParameter;

	// 电话簿参数设置
	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();

	pParentWnd->m_ProgDlg.ShowWindow(TRUE);
	pParentWnd->m_ProgDlg.SetRange(0,100);
	pParentWnd->m_ProgDlg.SetStatusText("正在从SIM卡中导出电话簿...");
	for (i=0; i<100; i++)
	{
		theApp.mobile.CPBR(i+1);
		RetInfo = theApp.mobile.ReceiveInfo();
		pParentWnd->m_ProgDlg.SetPos(i);
		if (RetInfo.Find("+CPBR:") == -1)
		{
			continue;
		}
		pParentWnd->ShowPhoneBookList(RetInfo, i+1);
	}
	pParentWnd->m_ProgDlg.SetPos(0);
	pParentWnd->m_ProgDlg.SetStatusText("完成");
	pParentWnd->m_ProgDlg.SetBtnEnable(TRUE);
	theApp.mobile.CloseComm();
	pParentWnd->SaveTempFile();
	
	return 0;
}

DWORD WINAPI ImportPBProc(LPVOID lpParameter)
{
	CPhoneBookPage * pParentWnd;
	int itemcount, i;
	CString phoneindex, name, phonenum;

	pParentWnd=(CPhoneBookPage *) lpParameter;

	itemcount = pParentWnd->GetItemCount();

	pParentWnd->m_ProgDlg.ShowWindow(TRUE);
	pParentWnd->m_ProgDlg.SetRange(0,itemcount);
	pParentWnd->m_ProgDlg.SetStatusText("正在将电话簿导入SIM卡...");
	
	for (i=0;i<itemcount;i++)
	{
		phoneindex = pParentWnd->m_pblist.GetItemText(i, 0);
		name = pParentWnd->m_pblist.GetItemText(i, 1);
		phonenum = pParentWnd->m_pblist.GetItemText(i, 2);
		pParentWnd->WritePhoneBook(phoneindex, phonenum, name);
		pParentWnd->m_ProgDlg.SetPos(i+1);
	}
	pParentWnd->m_ProgDlg.SetPos(0);
	pParentWnd->m_ProgDlg.SetStatusText("完成");
	pParentWnd->m_ProgDlg.SetBtnEnable(TRUE);
	theApp.mobile.CloseComm();

	return 0;
}

void CPhoneBookPage::OnSendsmsto() 
{
	// TODO: Add your command handler code here
	CString sName, sNum;
	sName = m_pblist.GetItemText(iCurrIndex, 1);
	sNum = m_pblist.GetItemText(iCurrIndex, 2);

	m_ReplyDlg.InfoCreate(sName, sNum, IDD_REPLYSMSDLG);
}

⌨️ 快捷键说明

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