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

📄 netprodlg.cpp

📁 通信增值服务,上网接听电话
💻 CPP
📖 第 1 页 / 共 4 页
字号:
// netproDlg.cpp : implementation file
//

#include "stdafx.h"
#include "ras.h"
#include "raserror.h"
#include "utily.h"
#include "tapiutils.h"
#include "netpro.h"
#include "netproDlg.h"
//#include "DlgProxy.h"
#include "ClientSocket.h"
#include "ObjBase.h"
#include "regkey.h"
#include "PropertyDlg.h"
#include "PhonebookListCtrl.h"
#include "PhoneBookDlg.h"
#include "callLogDlg.h"

#pragma comment(lib,"winmm.lib")//多媒体

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
#define	WM_ICON_NOTIFY			WM_USER+10
#define SOCKET_TIMEOUT          3 //3 seconds
/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About

#include "precomp.h"
#include "DialDlg.h"
//*******************
//GLOBALS
//*******************

#define MAX_SZ 200
Conf *pConf;
extern CSystemStatus SystemStatus;
const int NETPRO_TIMER_ID = 512;
const int MODEM_TIMER_ID =513;

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)
	ON_WM_CTLCOLOR()
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CNetproDlg dialog

IMPLEMENT_DYNAMIC(CNetproDlg, CDialog);

CNetproDlg::CNetproDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CNetproDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CNetproDlg)
	bListenFlg=TRUE;
	//}}AFX_DATA_INIT
	// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
//	m_pAutoProxy = NULL;

	m_bInConnectionToServer = FALSE;
    UnConnectFlg=TRUE;
    m_Option1Enabled = TRUE;
	m_CallName=_T("");
	m_origIP=_T("");
	m_origDN=_T("");
	m_cStatus =_T("");
	m_cStatus2=_T("");
    m_uTimer = 0;
	m_ModemTestTimer=0;
	m_FillDNFirst=TRUE;

	m_hEventConnectThread = NULL;
	m_hEventConnectThread = CreateEvent(NULL,FALSE,TRUE,NULL);

	m_WaveFormat.wFormatTag = WAVE_FORMAT_PCM; 
    m_WaveFormat.nChannels  = 1;     
	m_WaveFormat.nSamplesPerSec = 8000; 
    m_WaveFormat.wBitsPerSample = 8;
	m_WaveFormat.nAvgBytesPerSec= m_WaveFormat.nSamplesPerSec*(m_WaveFormat.wBitsPerSample/8);     
	m_WaveFormat.nBlockAlign  = 1;// (wBitsPerSample/8)* nChannels   
	m_WaveFormat.cbSize		  = 32;
	m_bExpanded=TRUE;
    m_strExpand="扩展>>";
	m_strContract="正常<<";
    m_pSize=new CSize;
	m_strCall="";
	m_bSCInUse = FALSE;

	m_CallTimer = 0;
	OneHourCounter = 0;

	m_pMsgWndOwner = new CMsgWndOwner;

	m_bOnLine = FALSE;

	bInCalling = FALSE;//正在呼叫吗
}

CNetproDlg::~CNetproDlg()
{

	// If there is an automation proxy for this dialog, set
	//  its back pointer to this dialog to NULL, so it knows
	//  the dialog has been deleted.
/*	if (m_pAutoProxy != NULL)
		m_pAutoProxy->m_pDialog = NULL;
  */
	delete m_pSize;
	delete m_pMsgWndOwner;
}

void CNetproDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CNetproDlg)
	DDX_Control(pDX, IDC_HYPERLINK, m_cHyperLink);
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CNetproDlg, CDialog)
	//{{AFX_MSG_MAP(CNetproDlg)
	ON_WM_PAINT()
	ON_WM_QUERYDRAGICON()
    ON_COMMAND(ID_POPUP_ANIMATE, OnAnimate)
	ON_WM_SIZE()
	ON_WM_TIMER()
	ON_WM_DESTROY()
	ON_COMMAND(ID_APP_PROPERTY, OnAppProperty)
	ON_WM_LBUTTONDOWN()
	ON_WM_CLOSE()
	ON_BN_CLICKED(IDC_BUTTON_PHONEBOOK, OnButtonPhonebook)
	ON_BN_CLICKED(IDC_BUTTON_CALLLOG, OnButtonCalllog)
	ON_BN_CLICKED(IDC_REJECT, OnReject)
	ON_BN_CLICKED(IDC_ACCEPT, OnAccept)
	//}}AFX_MSG_MAP
	ON_MESSAGE(WM_RESULT_RECEIVED,OnResultReceived)
//	ON_MESSAGE(WM_COMM_RXCHAR, OnCommunication)
//	ON_MESSAGE(WM_COMM_CTS_DETECTED, OnCTSDetected)
END_MESSAGE_MAP()

BOOL WriteINIKey(CString m_sFilename,CString  m_Section,CString m_Key,CString m_KeyValue)
{
	CString m_strConfig,m_strSection,m_strKey,m_strKeyValue,cValue;
	CString m_strFinal;
	int m_Position;
	char m_sConfig[MAX_FILESIZE];
	CFile f;
	int m_FileSize;
	f.Open(m_sFilename,CFile::modeReadWrite);
	m_FileSize=f.Read(m_sConfig,MAX_FILESIZE);
	
	m_strConfig = m_sConfig;
	m_strConfig = m_strConfig.Left(m_FileSize);
	m_strSection = m_Section;
	m_strKey = m_Key+_T("=");
	m_strKeyValue = m_KeyValue;
	if((m_Position=m_strConfig.Find(m_strSection))!=-1)
	{
			if((m_Position=m_strConfig.Find(m_Key,m_Position))!=-1)
			//Update Key Value
			{
				m_strFinal = m_strConfig.Left(m_Position+m_strKey.GetLength());
				m_strFinal+=m_strKeyValue;
				m_strFinal+=m_strConfig.Right(m_strConfig.GetLength()-m_strConfig.Find("\r\n",m_Position));
			}
			else
			//New Key
			{
				m_Position=m_strConfig.Find(m_strSection);
				m_strFinal = m_strConfig.Left(m_Position);
				m_strFinal+=_T("\r\n");
				m_strFinal+=m_strKey;
				m_strFinal+=m_strKeyValue;
				m_strFinal+=m_strConfig.Right(m_strConfig.GetLength()-m_Position);
			}
	}
	else
	//New Section
	{
				m_strFinal = m_strConfig;
				m_strFinal+=m_strSection;
				m_strFinal+=_T("\r\n");
				m_strFinal+=m_strKey;
				m_strFinal+=m_strKeyValue;
				m_strFinal+=_T("\r\n");
			
	}
	f.SeekToBegin();
	f.Write(m_strFinal.GetBuffer(1),m_strFinal.GetLength());
	m_strFinal.ReleaseBuffer();
	f.Close();
	return TRUE;
}

BOOL CNetproDlg::ReadPhonebook(CString m_sFilename,CString  m_Section)
{
	CString m_strPhonebook,m_strSection,CRLF;
	CString m_strName,m_strNum,m_strKey;
	int m_Position,m_Position2;
	char m_sPhonebook[MAX_FILESIZE];

	CRLF = _T("\r\n");
	CFile f;
	int m_FileSize;
	f.Open(m_sFilename,CFile::modeRead|CFile::modeNoTruncate|CFile::modeCreate);
	m_FileSize=f.Read(m_sPhonebook,MAX_FILESIZE);
	f.Close();
	
	m_strPhonebook = m_sPhonebook;
	m_strPhonebook = m_strPhonebook.Left(m_FileSize);
	m_strSection = m_Section;
	m_strKey = _T("=");
	if((m_Position=m_strPhonebook.Find(m_strSection))!=-1)
	{
			if( (m_Position=m_strPhonebook.Find(CRLF,m_Position))!=-1)
			{
				m_Position+=CRLF.GetLength();
				while((m_Position2=m_strPhonebook.Find(m_strKey,m_Position))!=-1)
				{
					
					m_strName = m_strPhonebook.Mid(m_Position,m_Position2-m_Position);
					m_Position = m_strPhonebook.Find(CRLF,m_Position2);
					if(m_Position==-1)
						break;
					m_Position2+=m_strKey.GetLength();
					m_strNum = 	m_strPhonebook.Mid(m_Position2,m_Position-m_Position2);
					m_Position = m_Position+CRLF.GetLength();
					if(m_strName!=_T("")&&m_strNum!=_T(""))
					{
						//Fill in Phonebook Map
						m_mapPhonebook.SetAt(m_strNum,m_strName);
					}
				}

			}
	}
	return TRUE;
}

/////////////////////////////////////////////////////////////////////////////
// CNetproDlg message handlers
CString ReadINIKey(char* m_sConfig,CString  m_Section,CString m_Key)
{
	CString m_strConfig,m_strSection,m_strKey,cValue;
	int m_Position;
	m_strConfig = m_sConfig;
	m_strSection = m_Section;
	m_strKey = m_Key+_T("=");
	if((m_Position=m_strConfig.Find(m_strSection))!=-1)
		{
			if((m_Position=m_strConfig.Find(m_Key,m_Position))!=-1)
			{
				cValue = m_strConfig.Mid(m_Position+m_strKey.GetLength(),m_strConfig.Find("\r\n",m_Position)-m_Position-m_strKey.GetLength());
				return cValue;
			}
	}
	return "";	
}

BOOL CNetproDlg::OnInitDialog()
{
 	// TODO: Add extra initialization here
	CString s;
	s.LoadString(IDS_PLS_INSTALL_NM21_LATER);
	pConf=new Conf(GetSafeHwnd());
	if (FAILED(pConf->Initialize()))
	{
		::MessageBox(NULL,s,"netpro",MB_OK);
		CDialog::OnCancel();
		return FALSE;
	}

	CDialDlg*   pDialDlg;
   	if(SystemStatus.bDisDial)
	{
	 pDialDlg= new CDialDlg;
     pDialDlg->DoModal();	
     delete pDialDlg;
	}
	
	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);
		}
		int iCount =pSysMenu->GetMenuItemCount();
		if(iCount!=-1)
			pSysMenu->EnableMenuItem(4,MF_GRAYED|MF_DISABLED|MF_BYPOSITION);

	}

	// 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
	

	/*
	CRgn MyRgn;
	MyRgn.CreateEllipticRgn(0, 0, 210, 160);
	SetWindowRgn(MyRgn, TRUE);
	*/

	m_brush.CreateSolidBrush(RGB(100,135,238)); // color white brush 
    
	// ShowWindow(SW_HIDE);
	CMyRegKey regKey;
	long lResult = regKey.Open(HKEY_LOCAL_MACHINE,_T("SOFTWARE\\FFCS\\VSL IPHONE\\Config"));
	if(lResult==ERROR_SUCCESS)
	{
		regKey.Read(_T("TELEPHONENUMBER"),m_origDN);
		m_oDN = m_origDN;
	}

	if (m_oDN == "")
	{
		OnAppProperty();
		m_FillDNFirst = FALSE;
	}
	else
	{
		m_FillDNFirst = FALSE;
	}
	BeginWaitCursor();
	char m_sConfig[MAX_FILESIZE];
	CFile f;
	int m_FileSize;
	f.Open("VSLCLIENT.INI",CFile::modeRead);
	m_FileSize=f.Read(m_sConfig,MAX_FILESIZE);
	f.Close();

    CString m_strSection;
	CString m_strKey;
	CString cValue;

	m_strSection = _T("[CONFIG]");
	m_strKey=_T("ServerAddr");
	m_ServerAddr = ReadINIKey(m_sConfig,m_strSection,m_strKey);
	m_strKey = _T("NetAddr");
	m_IPCompare = ReadINIKey(m_sConfig,m_strSection,m_strKey);
	m_strKey = _T("AdURL");
	m_strAdURL = ReadINIKey(m_sConfig,m_strSection,m_strKey);
    	
	if(!ReadPhonebook(_T("phonebook.dat"),_T("[PHONEBOOK]")))
		return 0;
	if(!ReadCallLog(_T("Call.log"),_T("[CALLLOG]")))
		return 0;
	while(m_IPCompare.Right(4)==_T(".255"))
	{
		m_IPCompare = m_IPCompare.Left(m_IPCompare.GetLength()-4);
	}
	m_IPCompare+=_T(".");

	m_cHyperLink.SetColours(RGB(0,0,200),RGB(85, 26, 139),RGB(125,125,0));
	m_cHyperLink.SetURL(_T("http://www.ffcs.net.cn"));
	m_cHyperLink.SetUnderline(FALSE);

	m_pMsgWndOwner->Create(IDD_DIALOG_MSGWND, this);
	m_pMsgWndOwner->ShowWindow(SW_SHOW);
	CRect rect;
	m_cHyperLink.GetWindowRect(rect);
	ScreenToClient(rect);
	CPoint point;
	point.x = rect.left;
	point.y = rect.top ;
	m_pMsgWndOwner->SetWindowPos(&wndNoTopMost,point.x,point.y,0,0,SWP_NOSIZE | SWP_NOZORDER|SWP_SHOWWINDOW );

//	UpdateData(FALSE);
	//VERIFY(m_cMsgwnd.SubclassDlgItem(IDC_STATIC_MSG, this));
	//m_cMsgwnd.m_PhoneNum = m_oDN;
	//m_cMsgwnd.PaintFlame();
	m_pMsgWndOwner->SetMsgWndStatus(m_oDN,4);
	if(waveInGetNumDevs()&&waveInGetNumDevs())
	{
		if(waveOutOpen(&hWaveOut,WAVE_MAPPER,&m_WaveFormat,(unsigned long)this->m_hWnd,0,CALLBACK_WINDOW)==MMSYSERR_NOERROR )
		{
			if(waveInOpen(&hWaveIn,WAVE_MAPPER,&m_WaveFormat,(unsigned long)this->m_hWnd,0,CALLBACK_WINDOW)!=MMSYSERR_NOERROR )
			{
				m_cStatus2.LoadString(IDS_SOUNDCARD_NOT_WELL_ENOUGH);// _T("您的声卡不符合要求; ");
				//return FALSE;
			}
			else
			{
				m_cStatus2 = _T("");
				waveInClose(hWaveIn);
				}
			waveOutClose(hWaveOut);
			//return FALSE;
		}
		else
		{
			m_cStatus2.LoadString(IDS_SOUNDCARD_INUSE); //_T("您的声卡被其他设备占用; ");
		}
	
	}
	else
	{
		m_cStatus2.LoadString(IDS_NO_SOUNDCARD);//_T("您的声卡未安装; ");
	}

	//m_cMsgwnd.m_cStatus2 = m_cStatus2;
	m_pMsgWndOwner->SetMsgWndStatus(m_cStatus2,2);
	//m_cMsgwnd.StartTimer();
	//m_pMainWnd->ShowWindow(SW_HIDE);
  //Test Buttons
  // Create the Lamp 256 colors button
  m_btnPhonebook256.SubclassDlgItem(IDC_BUTTON_PHONEBOOK, this);
  m_btnPhonebook256.SetIcon(IDI_PHONEBOOK256, IDI_PHONEBOOK2); 
  m_btnPhonebook256.SetAlign(1);
  m_btnPhonebook256.SetTooltipText(IDS_PHONEBOOK_TOOLTIP);
  // Don't draw border for this button
  //m_btnLamp256.DrawBorder(FALSE);

  m_btnHangup256.SubclassDlgItem(IDC_CALLHANGUP, this);
  m_btnHangup256.SetIcon(IDI_HANGUP2,IDI_HANGUP256); 
  m_btnHangup256.SetAlign(1);
  m_btnHangup256.SetTooltipText(IDS_HANGUP_TOOLTIP);
  ::EnableWindow(::GetDlgItem(m_hWnd,IDC_CALLHANGUP),FALSE);


  m_btnAccept256.SubclassDlgItem(IDC_ACCEPT, this);
  m_btnAccept256.SetIcon(IDI_ACCEPT2,IDI_ACCEPT256); 
  m_btnAccept256.SetAlign(1);
  m_btnAccept256.SetTooltipText(IDS_ACCEPT);
  ::EnableWindow(::GetDlgItem(m_hWnd,IDC_ACCEPT),FALSE);


  m_btnReject256.SubclassDlgItem(IDC_REJECT, this);
  m_btnReject256.SetIcon(IDI_REJECT2,IDI_REJECT256); 
  m_btnReject256.SetAlign(1);
  m_btnReject256.SetTooltipText(IDS_REJECT);
  ::EnableWindow(::GetDlgItem(m_hWnd,IDC_REJECT),FALSE);


  m_btnCalllog256.SubclassDlgItem(IDC_BUTTON_CALLLOG, this);
  m_btnCalllog256.SetIcon(IDI_CALLLOG256, IDI_CALLLOG2); 
  m_btnCalllog256.SetAlign(1);
  m_btnCalllog256.SetTooltipText(IDS_CALLLOG_TOOLTIP);

	s.LoadString(IDS_VSL_PHONENUM);
	if (!m_TrayIcon.Create(NULL,                            // Parent window
                           WM_ICON_NOTIFY,                  // Icon notify message to use
                           s+m_oDN,  // tooltip
                           AfxGetApp()->LoadIcon(IDI_ICON4),  // Icon to use
                           IDR_POPUP_MENU))                 // ID of tray icon
		return -1;

    m_TrayIcon.SetMenuDefaultItem(0, TRUE);

    if(!m_uTimer)
    {
        //m_uTimer = SetTimer(NETPRO_TIMER_ID,20000,NULL);
                         //   1800000,
                         //   NULL);
    }
    if(!m_ModemTestTimer)
    {
        m_ModemTestTimer = SetTimer(MODEM_TIMER_ID,2000,NULL);
                         //   1800000,
                         //   NULL);
    }
   //m_cMsgwnd.m_cDialUp ="已经拨号上网";
 	m_pMsgWndOwner->SetMsgWndStatus(IDS_BEEN_DIALUP,3);
  ModemTest();
  // OnIPCompare();
 //   SetupRegion(GetWindowDC(), IDB_MASK);
	
	s.LoadString(IDS_VSL_IP_PHONE);
	SetWindowText(s);

/*	if (m_SerialPort.InitPort(this, 1, 9600,'N',8,1)){
			m_SerialPort.StartMonitoring();
	//the next line just for test,muse delete it after test
			SendCmdToVSLC(0);
	}
*/
    EndWaitCursor();
	return TRUE;  // return TRUE  unless you set the focus to a control
}



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

// Automation servers should not exit when a user closes the UI

⌨️ 快捷键说明

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