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

📄 frmmain.cs

📁 2001年度.net程序大赛清华大学作品 网上订票系统
💻 CS
字号:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Runtime.InteropServices;

namespace MobileClient
{
	/// <summary>
	/// Summary description for Form1.
	/// </summary>
	public class frmMain : System.Windows.Forms.Form
	{
		[DllImport("Sound.dll", EntryPoint="HelloWorld",
		 ExactSpelling=false,CallingConvention=CallingConvention.StdCall)]
		public static extern IntPtr HelloWorld();
		
		[DllImport("Sound.dll", EntryPoint="Start",
			 ExactSpelling=false,CallingConvention=CallingConvention.StdCall)]
		public static extern void Start();
		
		[DllImport("Sound.dll", EntryPoint="Stop",
			 ExactSpelling=false,CallingConvention=CallingConvention.StdCall)]
		public static extern void Stop();
		
		[DllImport("Sound.dll", EntryPoint="PlayVoice",
			 ExactSpelling=false,CallingConvention=CallingConvention.StdCall)]
		public static extern void PlayVoice();
		
		[DllImport("Sound.dll", EntryPoint="Play",
			 ExactSpelling=false,CallingConvention=CallingConvention.StdCall)]
		public static extern void Play(byte[] b,int Length);
		
		[DllImport("Sound.dll", EntryPoint="GetBufferLength",
			 ExactSpelling=false,CallingConvention=CallingConvention.StdCall)]
		public static extern int GetBufferLength();
		
		[DllImport("Sound.dll", EntryPoint="GetInputBuffer",
			 ExactSpelling=false,CallingConvention=CallingConvention.StdCall)]
		public static extern IntPtr GetInputBuffer();

		private System.Windows.Forms.Button btnStart;
		private System.Windows.Forms.Button btnStop;
		private GateWay.VoiceCmd vc;
		private GateWay.CmdResult cr;
		private System.Windows.Forms.Label label1;
		private System.Windows.Forms.Label label2;
		/// <summary>
		/// Required designer variable.
		/// </summary>
		private System.ComponentModel.Container components = null;

		public frmMain()
		{
			//
			// Required for Windows Form Designer support
			//
			InitializeComponent();
			vc = new GateWay.VoiceCmd();
			cr = new GateWay.CmdResult();
			//
			// TODO: Add any constructor code after InitializeComponent call
			//
		}

		/// <summary>
		/// Clean up any resources being used.
		/// </summary>
		protected override void Dispose( bool disposing )
		{
			if( disposing )
			{
				if (components != null) 
				{
					components.Dispose();
				}
			}
			base.Dispose( disposing );
		}

		#region Windows Form Designer generated code
		/// <summary>
		/// Required method for Designer support - do not modify
		/// the contents of this method with the code editor.
		/// </summary>
		private void InitializeComponent()
		{
			this.label1 = new System.Windows.Forms.Label();
			this.label2 = new System.Windows.Forms.Label();
			this.btnStop = new System.Windows.Forms.Button();
			this.btnStart = new System.Windows.Forms.Button();
			this.SuspendLayout();
			// 
			// label1
			// 
			this.label1.AutoSize = true;
			this.label1.Location = new System.Drawing.Point(40, 56);
			this.label1.Name = "label1";
			this.label1.Size = new System.Drawing.Size(104, 13);
			this.label1.TabIndex = 1;
			this.label1.Text = "Tsinghua University";
			// 
			// label2
			// 
			this.label2.AutoSize = true;
			this.label2.Location = new System.Drawing.Point(16, 88);
			this.label2.Name = "label2";
			this.label2.Size = new System.Drawing.Size(151, 13);
			this.label2.TabIndex = 1;
			this.label2.Text = "Moblie Life Client Version 1.0";
			// 
			// btnStop
			// 
			this.btnStop.Location = new System.Drawing.Point(96, 16);
			this.btnStop.Name = "btnStop";
			this.btnStop.Size = new System.Drawing.Size(69, 22);
			this.btnStop.TabIndex = 0;
			this.btnStop.Text = "Stop";
			this.btnStop.Click += new System.EventHandler(this.btnStop_Click);
			// 
			// btnStart
			// 
			this.btnStart.Location = new System.Drawing.Point(8, 16);
			this.btnStart.Name = "btnStart";
			this.btnStart.Size = new System.Drawing.Size(68, 22);
			this.btnStart.TabIndex = 0;
			this.btnStart.Text = "Start";
			this.btnStart.Click += new System.EventHandler(this.btnStart_Click);
			// 
			// frmMain
			// 
			this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
			this.ClientSize = new System.Drawing.Size(176, 119);
			this.Controls.AddRange(new System.Windows.Forms.Control[] {
																		  this.label2,
																		  this.label1,
																		  this.btnStop,
																		  this.btnStart});
			this.Name = "frmMain";
			this.Text = "Moblie Client";
			this.Load += new System.EventHandler(this.frmMain_Load);
			this.ResumeLayout(false);

		}
		#endregion

		/// <summary>
		/// The main entry point for the application.
		/// </summary>
		[STAThread]
		static void Main() 
		{
			Application.Run(new frmMain());
		}

		private void btnStart_Click(object sender, System.EventArgs e)
		{
			Start();
		}

		private void btnStop_Click(object sender, System.EventArgs e)
		{
			Stop();
			int length = GetBufferLength();
			IntPtr ret = Marshal.AllocHGlobal(length);
			ret = GetInputBuffer();	
			byte[] b = new byte[length];
			int i;
			for (i = 0 ; i < length ; i++)
				b[i] = Marshal.ReadByte(ret,i);
			cr = vc.Command("lfan",b);
			string str = cr.text;
			SpeechLib.SpVoice sp = new SpeechLib.SpVoice();
			sp.Speak(str,SpeechLib.SpeechVoiceSpeakFlags.SVSFDefault);
		}

		private void btnPlay_Click(object sender, System.EventArgs e)
		{
			PlayVoice();
		}

		private void frmMain_Load(object sender, System.EventArgs e)
		{

		}
	}
}

⌨️ 快捷键说明

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