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

📄 netpro.cpp

📁 通信增值服务,上网接听电话
💻 CPP
字号:
// netpro.cpp : Defines the class behaviors for the application.
//

#include "stdafx.h"
#include "ras.h"
#include "raserror.h"
#include "tapiutils.h"
#include "DialDlg.h"
#include "netpro.h"
#include "netproDlg.h"
#include <initguid.h>
#include "Netpro_i.c"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
extern CSystemStatus SystemStatus;
/////////////////////////////////////////////////////////////////////////////
// CNetproApp

BEGIN_MESSAGE_MAP(CNetproApp, CWinApp)
	//{{AFX_MSG_MAP(CNetproApp)
	ON_COMMAND(ID_APP_ABOUT, OnAppAbout)
	//}}AFX_MSG_MAP
   // ON_COMMAND(ID_APP_ABOUT, OnAppAbout)
	ON_COMMAND(ID_WND_OPEN, OnWndOpen)
	ON_COMMAND(ID_DIALUPWND,OnDialUpWnd)
	ON_COMMAND(ID_HELP, CWinApp::OnHelp)
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CNetproApp construction

CNetproApp::CNetproApp()
{
	// TODO: add construction code here,
     
	// Place all significant initialization in InitInstance
}

/////////////////////////////////////////////////////////////////////////////
// The one and only CNetproApp object
HINSTANCE hRasLib;
CNetproApp theApp;
//int bForLink=0;
/////////////////////////////////////////////////////////////////////////////
// CNetproApp initialization

BOOL CNetproApp::InitInstance()
{
 CNetproDlg *dlg;
 	
 	/////////////////////////////
	CFile f;
	if(f.Open("VSLCLIENT.INI",CFile::modeRead)==0)
	{
			AfxMessageBox("读配置文件出错");
			return FALSE;
	}
	f.Close();
	int nResponse;  
    SystemStatusIni();
	if (!CheckSingleInstance(IDR_MAINFRAME))
 	  return FALSE;
	if(::FindWindow("MPWClass",NULL)!=NULL)
	{
		AfxMessageBox("NetMeeting 已经运行");
	    return FALSE;
	} 

	HINSTANCE m_hRasApi32;
	m_hRasApi32 = NULL;
	m_hRasApi32 = LoadLibrary(_T("RASAPI32.DLL"));
	if (!m_hRasApi32)
	{
		TRACE(_T("Can't load RASAPI32.DLL, GetLastError() returns: %d.\n"), GetLastError());
		AfxMessageBox("没有安装拨号网络,请正确安装后再运行本程序");
		return FALSE;
	}
	FreeLibrary(m_hRasApi32);
	m_hRasApi32 = NULL;
  
	/////////////////////////////
	if (!AfxSocketInit())
	{
		AfxMessageBox(IDP_SOCKETS_INIT_FAILED);
		return FALSE;
	}

	// Initialize OLE libraries
	if (!AfxOleInit())
	{
		AfxMessageBox(IDP_OLE_INIT_FAILED);
		return FALSE;
	}

/*	if (!InitATL())
		return FALSE;
*/
	AfxEnableControlContainer();

	// Standard initialization
	// If you are not using these features and wish to reduce the size
	//  of your final executable, you should remove from the following
	//  the specific initialization routines you do not need.

#ifdef _AFXDLL
	Enable3dControls();			// Call this when using MFC in a shared DLL
#else
	Enable3dControlsStatic();	// Call this when linking to MFC statically
#endif
/*
	// Parse the command line to see if launched as OLE server
	if (RunEmbedded() || RunAutomated())
	{
		// Register all OLE server (factories) as running.  This enables the
		//  OLE libraries to create objects from other applications.
		COleTemplateServer::RegisterAll();
	_Module.RegisterClassObjects(CLSCTX_LOCAL_SERVER, 
		REGCLS_MULTIPLEUSE);

	}
	else
	{
		// When a server application is launched stand-alone, it is a good idea
		//  to update the system registry in case it has been damaged.
		COleObjectFactory::UpdateRegistryAll();
	}
*/
	dlg = new CNetproDlg();
	m_pMainWnd = dlg;
	nResponse = dlg->DoModal();
	delete dlg;
	//m_pMainWnd->UpdateWindow();
	if (nResponse == IDOK)
	{
		// TODO: Place code here to handle when the dialog is
		//  dismissed with OK
	}
	else if (nResponse == IDCANCEL)
	{
		// TODO: Place code here to handle when the dialog is
		//  dismissed with Cancel
	}
   


	// Since the dialog has been closed, return FALSE so that we exit the
	//  application, rather than start the application's message pump.
	return FALSE;
}

void CNetproApp::SystemStatusIni()
{ 
    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("CFBL");
	SystemStatus.m_CFBL  = ReadINIKey(m_sConfig,m_strSection,m_strKey);
    m_strKey=_T("END_CFBL");
	SystemStatus.m_EndCFBL  = ReadINIKey(m_sConfig,m_strSection,m_strKey);

	m_strSection = _T("[SYSTEMSTATUS]");
	m_strKey=_T("bOnDial");
	SystemStatus.bOnDial  = atoi(ReadINIKey(m_sConfig,m_strSection,m_strKey));
	m_strKey = _T("bOffDial");
	SystemStatus.bOffDial = atoi(ReadINIKey(m_sConfig,m_strSection,m_strKey));
	m_strKey=_T("bDisDial");
	SystemStatus.bDisDial  = atoi(ReadINIKey(m_sConfig,m_strSection,m_strKey));
	m_strKey = _T("bOnJMP");
	SystemStatus.bOnJMP = atoi(ReadINIKey(m_sConfig,m_strSection,m_strKey));
    m_strKey = _T("bOffJMP");
	SystemStatus.bOffJMP = atoi(ReadINIKey(m_sConfig,m_strSection,m_strKey));
    m_strKey = _T("iSelect");
	SystemStatus.m_iSelect = atoi(ReadINIKey(m_sConfig,m_strSection,m_strKey));
    if(SystemStatus.bDisDial==0)
	{
		SystemStatus.bDialWinOnCancel=TRUE;

	}
}
/*
CNetproModule _Module;

BEGIN_OBJECT_MAP(ObjectMap)
END_OBJECT_MAP()

LONG CNetproModule::Unlock()
{
	AfxOleUnlockApp();
	return 0;
}

LONG CNetproModule::Lock()
{
	AfxOleLockApp();
	return 1;
}

*/
int CNetproApp::ExitInstance()
{
	if (hRasLib!=NULL)
		::FreeLibrary(hRasLib);
/*	if (m_bATLInited)
	{
		_Module.RevokeClassObjects();
		_Module.Term();
	}
*/
	SystemStatusSave();
    ::CoFreeUnusedLibraries ();
	return CWinApp::ExitInstance();

}
void CNetproApp::SystemStatusSave()
{
    char m_sConfig[MAX_FILESIZE];
	CFile f;
	int m_FileSize;
	CString m_strSection;
	CString m_strKey;
	CString cValue;
	CString cFileName;
    f.Open("VSLCLIENT.INI",CFile::modeRead);
	m_FileSize=f.Read(m_sConfig,MAX_FILESIZE);
	f.Close();
    cFileName=_T("VSLCLIENT.INI");
	m_strSection = _T("[SYSTEMSTATUS]");
	m_strKey=_T("bOnDial");
    cValue.Format("%d",SystemStatus.bOnDial);
	::WriteINIKey(cFileName,m_strSection,m_strKey,cValue);
	m_strKey=_T("bOffDial");
    cValue.Format("%d",SystemStatus.bOffDial);
	::WriteINIKey(cFileName,m_strSection,m_strKey,cValue);
	m_strKey=_T("bOnJMP");
    cValue.Format("%d",SystemStatus.bOnJMP);
	::WriteINIKey(cFileName,m_strSection,m_strKey,cValue);
	m_strKey=_T("bOffJMP");
    cValue.Format("%d",SystemStatus.bOffJMP);
	::WriteINIKey(cFileName,m_strSection,m_strKey,cValue);
	m_strKey=_T("bDisDial");
    cValue.Format("%d",SystemStatus.bDisDial);
	::WriteINIKey(cFileName,m_strSection,m_strKey,cValue);
	m_strKey=_T("iSelect");
    cValue.Format("%d",SystemStatus.m_iSelect);
	::WriteINIKey(cFileName,m_strSection,m_strKey,cValue);
	
}
/*
BOOL CNetproApp::InitATL()
{
	m_bATLInited = TRUE;

	_Module.Init(ObjectMap, AfxGetInstanceHandle());
	_Module.dwThreadID = GetCurrentThreadId();

	return TRUE;

}*/

void CNetproApp::OnDialUpWnd()
{
 CDialDlg*   pDialDlg;
    pDialDlg= new CDialDlg;
    pDialDlg->DoModal();	
    delete pDialDlg;
}
void CNetproApp::OnWndOpen() 
{
	m_pMainWnd->SetWindowText(_T("VSL IP PHONE"));
	m_pMainWnd->ShowWindow(SW_NORMAL);
	m_pMainWnd->Invalidate();
	m_pMainWnd->UpdateWindow();
	SetForegroundWindow(m_pMainWnd->m_hWnd);
	
}



void CNetproApp::OnAppAbout() 
{
	CAboutDlg aboutDlg;
	aboutDlg.DoModal();
	
}

BOOL bCanDialEx()
{
RASCONN ras[20];
DWORD  dSize, dNumber;
DWORD  (*lpfnRasEnumConnections)(
  LPRASCONN lprasconn,  // buffer to receive connections data
  LPDWORD lpcb,         // size in bytes of buffer
  LPDWORD lpcConnections
                      // number of connections written to buffer
);

DWORD (*lpfnRasGetConnectStatus)(
  HRASCONN hrasconn,  // handle to RAS connection of interest
  LPRASCONNSTATUS lprasconnstatus
                      // buffer to receive status data
);

DWORD dwRet; 

RASCONNSTATUS rasconnstatus;	
hRasLib = ::LoadLibrary( "RASAPI32.LIB" ); 
if(!hRasLib) return FALSE; 
	(FARPROC&)lpfnRasEnumConnections = GetProcAddress( hRasLib, "RasEnumConnections" ); 
	DWORD dwTemp=GetLastError();
	CString cTemp;
	cTemp.FormatMessage(dwTemp);
	if(!lpfnRasEnumConnections) return FALSE;
	(FARPROC&)lpfnRasGetConnectStatus =GetProcAddress( hRasLib, "RasGetConnectStatus" ); 
	if(!lpfnRasGetConnectStatus) return FALSE;
	ras[0].dwSize = sizeof( RASCONN );
	dSize = sizeof( ras );   // Get active RAS - Connection
	dwRet = (*lpfnRasEnumConnections)( ras, &dSize, &dNumber );
	if(dwRet!=0) return FALSE;
	rasconnstatus.dwSize=sizeof(rasconnstatus);
	for( DWORD dCount = 0;  dCount < dNumber;  dCount++ )
	{
      dwRet=(*lpfnRasGetConnectStatus)(ras[dCount].hrasconn,&rasconnstatus);
	  if(dwRet!=0) return FALSE;
      if(rasconnstatus.rasconnstate==RASCS_Connected) return FALSE;
	}
	return TRUE;
}

BOOL CNetproApp::bCanDial()
{
RASCONN ras[20];
DWORD  dSize, dNumber;
RASENTRYNAME rasname[20]; 
	//ras[0].dwSize = sizeof( RASCONN );
	dSize = sizeof( rasname );   // Get active RAS - Connection
	rasname[0].dwSize=sizeof(RASENTRYNAME);
	RasEnumEntries(NULL,NULL,rasname,&dSize,&dNumber);
	ras[0].dwSize = sizeof( RASCONN );
	dSize = sizeof( ras );   // Get active RAS - Connection
	return TRUE;
}
/*BOOL CNetproApp::Dialup()
{
RASDIALPARAMS rdParams;
HRASCONN hRasConn = NULL;
char  szBuf[256];
DWORD dwRet;        
    memset(&rdParams,0,sizeof(RASDIALPARAMS));
    rdParams.dwSize = sizeof(RASDIALPARAMS);
	rdParams.szEntryName[0] = '\0';
	lstrcpy( rdParams.szPhoneNumber, "163");
	rdParams.szCallbackNumber[0] = '\0';
	lstrcpy( rdParams.szUserName, "ofd@pub3.fz.fj.cn");
	lstrcpy( rdParams.szPassword, ";
	rdParams.szDomain[0] = '\0';

	dwRet = RasDial( NULL, NULL, &rdParams, 0L, NULL, &hRasConn );
    if ( dwRet != 0 )  
	{
		if ( RasGetErrorString( (UINT)dwRet, (LPSTR)szBuf, 256 ) != 0 )
		 wsprintf( (LPSTR)szBuf, "Undefined RAS Dial Error (%ld).", dwRet );
	    RasHangUp( hRasConn );
		::MessageBox( GetSafeHwnd(),(LPSTR)szBuf, "Error", MB_OK | MB_ICONSTOP );
	    return false;
    }
	dwRet = RasHangUp( hRasConn );
	if ( dwRet != 0 )
		{
			if ( RasGetErrorString( (UINT)dwRet, (LPSTR)szBuf, 256 ) != 0 )
				wsprintf( (LPSTR)szBuf, "Undefined RAS HangUp Error (%ld).", dwRet );
			MessageBox( NULL,(LPSTR)szBuf, "RasHangUp", MB_OK | MB_ICONSTOP );
			return false;
		}
    memset(&rdParams,0,sizeof(RASDIALPARAMS));
    rdParams.dwSize = sizeof(RASDIALPARAMS);
	rdParams.szEntryName[0] = '\0';
	lstrcpy( rdParams.szPhoneNumber, "163");
	rdParams.szCallbackNumber[0] = '\0';
	lstrcpy( rdParams.szUserName, "ofd@pub3.fz.fj.cn");
	lstrcpy( rdParams.szPassword, "dcom.2000");
	rdParams.szDomain[0] = '\0';

	dwRet = RasDial( NULL, NULL, &rdParams, 0L, NULL, &hRasConn );
    if ( dwRet != 0 )  
	{
		if ( RasGetErrorString( (UINT)dwRet, (LPSTR)szBuf, 256 ) != 0 )
		 wsprintf( (LPSTR)szBuf, "Undefined RAS Dial Error (%ld).", dwRet );
	    RasHangUp( hRasConn );
	    MessageBox( NULL,(LPSTR)szBuf, "Error", MB_OK | MB_ICONSTOP );
	    return false;
    }
	dwRet = RasHangUp( hRasConn );
	if ( dwRet != 0 )
		{
			if ( RasGetErrorString( (UINT)dwRet, (LPSTR)szBuf, 256 ) != 0 )
				wsprintf( (LPSTR)szBuf, "Undefined RAS HangUp Error (%ld).", dwRet );
			MessageBox( NULL,(LPSTR)szBuf, "RasHangUp", MB_OK | MB_ICONSTOP );
			return false;
		}

	return true;

}*/

⌨️ 快捷键说明

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