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

📄 rnaapp.c

📁 See Hanoi.cpp for the implementation of this cla
💻 C
📖 第 1 页 / 共 3 页
字号:
/******************************************************************************
Copyright (c) 1995-2000 Microsoft Corporation.  All rights reserved.

RnaApp.c : Remote networking worker program

	@doc EX_RNAAPP

	@topic     RNAApp |
		This program is used to create and maintain a RAS connection.


	NOTE: This is an internal program used by the Remote Networking application.
	Its' command line parameters and existance in Windows CE may change from release
	to release as we add more features or change internal architecture of the components.
		
	The RNAApp.exe program will attempt to create a RAS connection. This
	is a worker app used by RemNet and tends to change with every release.
	In general apps should use RasDial() themselves so they they can maintain
	their own state

	Usage:
	RNAAPP [-n -p -m -cNUM] -eENTRYNAME

	Option		Description
	-n			Disables most error message boxes, used when calling
				application will display the error values
	-p			By default it will prompt for username/password for
				dial-up entries, if this is specified it will skip the initial
				prompt
	-m			Minimize on connection.
	-cNUM		Set the context value to NUM (this should be a HEX value,
				eg. -c54AF)
	-eENTRYNAME	The name of the RASEntry to use.  If the name contains any
				embedded spaces then this should be enclosed in double quotes.

	Examples:
	rnaapp -m -eDirect
	rnaapp -e"Name with spaces"


	RNAApp will send a broadcast message to all applications when a
	connection succeeds (or fails).  This broadcast message is sent as follows:

	
	SendNotifyMessage( HWND_BROADCAST, WM_NETCONNECT, (WPARAM)TRUE,
		(LPARAM)&v_RNAAppInfo );

	The wParam of the message is a boolean that indicates either connection
	success (TRUE) or termination of the connection (FALSE).	

	The lParam of the message is a pointer to the following structure
	(defined in ras.h):
	
	typedef struct tagRNAAppInfo {
		DWORD	dwSize;					// The size of this structure
		DWORD	hWndRNAApp;				// The handle of the RNAApp window
		DWORD	Context;				// Context value specified on CmdLine
		DWORD	ErrorCode;				// Last error code
		TCHAR	RasEntryName[RAS_MaxEntryName+1];
	} RNAAPP_INFO, *PRNAAPP_INFO;

	The structure elements are defined as follows:

	dwSize		Size of the structure, to be certain of tracking version
				changes you should compare this against the
				sizeof(RNAAPP_INFO).
	hWndRNAApp	The window handle of the RNAApp program (see below).
	Context		The context specified on the command line.
	ErrorCode	The error code (only valid if wParam == FALSE). See below for
				the list of error codes.
	RasEntryName The RAS entry name specified on the command line.

	Error Codes (defined in raserror.h)
	ERROR_PORT_NOT_AVAILABLE
		Port was not available.
	ERROR_PORT_DISCONNECTED
		After sucessfully connecting the port was disconnected.
	ERROR_NO_CARRIER
		No carrier was detected by the modem.
	ERROR_NO_DIALTONE
		No dialtone was detected by the modem (not all modems support this).
	ERROR_DEVICE_NOT_READY
		The device is not ready (for PCMCIA modems the device might not be
		inserted).
	ERROR_LINE_BUSY
		The modem detected a busy signal.
	ERROR_NO_ANSWER
		No one answered the phone
	ERROR_POWER_OFF
		The serial device returned indication that power had been turned off.
	ERROR_POWER_OFF_CD
		The serial device returned indication that power had been turned off,
		and that Carrier Detect was currently asserted.  This is an indication
		that we are still in the docking station.
	ERROR_USER_DISCONNECTION
		The user has disconnected the connection (by pressing the
		disconnect/cancel button)
	ERROR_DISCONNECTION
		Disconnected for an unknow reason.
	ERROR_INVALID_PARAMETER
		Invalid or missing parameter.  The -e parameter is required.
	ERROR_STATE_MACHINES_ALREADY_STARTED
		The system cannot establish another RAS connection
	ERROR_CANNOT_FIND_PHONEBOOK_ENTRY
		Unable to find specified RAS entry.
	ERROR_EVENT_INVALID
		Internal error.
				

	Sending messages to the RNAApp.
		The calling application can send messages to RNAApp.  These should
		be sent in the form:
		
		SendMessage (hWnd, RNA_RASCMD, <CMD>, <INFO>);

		Where <CMD> is one of the following:
		RNA_ADDREF	Add a reference to the current connection. <INFO> should
					be 0.
		RNA_DELREF	Delete a reference to the current connection.  If the
					reference count is decremented to zero then the
					connection is dropped as if the user had selected
					Disconnect. <INFO> should be 0.
		RNA_GETINFO	Will send a WM_NETCONNET message to the window specified
					in the <INFO> parameter.  This allows an application to
					inquire what the entryname of this instance of RNAApp is.

		Finding instances of RNAApp.  By creating a function as follows:

		BOOL FindRNAAppWindow(HWND hWnd, LPARAM lParam)
		{
			TCHAR  	szClassName[32];

			GetClassName (hWnd, szClassName,
				sizeof(szClassName)/sizeof(TCHAR));

			if (!_tcscmp (szClassName, TEXT("Dialog")) &&
				(RNAAPP_MAGIC_NUM == GetWindowLong (hWnd, DWL_USER))) {
				*((HWND *)lParam) = hWnd;
				return FALSE;
				}
			return TRUE;
		}

		And then performing the following command:
		
		EnumWindows(FindRNAAppWindow, (LPARAM)&hOldRNAWnd);

		You can determine the window handle of the currently running instance
		of RNAApp.exe (if any).
		

******************************************************************************/


#include <windows.h>
#include <tchar.h>
#include "string.h"
#include "memory.h"
#include "commctrl.h"
#include "raserror.h"
#include "notify.h"
#include "ras.h"
#include "tapihelp.h"
#include "resource.h"
#include "windev.h"     // for IsAPIReady()
#ifdef USE_SIP
#	include <sipapi.h>
	typedef BOOL (WINAPI* LPFNSIP)(SIPINFO*);
	typedef DWORD (WINAPI* LPFNSIPSTATUS)();
#endif

// direct macro for Shell_NotifyIcon, so that we have it even if the COREDLL thunk is absent
#define Shell_NotifyIcon PRIV_IMPLICIT_DECL(BOOL, SH_SHELL, 6, (DWORD,PNOTIFYICONDATA))

#define SIP_UP      0
#define SIP_DOWN    1

// Globals

const TCHAR     szAppName[] = TEXT("rnaapp");
TCHAR       	EntryName[RAS_MaxEntryName + 1];
RASENTRY    	v_RasEntry;   // The Entry.
HWND        	v_hMainWnd;
HWND        	v_hStatusWnd;
HWND        	v_hCancelBtn;
HWND        	v_hDismissBtn;
HINSTANCE   	v_hInstance;
HRASCONN    	v_hRasConn;
RASDIALPARAMS   v_RasDialParams;
BOOL        	v_fMinOnConnect;
BOOL			v_fNoPassword;
BOOL			v_fNoMsgBox;
BOOL			v_fInErrorBox;
BOOL			v_fReturnFalse;
DWORD			v_RefCount;
DWORD			v_RetryCnt;
BOOL            v_fPassword;
HICON           v_hDirectIcon;
HICON           v_hDialupIcon;
HICON			v_hVPNIcon;
HICON			v_hNotifyIcon;
DWORD			v_dwDeviceID;
RNAAPP_INFO		v_RNAAppInfo;
#ifdef USE_SIP
LPFNSIP         v_lpfnSipGetInfo;
LPFNSIP         v_lpfnSipSetInfo;
LPFNSIPSTATUS	v_lpfnSipStatus;
HINSTANCE 		v_hSipLib;
#endif

// Locals

static	BOOL	NetDisconnect;
static	BOOL	CredentialPrompt;
static  HWND    hCredentials;

#define IDM_TASKBAR_NOTIFY  (WM_USER + 200)
#define IDM_START_RASDIAL   (WM_USER + 201)
	

// Debug Zones 

#ifdef DEBUG
DBGPARAM dpCurSettings = 
{
    TEXT("rnaapp"), 
	{
		TEXT("Unused"),TEXT("Unused"),TEXT("Unused"),TEXT("Unused"),
		TEXT("Unused"),TEXT("Unused"),TEXT("Unused"),TEXT("Unused"),
		TEXT("Unused"),TEXT("Ras"),TEXT("Tapi"),TEXT("Misc"),
		TEXT("Alloc"),TEXT("Function"),TEXT("Warning"),TEXT("Error") 
	},
    0x00000000
}; 

#define ZONE_RAS        DEBUGZONE(9)	    // 0x0200
#define ZONE_TAPI       DEBUGZONE(10)       // 0x0400
#define ZONE_MISC       DEBUGZONE(11)       // 0x0800
#define ZONE_ALLOC      DEBUGZONE(12)       // 0x1000
#define ZONE_FUNCTION   DEBUGZONE(13)       // 0x2000
#define ZONE_WARN       DEBUGZONE(14)       // 0x4000
#define ZONE_ERROR      DEBUGZONE(15)       // 0x8000

#endif  // DEBUG


// What size should we be?

#define SCREEN_WIDTH    240
#define SCREEN_HEIGTH   80


void CALLBACK 
lineCallbackFunc(DWORD dwDevice, DWORD dwMsg, DWORD dwCallbackInstance, 
				 DWORD dwParam1, DWORD dwParam2, DWORD dwParam3)
{
   return;
}
void
ShowError (DWORD Message, DWORD Title)
{
    TCHAR           szTemp[218];
    TCHAR           szTemp2[128];
	
	if( v_fNoMsgBox ) {
		return;
	}
	LoadString (v_hInstance, Message, szTemp, sizeof(szTemp)/sizeof(TCHAR));
	LoadString (v_hInstance, Title, szTemp2, sizeof(szTemp2)/sizeof(TCHAR));
	MessageBox( v_hMainWnd, szTemp, szTemp2, MB_SETFOREGROUND | MB_APPLMODAL | MB_OK |
				MB_ICONEXCLAMATION);
}
void
SetTapiDisplayStuff(HWND hDlg)
{
    TCHAR	szPhone[256];
    LPTSTR  pLocName;

	szPhone[0] = TEXT('\0');

	RasGetDispPhoneNum (NULL, EntryName, szPhone, sizeof(szPhone));
	SetWindowText(GetDlgItem(hDlg, IDC_PHONE), szPhone);
        
    if (pLocName = TapiGetDefaultLocationName()) {
        SetWindowText(GetDlgItem(hDlg, IDC_DIALFROM), pLocName);
        LocalFree(pLocName);
    }    
    return;
}

LRESULT CALLBACK
DlgProcCredentials( HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam )
{
    BOOL RemovePassword;
    static BOOL fReEnable = FALSE;

    switch( message ) {
    case WM_INITDIALOG:
		// Since main window is hidden, I need to bring myself to the
		// foreground
		//
		SetForegroundWindow ( hDlg );
		if (!_tcscmp (v_RasEntry.szDeviceType, RASDT_Modem)) {
            SendMessage(GetDlgItem(hDlg, IDC_STATUSICON), STM_SETIMAGE,
                        IMAGE_ICON, (LPARAM) v_hDialupIcon);
		} else if (!_tcscmp (v_RasEntry.szDeviceType, RASDT_Direct)) {
            SendMessage(GetDlgItem(hDlg, IDC_STATUSICON), STM_SETIMAGE,
                        IMAGE_ICON, (LPARAM) v_hDirectIcon);
		} else if (!_tcscmp (v_RasEntry.szDeviceType, RASDT_Vpn)) {
            SendMessage(GetDlgItem(hDlg, IDC_STATUSICON), STM_SETIMAGE,
                        IMAGE_ICON, (LPARAM) v_hVPNIcon);
		} else {
			RETAILMSG (1, (TEXT("Error, unhandled Device Type\r\n")));
			ASSERT (0);
		}


		hCredentials = hDlg;				// save handle for cancel

        SetWindowText(GetDlgItem(hDlg, IDC_ENTRYNAME), EntryName);

        SetTapiDisplayStuff(hDlg);
        
        SetDlgItemText( hDlg, IDC_USERNAME, v_RasDialParams.szUserName );
        SetDlgItemText( hDlg, IDC_PASSWORD, v_RasDialParams.szPassword );
        SetDlgItemText( hDlg, IDC_DOMAIN, v_RasDialParams.szDomain );

        if (v_fPassword) {
            // A password has been saved so check the box
            SendMessage(GetDlgItem(hDlg, IDC_SAVEPASSWORD), BM_SETCHECK,1,0);
        }
		
        if (v_RasDialParams.szUserName[0] == TEXT('\0')) {
            SetFocus(GetDlgItem(hDlg, IDC_USERNAME));
		} else {
            SetFocus(GetDlgItem(hDlg, IDC_PASSWORD));
		}
        return FALSE;

    case WM_COMMAND:
        
        switch( LOWORD( wParam ) ) {
        case IDCANCEL: 				// Ignore values

            EndDialog( hDlg, FALSE );
            break;

        case IDCONNECT: 					// Get the dialog values

            GetDlgItemText( hDlg, IDC_USERNAME,
							v_RasDialParams.szUserName, UNLEN + 1);

            GetDlgItemText( hDlg, IDC_PASSWORD,
							v_RasDialParams.szPassword, PWLEN + 1);

            GetDlgItemText( hDlg, IDC_DOMAIN,
							v_RasDialParams.szDomain, DNLEN + 1);

            if (SendMessage(GetDlgItem(hDlg, IDC_SAVEPASSWORD),
							BM_GETCHECK, 0, 0)) {
                RemovePassword = FALSE;
            } else {
                RemovePassword = TRUE;
            }
            RasSetEntryDialParams( NULL, &v_RasDialParams, RemovePassword );
            EndDialog( hDlg, TRUE );
            break;

        case IDDIALPROPERTIES:
            lineTranslateDialog(v_hLineApp, v_dwDeviceID, v_dwVersion,
								hDlg, NULL);
            SetTapiDisplayStuff(hDlg);
            break;
            
#ifdef USE_SIP
        case IDC_PASSWORD:
            if (v_lpfnSipGetInfo && v_lpfnSipSetInfo &&
                ((HIWORD(wParam) == EN_SETFOCUS) || 
                ((HIWORD(wParam) == EN_KILLFOCUS) &&
                  fReEnable)))
            {
                SIPINFO si;

                memset(&si, 0, sizeof(SIPINFO));
                si.cbSize = sizeof(SIPINFO);
                if ((*v_lpfnSipGetInfo)(&si))
                {
                    // Toggle password completion, but keep track of 
                    // whether or not this flag was set a priori when setting focus
                    if (HIWORD(wParam) == EN_SETFOCUS)
                    {
                        fReEnable = !(si.fdwFlags & SIPF_DISABLECOMPLETION);
                        si.fdwFlags |= SIPF_DISABLECOMPLETION;
                    }
                    else
                    {
                        si.fdwFlags &= ~SIPF_DISABLECOMPLETION;
                    }
		            (*v_lpfnSipSetInfo)(&si);
                }
            }
            break;
#endif

        default:

            break;
        }

    case WM_DESTROY:

        return( FALSE );

    default:
		
        return( FALSE );
        break;
    }
}

VOID
SetStatusWnd (DWORD StringID)

⌨️ 快捷键说明

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