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

📄 frmchat.cs

📁 实现微软OFFICEACCESE数据库自动备份功能
💻 CS
字号:
using System;
using System.Collections.Generic;
using System.Configuration;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Diagnostics;
using System.IO;
using gowk.multimedia;

namespace avt
{
    public partial class frmChat : Form
    {
        AV myav;
        Mixer mixer;
        Mixer.MixerControlDetail indtl, outdtl;
         
        bool StreamStarted;
        bool StreamError;
        bool StreamEnded;
        string picSave;
         

        public frmChat()
        {
            InitializeComponent();
        }

        private void frmChat_Load(object sender, EventArgs e)
        {

            try
            {

                FileInfo me = new FileInfo(Application.ExecutablePath);
                Debug.Print(me.DirectoryName);
                picSave = me.DirectoryName+"\\Photos";
                picSaveDlg.RootFolder = Environment.SpecialFolder.Desktop;
                myav = new AV(this.picLocal, this.picRemote);
                mixer = new Mixer(this);
                mixer.MixerControlChange += new EventHandler(mixer_MixerControlChange);


                this.outdtl = new gowk.multimedia.Mixer.MixerControlDetail(mixer, gowk.multimedia.Mixer.MIXERLINE_COMPONENTTYPE_DST_SPEAKERS);
                this.outvolume.Minimum = this.outdtl.Min;
                this.outvolume.Maximum = this.outdtl.Max;
                this.outvolume.Value = this.outdtl.Volume;
                this.outvolume.MouseMove += new MouseEventHandler(outvolume_MouseMove);
                this.outvolume.MouseUp += new MouseEventHandler(outvolume_MouseUp);

                this.indtl = new gowk.multimedia.Mixer.MixerControlDetail(mixer, gowk.multimedia.Mixer.MIXERLINE_COMPONENTTYPE_SRC_MICROPHONE);
                this.involume.Minimum = indtl.Min;
                this.involume.Maximum = indtl.Max;
                this.involume.Value = this.indtl.Volume;
                this.involume.MouseMove += new MouseEventHandler(involume_MouseMove);
                this.involume.MouseUp += new MouseEventHandler(involume_MouseUp);
                this.Icon = avt.Properties.Resources.AVPhone;
                /*
                  myav.IniChanel();
                  myav.IniAudio();
                  myav.IniVideo();
                  */
                myav.Initial();
                //this.Width = picLocal.Left + picLocal.Width + 32 + (this.Width - this.ClientSize.Width);
                //this.Height = picLocal.Top + picLocal.Height + 32 + (this.Height - this.ClientSize.Height);
                myav.AVChanel.StreamEnd += new AVChanel.AVChanelEventHandler(AVChanel_StreamEnd);
                myav.AVChanel.StreamError += new AVChanel.AVChanelEventHandler(AVChanel_StreamError);
                myav.AVChanel.SteamStart += new AVChanel.AVChanelEventHandler(AVChanel_SteamStart);
                

                if (System.Environment.GetCommandLineArgs().Length >= 3)  //GetCommandLineArgs()返回一个String[],参数[0]为exe文件名
                {
                    //为了调试方便,还可以在程序的 属性页-调试 设置启动参数,或者外部写bat文件测试
                    //参数格式 [对方地址] [对方端口] [对方用户名]
                    textBox1.Text = System.Environment.GetCommandLineArgs()[1];
                    textBox2.Text = System.Environment.GetCommandLineArgs()[2];
                    panel1.Visible = false;
                }
                else if (System.Environment.GetCommandLineArgs().Length == 2)
                {
                    //button2.Enabled = false;
                    //panel1.Visible = false;
                }
                if (System.Environment.GetCommandLineArgs().Length == 4)
                {
                    lblRemote.Text = System.Environment.GetCommandLineArgs()[3] + " 的视频";


                }
                try
                {
                    string[] tmpstr = File.ReadAllLines(me.DirectoryName + "\\save.dat", Encoding.Unicode);
                    if (!(tmpstr[0].Trim() == ""))
                    {
                        picSave = tmpstr[0];
                    }
                }
                catch
                {
                    Stream fs = File.Open(me.DirectoryName + "\\save.dat", FileMode.OpenOrCreate);
                    fs.Close();
                }
                
            }
            catch (Exception ex)
            {
                MessageBox.Show("错误!" + ex.Message,"ZX Messenger AVPhone", MessageBoxButtons.OK, MessageBoxIcon.Error);
                //this.Close();
            }

             
            
        }

         

        void involume_MouseUp(object sender, MouseEventArgs e)
        {
            //throw new Exception("The method or operation is not implemented.");
            if (e.X < 0 || e.X > this.involume.Width) return;
            int v = (int)(e.X * this.involume.Maximum / this.involume.Width);
            this.indtl.Volume = v;
            this.involume.Value = this.indtl.Volume;
        }

        void involume_MouseMove(object sender, MouseEventArgs e)
        {
            //throw new Exception("The method or operation is not implemented.");
            if (this.involume.Capture) involume_MouseUp(sender, e);
        }

        void outvolume_MouseUp(object sender, MouseEventArgs e)
        {
            //throw new Exception("The method or operation is not implemented.");
            if (e.X < 0 || e.X > this.outvolume.Width) return;
            int v = (int)(e.X * this.outvolume.Maximum / this.outvolume.Width);
            this.outdtl.Volume = v;
            this.outvolume.Value = this.outdtl.Volume;
        }

        void outvolume_MouseMove(object sender, MouseEventArgs e)
        {
            //throw new Exception("The method or operation is not implemented.");
            if (this.outvolume.Capture) outvolume_MouseUp(sender, e);
        }

        

        void mixer_MixerControlChange(object sender, EventArgs e)
        {
            //throw new Exception("The method or operation is not implemented.");
            SyncVolumn();
        }


        private void SyncVolumn()
        {
            this.involume.Value = this.indtl.Volume;
            this.outvolume.Value = this.outdtl.Volume;
        }
        

        void AVChanel_SteamStart(object sender, AVChanel.AVChanelEventArgs e)
        {
            //throw new Exception("The method or operation is not implemented.");
            StreamStarted = true;
            StreamEnded = false;
            StreamError = false;
            Debug.Print("********************coversation started******************");
            
            
        }

        void AVChanel_StreamError(object sender, AVChanel.AVChanelEventArgs e)
        {
            //throw new Exception("The method or operation is not implemented.");
             
            StreamError = true;
            StreamStarted = false;
             

        }

        void AVChanel_StreamEnd(object sender, AVChanel.AVChanelEventArgs e)
        {
            //throw new Exception("The method or operation is not implemented.");
             
            StreamEnded = true;
            StreamStarted = false;
            
        }

        void frmChat_FormClosing(object sender, System.Windows.Forms.FormClosingEventArgs e)
        {
            //throw new System.Exception("The method or operation is not implemented.");
            try
            {
                if (myav != null)
                {

                    myav.Dispose();
                    mixer.Close();
                    Application.DoEvents();
                }
            }
            catch (Exception ex)
            {
                Debug.Print(ex.Message);
            }
            Application.Exit();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            try
            {
                if (myav != null)
                {
                    if (myav.Chanel.Connected)
                    {
                        myav.Chanel.Disconnect();
                        StreamEnded = true;
                    }
                }
            }
            catch (Exception ex)
            {
                Debug.Print(ex.Message);
            }

           
            RestorePic();
            //button2.Enabled = false;
        }
        private void RestorePic()
        {
            try
            {
                picLocal.Width = 176;
                picLocal.Height = 144;
                //远程
                picRemote.Width = 176;
                picRemote.Height = 144;
                picRemote.Refresh();
                this.Width = 459;
                this.Height = 493;
            }
            catch (Exception ex)
            {
                picRemote.Refresh();
                picLocal.Refresh();
                Debug.Print(ex.Message);
            }
               


        }

        private void button2_Click(object sender, EventArgs e)
        {
            if (lblStatus.Text != "连接成功,正在通话...")
            {
                pictureBox1.Image = avt.Properties.Resources.connect ;
                progressBar1.Visible = true;
               
                lblStatus.Text = "重新呼叫";
            }
            if (myav != null)
            {
                myav.Start(textBox1.Text, int.Parse(textBox2.Text));
            }

        }

        private void timer1_Tick(object sender, EventArgs e)
        {
            
            if (StreamStarted)
            {
                progressBar1.Visible = false;
                lblStatus.Text = "连接成功,正在通话...";
                lblStatus.Left = pictureBox1.Left;
                pictureBox1.Image = avt.Properties.Resources.remote;
                
            
            }
            if (StreamError)
            {
                lblStatus.Text = "网络错误!连接已断开。";
                pictureBox1.Image = avt.Properties.Resources.stop;
            }
            if(StreamEnded)
            {
                lblStatus.Text = "通话已停止。";
                lblStatus.Left =pictureBox1.Left ;
                pictureBox1.Image = avt.Properties.Resources.kllckety;
                picRemote.Refresh();
                picLocal.Refresh();
                 
            }

        }

        private void toolStripButton3_Click(object sender, EventArgs e)
        {
            picSaveDlg.ShowDialog();
            if (picSaveDlg.SelectedPath != "")
            {
                picSave = picSaveDlg.SelectedPath;
                try
                {
                    FileStream fs = File.Open((new FileInfo(Application.ExecutablePath)).DirectoryName+"\\save.dat", FileMode.OpenOrCreate);
                    fs.Write(UnicodeEncoding.Unicode.GetBytes(picSave.ToCharArray()), 0, UnicodeEncoding.Unicode.GetBytes(picSave.ToCharArray()).Length);
                    fs.Close();
                }
                catch
                {

                }

            }
            //Debug.Print(picSave);
        }

        private void toolStripButton1_Click(object sender, EventArgs e)
        {
            try
            {
                if (myav != null)
                {
                    if (myav.Chanel.Connected)
                    {
                        myav.Chanel.Disconnect();
                        Application.DoEvents();
                    }
                }
            }
            catch (Exception ex)
            {
                Debug.Print(ex.Message);
            }
            finally
            {
                this.Close();
            }
        }

        private void toolStripButton4_Click(object sender, EventArgs e)
        {
            //Debug.Print(GetFileNameStr());
            
            if (myav.SaveToPicture(picSave+"\\"+GetFileNameStr()))
            {
                lblpicSave.Text = "照片成功保存至:"+picSave ;
            }
            else
            {
                lblpicSave.Text = "照片保存失败!";
            }
        }
        private string GetFileNameStr()
        {

             
            
            return  DateTime.Now.ToString().Replace(":","_")  + ".bmp";




        }

        private void toolStripButton5_Click(object sender, EventArgs e)
        { 
                
               if( myav.SaveRemoteToPicture(picSave + "\\" + GetFileNameStr()))
               {
                   lblpicSave.Text = "照片成功保存至:"+picSave ;
               }else{
                   lblpicSave.Text = "照片保存失败!";
               }
 
        }

       

    }
}

⌨️ 快捷键说明

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