www.pudn.com > Vax_SIP_User_Agent_SDK_V3.0[7.0.3.4].rar > MainForm.cs, change:2007-01-25,size:36138b


using System; 
using System.Collections.Generic; 
using System.ComponentModel; 
using System.Data; 
using System.Drawing; 
using System.Text; 
using System.Windows.Forms; 
using System.Runtime.InteropServices; 
 
 
 
namespace Project 
{     
    public partial class MainForm : Form 
    { 
        public MainForm() 
        { 
            InitializeComponent(); 
        } 
 
        public int SND_ASYNC = 0x0001; 
        public int SND_NODEFAULT = 0x0002; 
        public int SND_LOOP = 0x0008; 
        public int SND_FILENAME = 0x00020000; 
         
        [DllImport("winmm.dll")] 
        private static extern bool PlaySound(string lpszName, int hModule, int dwFlags);  
                
        private void ErrorMessages() 
        { 
 
            int nVaxObjectError = VaxSIPUserAgentOCX.GetVaxObjectError(); 
 
            switch (nVaxObjectError) 
            { 
                case 10: 
                    MessageBox.Show("You are not Online, please click the 'Online' button first.", "VaxVoIP SDK"); 
                    break; 
 
                case 11: 
                    MessageBox.Show("Cann't open local communication port. Another softphone (x-Ten, x-lite or skype etc) is already running. Please close it first.", "VaxVoIP SDK"); 
                    break; 
 
                case 12: 
                    MessageBox.Show("License Key is not valid.", "VaxVoIP SDK"); 
                    break; 
 
                case 13: 
                    MessageBox.Show("Fail to initialize VaxVoIP task window.", "VaxVoIP SDK"); 
                    break; 
 
                case 14: 
                    MessageBox.Show("Cann't access Input/Mic device or device is already in use.", "VaxVoIP SDK"); 
                    break; 
 
                case 15: 
                    MessageBox.Show("Cann't access Output/Speaker device or device is already in use.", "VaxVoIP SDK"); 
                    break; 
 
                case 16: 
                    MessageBox.Show("Input/Mic device is not open.", "VaxVoIP SDK"); 
                    break; 
 
                case 17: 
                    MessageBox.Show("Output/Speaker device is not open.", "VaxVoIP SDK"); 
                    break; 
 
                case 18: 
                    MessageBox.Show("Your sound device does not support mic volume.", "VaxVoIP SDK"); 
                    break; 
 
                case 19: 
                    MessageBox.Show("Your sound device does not support speaker volume.", "VaxVoIP SDK"); 
                    break; 
 
                case 20: 
                    MessageBox.Show("Recording media initialization fail.", "VaxVoIP SDK"); 
                    break; 
 
                case 21: 
                    MessageBox.Show("Cann't open the wave file.", "VaxVoIP SDK"); 
                    break; 
 
                case 22: 
                    MessageBox.Show("Provided SIP URI is not valid.", "VaxVoIP SDK"); 
                    break; 
 
                case 23: 
                    MessageBox.Show("Codec is not supported.", "VaxVoIP SDK"); 
                    break; 
 
                case 24: 
                    MessageBox.Show("Error to create SDP (Session Description Protocol) request.", "VaxVoIP SDK"); 
                    break; 
 
                case 25: 
                    MessageBox.Show("Error to create CONNECTION request. Please check the provided SIP URI is valid.", "VaxVoIP SDK"); 
                    break; 
 
                case 26: 
                    MessageBox.Show("Error to create REGISTER request. Please check the provided SIP URI is valid.", "VaxVoIP SDK"); 
                    break; 
 
                case 27: 
                    MessageBox.Show("Error to create UN-REGISTER request. Please check the provided SIP URI is valid.", "VaxVoIP SDK"); 
                    break; 
 
                case 28: 
                    MessageBox.Show("Error to create DISCONNECT request.", "VaxVoIP SDK"); 
                    break; 
 
                case 29: 
                    MessageBox.Show("Line No is not valid.", "VaxVoIP SDK"); 
                    break; 
 
                case 30: 
                    MessageBox.Show("Line is already busy.", "VaxVoIP SDK"); 
                    break; 
 
                case 31: 
                    MessageBox.Show("Line is not open.", "VaxVoIP SDK"); 
                    break; 
 
                case 32: 
                    MessageBox.Show("Invalid Call-Id.", "VaxVoIP SDK"); 
                    break; 
 
                case 33: 
                    MessageBox.Show("Provided value is not valid.", "VaxVoIP SDK"); 
                    break; 
 
                case 34: 
                    MessageBox.Show("Selected line is not in voice session.", "VaxVoIP SDK"); 
                    break; 
 
                case 35: 
                    MessageBox.Show("Fail to read wave file.", "VaxVoIP SDK"); 
                    break; 
 
                case 36: 
                    MessageBox.Show("Fail to write wave file.", "VaxVoIP SDK"); 
                    break; 
 
                case 37: 
                    MessageBox.Show("Unsupported wave file format.", "VaxVoIP SDK"); 
                    break; 
            } 
 
        } 
         
                 
        private Boolean InitVaxVoIPObject() 
        { 
            /******************************************************************** 
                    Listen Port: default SIP port 5060. 
                      SIP Proxy: SIP Proxy IP or FQDN provided by your service provider. 
                  OutboundProxy: SIP outbound/NAT proxy IP or FQDN provided by your 
                    service provider to use SIP phone behind the NAT. 
         
            *********************************************************************/ 
             
            /****** Constructing SIP From URI for IP Telephony *******/ 
            string sFromURI = EditLoginId.Text + " <sip:" + EditLoginId.Text + "@" + EditSIPProxy.Text + ">"; 
 
            if(EditDisplayName.Text != "") 
                sFromURI = EditDisplayName.Text + " <sip:" + EditLoginId.Text + "@" + EditSIPProxy.Text + ">"; 
 
            String sMyIP = VaxSIPUserAgentOCX.GetMyIP(); 
            Boolean bResult = true; 
 
            int nListenPort = 5060; 
 
            for(nListenPort = 5060; nListenPort < 7000; nListenPort++) 
            { 
                if (!VaxSIPUserAgentOCX.Initialize(false, sMyIP, nListenPort, sFromURI, EditOutBoundProxy.Text, EditSIPProxy.Text, EditLoginId.Text, EditLoginPwd.Text, true, 7)) 
                { 
                    if(11 != VaxSIPUserAgentOCX.GetVaxObjectError()) 
                    { 
                        bResult = false; 
                         
                        ErrorMessages(); 
                        break; 
                    } 
                } 
                else 
                { 
                    break; 
                } 
            } 
 
            if(nListenPort >= 7000) 
            { 
                MessageBox.Show("Cann't open SIP communication port.", "VaxVoIP SDK"); 
                bResult = false; 
            } 
 
            return bResult; 
        } 
 
        private Boolean OpenLines(int nTotalNoOfLine) 
        { 
            Boolean bResult = true; 
            int nListenPort = 7000; 
            int nErrorCount = 0; 
 
            String sMyIP = VaxSIPUserAgentOCX.GetMyIP(); 
 
            for (int nLineNo = 0; nLineNo < nTotalNoOfLine; nLineNo++) 
            { 
                if (!VaxSIPUserAgentOCX.OpenLine(nLineNo, false, sMyIP, nListenPort)) 
                { 
                    if (VaxSIPUserAgentOCX.GetVaxObjectError() != 11) 
                    { 
                        bResult = false; 
 
                        ErrorMessages(); 
                        break; 
                    } 
                    else 
                    { 
                        nErrorCount += 1; 
                        nLineNo = nLineNo - 1; 
                    } 
 
                } 
 
                nListenPort += 2; //It is importent to increament RTP Listen port by 2 
 
                if (nErrorCount >= (nTotalNoOfLine + 1000)) // If unable to open more than 1000 ports. 
                { 
                    MessageBox.Show("Unable to open RTP communication port.", "VaxVoIP SDK"); 
                    bResult = false; 
                    break; 
                } 
            } 
 
            return bResult; 
        } 
 
        private void BtnOnline_Click(object sender, EventArgs e) 
        { 
            if( BtnOnline.Text == "Offline") 
            { 
                VaxSIPUserAgentOCX.UnInitialize(); 
 
                BtnOnline.Text = "Online"; 
                 
                TimerTick.Enabled = false; 
                ProgressTimer.Enabled = false; 
 
                ComboAudioOut.Items.Clear(); 
                ComboAudioIn.Items.Clear(); 
                 
                SpkProgBar.Value = 0; 
                MicProgBar.Value = 0; 
 
                return; 
            } 
                         
            if( EditLoginId.Text == "") 
            { 
                MessageBox.Show("Please enter the SIP proxy Login Id.", "VaxVoIP SDK"); 
                return; 
            } 
 
            if( EditSIPProxy.Text == "" ) 
            { 
                MessageBox.Show("Please enter the SIP proxy address or URI.", "VaxVoIP SDK"); 
                return; 
            } 
 
            VaxSIPUserAgentOCX.SetLicenceKey("TRIAL-LICENSE-KEY"); 
                                 
            if(!InitVaxVoIPObject()) 
                return; 
             
            if(!OpenLines(7)) 
                return; 
 
            if (CheckRegisterToProxy.Checked) 
            { 
                if (!VaxSIPUserAgentOCX.RegisterToProxy(3600)) 
                { 
                    ErrorMessages(); 
                    return; 
                } 
 
                AddToStatusLog("Registering to SIP Proxy."); 
            } 
 
            if (CheckEchoCancel.Checked) 
                VaxSIPUserAgentOCX.EnableEchoNoiseCancellation(); 
            else 
                VaxSIPUserAgentOCX.DisableEchoNoiseCancellation(); 
             
            VaxSIPUserAgentOCX.DeselectAllVoiceCodec(); 
 
            if (CheckGSM610.Checked) 
                VaxSIPUserAgentOCX.SelectVoiceCodec(0); 
 
            if (CheckiLBC.Checked) 
                VaxSIPUserAgentOCX.SelectVoiceCodec(1); 
 
            if (CheckG711A.Checked) 
                VaxSIPUserAgentOCX.SelectVoiceCodec(2); 
 
            if (CheckG711U.Checked) 
                VaxSIPUserAgentOCX.SelectVoiceCodec(3); 
 
            VaxSIPUserAgentOCX.EnableKeepAlive(10); 
                         
            BtnOnline.Text = "Offline"; 
 
            UpdateSoundDevice(); 
             
            TimerTick.Enabled = true; 
            ProgressTimer.Enabled = true; 
        } 
 
        private void UpdateSoundDevice() 
        { 
            ComboAudioIn.Items.Clear(); 
            ComboAudioIn.Items.Add("Default Device"); 
 
            for(int nDeviceId = 0; nDeviceId < VaxSIPUserAgentOCX.GetAudioInDevTotal(); nDeviceId++) 
            { 
                ComboAudioIn.Items.Add(VaxSIPUserAgentOCX.GetAudioInDevName(nDeviceId)); 
            } 
 
            ComboAudioIn.SelectedIndex = 0; 
 
            ComboAudioOut.Items.Clear(); 
            ComboAudioOut.Items.Add("Default Device"); 
 
            for (int nDeviceId = 0; nDeviceId < VaxSIPUserAgentOCX.GetAudioOutDevTotal(); nDeviceId++) 
            { 
                ComboAudioOut.Items.Add(VaxSIPUserAgentOCX.GetAudioOutDevName(nDeviceId)); 
            } 
 
            ComboAudioOut.SelectedIndex = 0; 
        } 
         
        private void BtnDialPad1_Click(object sender, EventArgs e) 
        { 
            EditPhoneNo.Text += "1"; 
            VaxSIPUserAgentOCX.DigitDTMF(ListLines.SelectedIndex, "1"); 
        } 
 
        private void BtnDialPad2_Click(object sender, EventArgs e) 
        { 
            EditPhoneNo.Text += "2"; 
            VaxSIPUserAgentOCX.DigitDTMF(ListLines.SelectedIndex, "2"); 
        } 
 
        private void BtnDialPad3_Click(object sender, EventArgs e) 
        { 
            EditPhoneNo.Text += "3"; 
            VaxSIPUserAgentOCX.DigitDTMF(ListLines.SelectedIndex, "3"); 
        } 
 
        private void BtnDialPad4_Click(object sender, EventArgs e) 
        { 
            EditPhoneNo.Text += "4"; 
            VaxSIPUserAgentOCX.DigitDTMF(ListLines.SelectedIndex, "4"); 
        } 
 
        private void BtnDialPad5_Click(object sender, EventArgs e) 
        { 
            EditPhoneNo.Text += "5"; 
            VaxSIPUserAgentOCX.DigitDTMF(ListLines.SelectedIndex, "5"); 
        } 
 
        private void BtnDialPad6_Click(object sender, EventArgs e) 
        { 
            EditPhoneNo.Text += "6"; 
            VaxSIPUserAgentOCX.DigitDTMF(ListLines.SelectedIndex, "6"); 
        } 
 
        private void BtnDialPad7_Click(object sender, EventArgs e) 
        { 
            EditPhoneNo.Text += "7"; 
            VaxSIPUserAgentOCX.DigitDTMF(ListLines.SelectedIndex, "7"); 
        } 
 
        private void BtnDialPad8_Click(object sender, EventArgs e) 
        { 
            EditPhoneNo.Text += "8"; 
            VaxSIPUserAgentOCX.DigitDTMF(ListLines.SelectedIndex, "8"); 
        } 
 
        private void BtnDialPad9_Click(object sender, EventArgs e) 
        { 
            EditPhoneNo.Text += "9"; 
            VaxSIPUserAgentOCX.DigitDTMF(ListLines.SelectedIndex, "9"); 
        } 
 
        private void BtnDialPadStar_Click(object sender, EventArgs e) 
        { 
            VaxSIPUserAgentOCX.DigitDTMF(ListLines.SelectedIndex, "*"); 
        } 
 
        private void BtnDialPad0_Click(object sender, EventArgs e) 
        { 
            EditPhoneNo.Text += "0"; 
            VaxSIPUserAgentOCX.DigitDTMF(ListLines.SelectedIndex, "0"); 
        } 
 
        private void BtnDialPadNo_Click(object sender, EventArgs e) 
        { 
            VaxSIPUserAgentOCX.DigitDTMF(ListLines.SelectedIndex, "#"); 
        } 
 
        private int FindLine() 
        { 
	        int nLineNo = ListLines.SelectedIndex; 
	        if(nLineNo == -1)	return -1; 
 
            if (!VaxSIPUserAgentOCX.IsLineBusy(nLineNo)) return nLineNo; 
 
	        for(nLineNo = 0; nLineNo < 7; nLineNo++) 
	        { 
                if (!VaxSIPUserAgentOCX.IsLineBusy(nLineNo)) return nLineNo; 
	        } 
 
	        return -1; 
        } 
 
        private void BtnDial_Click(object sender, EventArgs e) 
        { 
           if( EditPhoneNo.Text == "" ) 
           { 
               MessageBox.Show("Please enter a phone number.", "VaxVoIP SDK"); 
               return; 
           }     
         
            /******************************************************* 
                Constructing SIP To URI for IP Telephony: 
                       sip:PhoneNumber@SIP Proxy 
            ********************************************************/ 
 
            String sToURI = "sip:" + EditPhoneNo.Text + "@" + EditSIPProxy.Text; 
 
            int nLineNo = FindLine(); 
            if(nLineNo == -1) 
            { 
                MessageBox.Show("No line is free", "VaxVoIP SDK"); 
                return; 
            } 
             
            if (!VaxSIPUserAgentOCX.Connect(nLineNo, sToURI, ComboAudioIn.SelectedIndex - 1, ComboAudioOut.SelectedIndex - 1)) 
            { 
                ErrorMessages(); 
            } 
            else 
            { 
                AddToStatusLog("Line-" + Convert.ToString(nLineNo + 1) + ": Dialing."); 
                ListLines.Items[nLineNo] = "Line-" + Convert.ToString(nLineNo + 1) + "  :  CONNECTING"; 
            } 
        } 
 
        private void BtnHangUp_Click(object sender, EventArgs e) 
        { 
            if (!VaxSIPUserAgentOCX.Disconnect(ListLines.SelectedIndex)) 
                ErrorMessages(); 
        } 
                              
        private void BtnAccept_Click(object sender, EventArgs e) 
        { 
            int nSelectedItemIndex = ListIncomingCall.SelectedIndex; 
            if(nSelectedItemIndex == -1) return; 
 
            int nLineNo = FindLine(); 
            if (nLineNo == -1) 
            { 
                MessageBox.Show("No line is free", "VaxVoIP SDK"); 
                return; 
            } 
             
            String sCallId = ListIncomingCallIds.Items[nSelectedItemIndex].ToString(); 
                         
            if (!VaxSIPUserAgentOCX.AcceptCall(nLineNo, sCallId, ComboAudioIn.SelectedIndex - 1, ComboAudioOut.SelectedIndex - 1)) 
            { 
                ErrorMessages(); 
                return; 
            } 
             
            PlaySound(null, 0, 0); 
 
            ListIncomingCall.Items.RemoveAt(nSelectedItemIndex); 
            ListIncomingCallIds.Items.RemoveAt(nSelectedItemIndex); 
 
            if ((ListIncomingCall.SelectedIndex == -1) && (ListIncomingCall.Items.Count > 0)) 
            { 
                ListIncomingCall.SelectedIndex = 0; 
            } 
 
            ListLines.Items[nLineNo] = "Line-" + Convert.ToString(nLineNo + 1) + "  :  CONNECTING"; 
             
        } 
 
        private void BtnReject_Click(object sender, EventArgs e) 
        { 
            int nSelectedItemIndex = ListIncomingCall.SelectedIndex; 
            if(nSelectedItemIndex == -1) 
                return; 
         
            String sCallId = ListIncomingCallIds.Items[nSelectedItemIndex].ToString(); 
 
            if(!VaxSIPUserAgentOCX.RejectCall(sCallId)) 
                ErrorMessages(); 
 
            PlaySound(null, 0, 0); 
 
            ListIncomingCall.Items.RemoveAt(nSelectedItemIndex); 
            ListIncomingCallIds.Items.RemoveAt(nSelectedItemIndex); 
 
            if ((ListIncomingCall.SelectedIndex == -1) && (ListIncomingCall.Items.Count > 0)) 
            { 
                ListIncomingCall.SelectedIndex = 0; 
            } 
        } 
 
        private void CheckPlayRingTone_CheckedChanged(object sender, EventArgs e) 
        { 
            if(CheckPlayRingTone.Checked == false) 
            { 
                PlaySound(null, 0, 0); 
            } 
        } 
 
        private void CheckkStartRecording_CheckedChanged(object sender, EventArgs e) 
        { 
           if(CheckkStartRecording.Checked == true) 
           { 
               if (!VaxSIPUserAgentOCX.StartRecording(ListLines.SelectedIndex, 2, true)) 
                   ErrorMessages(); 
           } 
           else 
           { 
               VaxSIPUserAgentOCX.StopRecording(ListLines.SelectedIndex); 
           } 
        } 
 
        private void BtnResetRecordingBuffer_Click(object sender, EventArgs e) 
        { 
            VaxSIPUserAgentOCX.ResetRecording(ListLines.SelectedIndex); 
        } 
 
        private void BtnSaveToWaveFile_Click(object sender, EventArgs e) 
        { 
            if (!VaxSIPUserAgentOCX.SaveRecordingToWaveFile(ListLines.SelectedIndex, EditSaveFileName.Text)) 
                ErrorMessages(); 
            else 
                MessageBox.Show("Saved Successfully", "VaxVoIP SDK"); 
        } 
 
        private void BtnSetPlayFile_Click(object sender, EventArgs e) 
        { 
            if(!VaxSIPUserAgentOCX.PlayWaveOpen(ListLines.SelectedIndex, EditPlayFileName.Text)) 
                ErrorMessages(); 
        } 
 
        private void BtnStartPlay_Click(object sender, EventArgs e) 
        { 
            if (!VaxSIPUserAgentOCX.PlayWaveStart(ListLines.SelectedIndex, CheckPlayListen.Checked)) 
                ErrorMessages(); 
        } 
 
        private void BtnPlayRewind_Click(object sender, EventArgs e) 
        { 
            if(!VaxSIPUserAgentOCX.PlayWaveSkipTo(ListLines.SelectedIndex, VaxSIPUserAgentOCX.PlayWavePosition(ListLines.SelectedIndex) - 2)) 
                ErrorMessages(); 
        } 
 
        private void BtnPlayForward_Click(object sender, EventArgs e) 
        { 
            if (!VaxSIPUserAgentOCX.PlayWaveSkipTo(ListLines.SelectedIndex, VaxSIPUserAgentOCX.PlayWavePosition(ListLines.SelectedIndex) + 2)) 
                ErrorMessages(); 
        } 
 
        private void BtnPlayPause_Click(object sender, EventArgs e) 
        { 
            if (!VaxSIPUserAgentOCX.PlayWavePause(ListLines.SelectedIndex)) 
                ErrorMessages(); 
        } 
 
        private void BtnPlayStop_Click(object sender, EventArgs e) 
        { 
            if (!VaxSIPUserAgentOCX.PlayWaveStop(ListLines.SelectedIndex)) 
                ErrorMessages(); 
        } 
 
        private void SliderSpkVol_Scroll(object sender, EventArgs e) 
        { 
            /* 
            SetSpkVolume method requires Volume value from 0 to 255 range     
            but the slider range is 0 to 10, so we multiply the slider value  
            to 25 to get the required value to pass to SetSpkVolume method. 
            */ 
 
            VaxSIPUserAgentOCX.SetSpkVolume(SliderSpkVol.Value * 25); 
        } 
 
        private void SliderMicVol_Scroll(object sender, EventArgs e) 
        { 
            /* 
            SetMicVolume method requires Volume value from 0 to 255 range     
            but the slider range is 0 to 10, so we multiply the slider value  
            to 25 to get the required value to pass to SetMicVolume method. 
            */ 
 
            VaxSIPUserAgentOCX.SetMicVolume(SliderMicVol.Value * 25); 
        } 
 
        private void CheckSpkMute_CheckedChanged(object sender, EventArgs e) 
        { 
            VaxSIPUserAgentOCX.MuteSpk(CheckSpkMute.Checked); 
        } 
 
        private void CheckMuteMic_CheckedChanged(object sender, EventArgs e) 
        { 
            VaxSIPUserAgentOCX.MuteMic(CheckMuteMic.Checked); 
        } 
 
        private void CheckEchoCancel_CheckedChanged(object sender, EventArgs e) 
        { 
            if (CheckEchoCancel.Checked == true) 
                VaxSIPUserAgentOCX.EnableEchoNoiseCancellation(); 
            else 
                VaxSIPUserAgentOCX.DisableEchoNoiseCancellation(); 
        } 
 
        private void CheckAGC_CheckedChanged(object sender, EventArgs e) 
        { 
            if (CheckAGC.Checked == true) 
            { 
                if (VaxSIPUserAgentOCX.EnableAGC(8000)) 
                    ErrorMessages(); 
            } 
            else 
            { 
                VaxSIPUserAgentOCX.DisableAGC(); 
            } 
        } 
 
        private void CheckMicBoost_CheckedChanged(object sender, EventArgs e) 
        { 
            if(CheckMicBoost.Checked == true) 
                VaxSIPUserAgentOCX.EnableMicBoost(); 
            else 
                VaxSIPUserAgentOCX.DisableMicBoost(); 
        } 
 
        private void CheckDisturb_CheckedChanged(object sender, EventArgs e) 
        { 
            if(CheckDisturb.Checked == true) 
                VaxSIPUserAgentOCX.EnableDonotDisturb(); 
            else 
                VaxSIPUserAgentOCX.DisableDonotDisturb(); 
        } 
 
        private void CheckGSM610_CheckedChanged(object sender, EventArgs e) 
        { 
            /****Codec No 0 represents GSM 6.10 *****/ 
 
            if (CheckGSM610.Checked == true) 
                VaxSIPUserAgentOCX.SelectVoiceCodec(0); 
            else 
                VaxSIPUserAgentOCX.DeselectVoiceCodec(0); 
        } 
 
        private void CheckiLBC_CheckedChanged(object sender, EventArgs e) 
        { 
            /****Codec No 1 represents iLBC *****/ 
 
            if (CheckiLBC.Checked == true) 
                VaxSIPUserAgentOCX.SelectVoiceCodec(1); 
            else 
                VaxSIPUserAgentOCX.DeselectVoiceCodec(1); 
             
        } 
 
        private void CheckG711A_CheckedChanged(object sender, EventArgs e) 
        { 
            /****Codec No 2 represents G711 A-LAW *****/ 
 
            if(CheckG711A.Checked == true) 
                VaxSIPUserAgentOCX.SelectVoiceCodec(2); 
            else 
                VaxSIPUserAgentOCX.DeselectVoiceCodec(2); 
        } 
 
        private void CheckG711U_CheckedChanged(object sender, EventArgs e) 
        { 
            /****Codec No 3 represents G711 U-LAW *****/ 
 
            if (CheckG711U.Checked == true) 
                VaxSIPUserAgentOCX.SelectVoiceCodec(3); 
            else 
                VaxSIPUserAgentOCX.DeselectVoiceCodec(3); 
        } 
 
        private void BtnTransferCall_Click(object sender, EventArgs e) 
        { 
            String sToURI = "sip:" + EditTransferPhoneNo.Text + "@" + EditSIPProxy.Text; 
 
            if (!VaxSIPUserAgentOCX.TransferCall(ListLines.SelectedIndex, sToURI)) 
                ErrorMessages(); 
        } 
 
        private void BtnClearLog_Click(object sender, EventArgs e) 
        { 
            ListStatusLog.Items.Clear(); 
        } 
 
        private void VaxSIPUserAgentOCX_OnCallTransferAccepted(object sender, AxVAXSIPUSERAGENTOCXLib._DVaxSIPUserAgentOCXEvents_OnCallTransferAcceptedEvent e) 
        { 
            AddToStatusLog("Line-" + Convert.ToString(e.lineNo + 1) + ": Transfer accepted."); 
        } 
 
        private void VaxSIPUserAgentOCX_OnConnecting(object sender, AxVAXSIPUSERAGENTOCXLib._DVaxSIPUserAgentOCXEvents_OnConnectingEvent e) 
        { 
            AddToStatusLog("Line-" + Convert.ToString(e.lineNo + 1) + ": Connecting."); 
        } 
 
        private void VaxSIPUserAgentOCX_OnDisconnectCall(object sender, AxVAXSIPUSERAGENTOCXLib._DVaxSIPUserAgentOCXEvents_OnDisconnectCallEvent e) 
        { 
            AddToStatusLog("Line-" + Convert.ToString(e.lineNo + 1) + ": Hung up."); 
        } 
 
        private void VaxSIPUserAgentOCX_OnFailToConnect(object sender, AxVAXSIPUSERAGENTOCXLib._DVaxSIPUserAgentOCXEvents_OnFailToConnectEvent e) 
        { 
             AddToStatusLog("Line-" + Convert.ToString(e.lineNo + 1) + ": Fail to connect."); 
        } 
 
        private void VaxSIPUserAgentOCX_OnFailToRegister(object sender, EventArgs e) 
        { 
            AddToStatusLog("Fail to register."); 
        } 
 
        private void VaxSIPUserAgentOCX_OnFailToUnRegister(object sender, EventArgs e) 
        { 
            AddToStatusLog("Fail to unregister."); 
        } 
 
        private void VaxSIPUserAgentOCX_OnGeneralFailureResponse(object sender, AxVAXSIPUSERAGENTOCXLib._DVaxSIPUserAgentOCXEvents_OnGeneralFailureResponseEvent e) 
        { 
            AddToStatusLog("Line-" + Convert.ToString(e.lineNo + 1) + " Response: " + e.reasonPhrase); 
        } 
 
        private void VaxSIPUserAgentOCX_OnIncomingCall(object sender, AxVAXSIPUSERAGENTOCXLib._DVaxSIPUserAgentOCXEvents_OnIncomingCallEvent e) 
        { 
            if(ListIncomingCallIds.FindString(e.callId) == -1) 
                ListIncomingCallIds.Items.Add(e.callId); 
 
            if(e.displayName.Length != 0) 
                ListIncomingCall.Items.Add("CLI: " + e.displayName); 
            else 
                ListIncomingCall.Items.Add("CLI: " + e.userName); 
 
            if((ListIncomingCall.SelectedIndex == -1) && (ListIncomingCall.Items.Count > 0)) 
                ListIncomingCall.SelectedIndex = 0; 
             
        } 
 
        private void VaxSIPUserAgentOCX_OnIncomingCallRingingStart(object sender, AxVAXSIPUSERAGENTOCXLib._DVaxSIPUserAgentOCXEvents_OnIncomingCallRingingStartEvent e) 
        { 
            if(CheckPlayRingTone.Checked == true) 
                PlaySound("ring.wav", 0, SND_ASYNC | SND_FILENAME | SND_LOOP | SND_NODEFAULT); 
        } 
 
        private void VaxSIPUserAgentOCX_OnIncomingCallRingingStop(object sender, AxVAXSIPUSERAGENTOCXLib._DVaxSIPUserAgentOCXEvents_OnIncomingCallRingingStopEvent e) 
        { 
            int nItemIndex = ListIncomingCallIds.Items.IndexOf(e.callId); 
            if (nItemIndex == -1) return; 
 
            ListIncomingCallIds.Items.RemoveAt(nItemIndex); 
            ListIncomingCall.Items.RemoveAt(nItemIndex); 
             
            PlaySound(null, 0, 0); 
        } 
 
        private void VaxSIPUserAgentOCX_OnPlayWaveDone(object sender, AxVAXSIPUSERAGENTOCXLib._DVaxSIPUserAgentOCXEvents_OnPlayWaveDoneEvent e) 
        { 
            AddToStatusLog("Line-" + Convert.ToString(e.lineNo + 1) + ": Play wave done."); 
        } 
 
        private void VaxSIPUserAgentOCX_OnProvisionalResponse(object sender, AxVAXSIPUSERAGENTOCXLib._DVaxSIPUserAgentOCXEvents_OnProvisionalResponseEvent e) 
        { 
            AddToStatusLog("Line-" + Convert.ToString(e.lineNo+ 1) + ": Response: " + e.reasonPhrase); 
        } 
 
        private void VaxSIPUserAgentOCX_OnRedirectionResponse(object sender, AxVAXSIPUSERAGENTOCXLib._DVaxSIPUserAgentOCXEvents_OnRedirectionResponseEvent e) 
        { 
            AddToStatusLog("Line-" + Convert.ToString(e.lineNo + 1) + ": Response: " + e.reasonPhrase); 
        } 
 
        private void VaxSIPUserAgentOCX_OnRequestFailureResponse(object sender, AxVAXSIPUSERAGENTOCXLib._DVaxSIPUserAgentOCXEvents_OnRequestFailureResponseEvent e) 
        { 
            AddToStatusLog("Line-" + Convert.ToString(e.lineNo + 1) + ": Response: " + e.reasonPhrase); 
        } 
 
        private void VaxSIPUserAgentOCX_OnServerFailureResponse(object sender, AxVAXSIPUSERAGENTOCXLib._DVaxSIPUserAgentOCXEvents_OnServerFailureResponseEvent e) 
        { 
            AddToStatusLog("Line-" + Convert.ToString(e.lineNo + 1) + ": Response: " + e.reasonPhrase); 
        } 
 
        private void VaxSIPUserAgentOCX_OnSuccessToConnect(object sender, AxVAXSIPUSERAGENTOCXLib._DVaxSIPUserAgentOCXEvents_OnSuccessToConnectEvent e) 
        { 
            if (e.lineNo != ListLines.SelectedIndex) 
            { 
                VaxSIPUserAgentOCX.HoldLine(e.lineNo); 
                ListLines.Items[e.lineNo] = "Line-" + Convert.ToString(e.lineNo + 1) + "  :  HOLD"; 
            } 
            else 
            { 
                ListLines.Items[e.lineNo] = "Line-" + Convert.ToString(e.lineNo + 1) + "  :  BUSY"; 
            } 
             
            AddToStatusLog("Line-" + Convert.ToString(e.lineNo + 1) + ": Success to connect."); 
 
            int nVol = VaxSIPUserAgentOCX.GetSpkVolume(); 
            SliderSpkVol.Value = nVol / 25; 
 
            nVol = VaxSIPUserAgentOCX.GetMicVolume(); 
            SliderMicVol.Value = nVol / 25; 
 
            CheckMicBoost.Checked = VaxSIPUserAgentOCX.IsMicBoostEnable(); 
        } 
 
        private void VaxSIPUserAgentOCX_OnSuccessToRegister(object sender, EventArgs e) 
        { 
            AddToStatusLog("Registered successfully."); 
        } 
 
        private void VaxSIPUserAgentOCX_OnSuccessToUnRegister(object sender, EventArgs e) 
        { 
            AddToStatusLog("Unregistered successfully."); 
        } 
 
        private void VaxSIPUserAgentOCX_OnTryingToRegister(object sender, EventArgs e) 
        { 
            AddToStatusLog("Trying to register."); 
        } 
 
        private void VaxSIPUserAgentOCX_OnTryingToUnRegister(object sender, EventArgs e) 
        { 
            AddToStatusLog("Trying to Unregister."); 
        } 
 
        private void UpdateListLine(int nLineNo) 
        { 
            if (CheckStartConf.Checked) 
	        { 
		        for(int nLineCount = 0; nLineCount < 7; nLineCount++) 
		        { 
			        if(VaxSIPUserAgentOCX.IsLineHold(nLineCount)) 
                        VaxSIPUserAgentOCX.UnHoldLine(nLineCount); 
		        } 
	        } 
	        else 
	        { 
		        for(int nLineCount = 0; nLineCount < 7; nLineCount++) 
		        { 
			        if(nLineCount == nLineNo) continue; 
 
                    if(VaxSIPUserAgentOCX.IsLineBusy(nLineCount) == true && VaxSIPUserAgentOCX.IsLineHold(nLineCount) == false)  
			        { 
                        VaxSIPUserAgentOCX.HoldLine(nLineCount); 
			        } 
		        } 
 
                if (VaxSIPUserAgentOCX.IsLineHold(nLineNo)) 
                    VaxSIPUserAgentOCX.UnHoldLine(nLineNo); 
	        } 
        }	 
 
        private void TimerTick_Tick(object sender, EventArgs e) 
        { 
            if (ListLines.Items.Count == 0) 
            { 
                for (int nLineNo = 0; nLineNo < 7; nLineNo++) 
                { 
                    ListLines.Items.Add("Line-" + Convert.ToString(nLineNo + 1) + "  :  FREE"); 
                } 
                ListLines.SelectedIndex = 0; 
            } 
 
            UpdateListLine(ListLines.SelectedIndex); 
 
            if (CheckkStartRecording.Checked != VaxSIPUserAgentOCX.IsRecording(ListLines.SelectedIndex)) 
            { 
                if (VaxSIPUserAgentOCX.IsRecording(ListLines.SelectedIndex)) 
                    CheckkStartRecording.Checked = true; 
                else CheckkStartRecording.Checked = false; 
            } 
 
            for (int nLineNo = 0; nLineNo < 7; nLineNo++) 
            { 
                String sItemText = ListLines.Items[nLineNo].ToString(); 
 
               if (!VaxSIPUserAgentOCX.IsLineOpen(nLineNo)) 
                { 
                    if (sItemText.IndexOf("CLOSE") == -1) 
                    { 
                        ListLines.Items[nLineNo] = "Line-" + Convert.ToString(nLineNo + 1) + "  :  CLOSE"; 
                    } 
                } 
                else if (VaxSIPUserAgentOCX.IsLineBusy(nLineNo)) 
                { 
                    if (VaxSIPUserAgentOCX.IsWaveFilePlaying(nLineNo)) 
                    { 
                        if (sItemText.IndexOf("PLAYING") == -1) 
                        { 
                            ListLines.Items[nLineNo] = "Line-" + Convert.ToString(nLineNo + 1) + "  :  PLAYING"; 
                        } 
                    } 
                    else if (VaxSIPUserAgentOCX.IsLineHold(nLineNo)) 
                    { 
                        if (sItemText.IndexOf("HOLD") == -1) 
                        { 
                            ListLines.Items[nLineNo] = "Line-" + Convert.ToString(nLineNo + 1) + "  :  HOLD"; 
                        } 
                    } 
                    else 
                    { 
                        if (sItemText.IndexOf("BUSY") == -1 && sItemText.IndexOf("CONNECTING") == -1) 
                        { 
                            ListLines.Items[nLineNo] = "Line-" + Convert.ToString(nLineNo + 1) + "  :  BUSY"; 
                        } 
                    } 
                } 
                else 
                { 
                    if (sItemText.IndexOf("FREE") == -1) 
                    { 
                        ListLines.Items[nLineNo] = "Line-" + Convert.ToString(nLineNo + 1) + "  :  FREE"; 
                    } 
                } 
            } 
        } 
 
        private void BtnHelpMore_Click(object sender, EventArgs e) 
        { 
            HelpForm HelpDlg = new HelpForm(); 
            HelpDlg.ShowDialog(); 
        } 
 
        private void VaxSIPUserAgentOCX_OnDTMFDigit(object sender, AxVAXSIPUSERAGENTOCXLib._DVaxSIPUserAgentOCXEvents_OnDTMFDigitEvent e) 
        { 
            AddToStatusLog("Line-" + Convert.ToString(e.lineNo + 1) + ": Key-pressed: " + e.digit); 
        } 
 
        private void AddToStatusLog(String sStatusLog) 
        { 
            ListStatusLog.Items.Add(sStatusLog); 
            ListStatusLog.TopIndex = ListStatusLog.Items.Count - 1; 
        } 
 
        private void ProgressTimer_Tick(object sender, EventArgs e) 
        { 
            SpkProgBar.Value = VaxSIPUserAgentOCX.GetSpkSoundLevel(); 
            MicProgBar.Value = VaxSIPUserAgentOCX.GetMicSoundLevel(); 
        } 
 
        private void CheckStartConf_CheckedChanged(object sender, EventArgs e) 
        { 
            int nBusyCount = 0; 
             
            for (int nLineCount = 0; nLineCount < 7; nLineCount++) 
            { 
                if (VaxSIPUserAgentOCX.IsLineBusy(nLineCount)) 
                    nBusyCount++; 
            } 
 
            if (nBusyCount < 2 && CheckStartConf.Checked) 
            { 
                CheckStartConf.Checked = false; 
                MessageBox.Show("Dial/receive more than one calls and then click start conference check box.", "VaxVoIP SDK"); 
            } 
        } 
    } 
}