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

📄 testfrm.cs

📁 本代码设计了一个销售管理系统
💻 CS
字号:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using QuartzTypeLib;

namespace LtsClient
{
	/// <summary>
	/// testFrm 的摘要说明。
	/// </summary>
	public class testFrm : System.Windows.Forms.Form
	{
		private System.ComponentModel.IContainer components;
		private const int WM_APP = 0x8000;
		private const int WM_GRAPHNOTIFY = WM_APP + 1;
		private const int EC_COMPLETE = 0x01;
		private const int WS_CHILD = 0x40000000;
		private const int WS_CLIPCHILDREN = 0x2000000;

		private FilgraphManager m_objFilterGraph = null;
		private IBasicAudio m_objBasicAudio = null;
		private IVideoWindow m_objVideoWindow = null;
		private IMediaEvent m_objMediaEvent = null;
		private IMediaEventEx m_objMediaEventEx = null;
		private IMediaPosition m_objMediaPosition = null;
		private IMediaControl m_objMediaControl = null;
		enum MediaStatus { None, Stopped, Paused, Running };
		private MediaStatus m_CurrentStatus = MediaStatus.None;

		private System.Windows.Forms.ToolBar toolBar1;
		private System.Windows.Forms.ToolBarButton toolBarButton1;
		private System.Windows.Forms.ToolBarButton toolBarButton2;
		private System.Windows.Forms.ToolBarButton toolBarButton3;
		private System.Windows.Forms.ToolBarButton toolBarButton4;
		private System.Windows.Forms.ToolBarButton toolBarButton5;
		private System.Windows.Forms.Panel panel1;
		/// <summary>
		/// 必需的设计器变量。
		/// </summary>

		public testFrm()
		{
			//
			// Windows 窗体设计器支持所必需的
			//
			InitializeComponent();

			//
			// TODO: 在 InitializeComponent 调用后添加任何构造函数代码
			//
		}

		/// <summary>
		/// 清理所有正在使用的资源。
		/// </summary>
		protected override void Dispose( bool disposing )
		{
			if( disposing )
			{
				if(components != null)
				{
					components.Dispose();
				}
			}
			base.Dispose( disposing );
		}

		#region Windows Form Designer generated code
		/// <summary>
		/// 设计器支持所需的方法 - 不要使用代码编辑器修改
		/// 此方法的内容。
		/// </summary>
		private void InitializeComponent()
		{
			this.toolBar1 = new System.Windows.Forms.ToolBar();
			this.toolBarButton1 = new System.Windows.Forms.ToolBarButton();
			this.toolBarButton2 = new System.Windows.Forms.ToolBarButton();
			this.toolBarButton3 = new System.Windows.Forms.ToolBarButton();
			this.toolBarButton4 = new System.Windows.Forms.ToolBarButton();
			this.toolBarButton5 = new System.Windows.Forms.ToolBarButton();
			this.panel1 = new System.Windows.Forms.Panel();
			this.SuspendLayout();
			// 
			// toolBar1
			// 
			this.toolBar1.Buttons.AddRange(new System.Windows.Forms.ToolBarButton[] {
																						this.toolBarButton1,
																						this.toolBarButton2,
																						this.toolBarButton3,
																						this.toolBarButton4,
																						this.toolBarButton5});
			this.toolBar1.ButtonSize = new System.Drawing.Size(80, 20);
			this.toolBar1.DropDownArrows = true;
			this.toolBar1.Name = "toolBar1";
			this.toolBar1.ShowToolTips = true;
			this.toolBar1.Size = new System.Drawing.Size(408, 25);
			this.toolBar1.TabIndex = 5;
			this.toolBar1.TextAlign = System.Windows.Forms.ToolBarTextAlign.Right;
			this.toolBar1.ButtonClick += new System.Windows.Forms.ToolBarButtonClickEventHandler(this.toolBar1_ButtonClick);
			// 
			// toolBarButton1
			// 
			this.toolBarButton1.Text = "打开  ";
			// 
			// toolBarButton2
			// 
			this.toolBarButton2.Text = "播放";
			// 
			// toolBarButton3
			// 
			this.toolBarButton3.Text = "暂停";
			// 
			// toolBarButton4
			// 
			this.toolBarButton4.Text = "停止";
			// 
			// toolBarButton5
			// 
			this.toolBarButton5.Text = "关闭";
			// 
			// panel1
			// 
			this.panel1.AllowDrop = true;
			this.panel1.BackColor = System.Drawing.SystemColors.ControlDarkDark;
			this.panel1.Location = new System.Drawing.Point(0, 32);
			this.panel1.Name = "panel1";
			this.panel1.Size = new System.Drawing.Size(408, 312);
			this.panel1.TabIndex = 6;
			// 
			// testFrm
			// 
			this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
			this.ClientSize = new System.Drawing.Size(408, 341);
			this.Controls.AddRange(new System.Windows.Forms.Control[] {
																		  this.panel1,
																		  this.toolBar1});
			this.Name = "testFrm";
			this.Text = "testFrm";
			this.ResumeLayout(false);

		}
		#endregion

		private void toolBar1_ButtonClick(object sender, System.Windows.Forms.ToolBarButtonClickEventArgs e)
		{
			switch(toolBar1.Buttons.IndexOf(e.Button))
			{
				case 0: Open_Dialog(sender,e);
					break; 

				case 1: m_objMediaControl.Run();
					m_CurrentStatus = MediaStatus.Running;
					break; 
				
				case 2: m_objMediaControl.Pause();
					m_CurrentStatus = MediaStatus.Paused;
					break; 

				case 3: m_objMediaControl.Stop();
					m_objMediaPosition.CurrentPosition = 0;
					m_CurrentStatus = MediaStatus.Stopped;
					CleanUp();
					break;
				case 4: ExitWin(sender,e);
					break; 
			}
            
			UpdateToolBar();  
		}

		private void CleanUp()
		{
			if (m_objMediaControl != null)
				m_objMediaControl.Stop();

			m_CurrentStatus = MediaStatus.Stopped;

			if (m_objMediaEventEx != null)
				m_objMediaEventEx.SetNotifyWindow(0, 0, 0);

			if (m_objVideoWindow != null)
			{
				m_objVideoWindow.Visible = 0;
				m_objVideoWindow.Owner = 0;
			}

			if (m_objMediaControl != null) m_objMediaControl = null;
			if (m_objMediaPosition != null) m_objMediaPosition = null;
			if (m_objMediaEventEx != null) m_objMediaEventEx = null;
			if (m_objMediaEvent != null) m_objMediaEvent = null;
			if (m_objVideoWindow != null) m_objVideoWindow = null;
			if (m_objBasicAudio != null) m_objBasicAudio = null;
			if (m_objFilterGraph != null) m_objFilterGraph = null;
		}

		private void Open_Dialog(object sender, System.EventArgs e)
		{
			OpenFileDialog openFileDialog = new OpenFileDialog();

			openFileDialog.Filter = "Media Files|*.mpg;*.avi;*.wma;*.mov;*.wav;*.mp2;*.mp3|All Files|*.*";

			if (DialogResult.OK == openFileDialog.ShowDialog())
			{
				CleanUp();

				m_objFilterGraph = new FilgraphManager();
				m_objFilterGraph.RenderFile(openFileDialog.FileName);				
                
				try
				{
					m_objBasicAudio = m_objFilterGraph as IBasicAudio;
					m_objVideoWindow = m_objFilterGraph as IVideoWindow;
					m_objVideoWindow.Owner = (int) panel1.Handle;
					m_objVideoWindow.WindowStyle = WS_CHILD | WS_CLIPCHILDREN;
					m_objVideoWindow.SetWindowPosition(panel1.ClientRectangle.Left,
						panel1.ClientRectangle.Top,
						panel1.ClientRectangle.Width,
						panel1.ClientRectangle.Height);
				}
				catch (Exception ex)
				{
					MessageBox.Show("不支持此类型");
					m_objVideoWindow = null;
				}

				m_objMediaEvent = m_objFilterGraph as IMediaEvent;

				m_objMediaEventEx = m_objFilterGraph as IMediaEventEx;
				m_objMediaEventEx.SetNotifyWindow((int) this.Handle,WM_GRAPHNOTIFY, 0);

				m_objMediaPosition = m_objFilterGraph as IMediaPosition;

				m_objMediaControl = m_objFilterGraph as IMediaControl;

				this.Text = "DirectShow - [" + openFileDialog.FileName + "]";

				m_objMediaControl.Run();
				m_CurrentStatus = MediaStatus.Running;

				UpdateToolBar();
			}
		}

		private void UpdateToolBar()
		{
			switch (m_CurrentStatus)
			{
				case MediaStatus.None   : 
					toolBarButton1.Enabled = true;
					toolBarButton2.Enabled = false;
					toolBarButton3.Enabled = false;
					toolBarButton4.Enabled = false;
					toolBarButton5.Enabled = true;
					break;
                                          
				case MediaStatus.Paused :
					toolBarButton1.Enabled = false;
					toolBarButton2.Enabled = true;
					toolBarButton3.Enabled = false;
					toolBarButton4.Enabled = true;
					toolBarButton5.Enabled = true;
					break;
                                          
				case MediaStatus.Running: 
					toolBarButton1.Enabled = false;
					toolBarButton2.Enabled = false;
					toolBarButton3.Enabled = true;
					toolBarButton4.Enabled = true;
					toolBarButton5.Enabled = true;
					break;
                                          
				case MediaStatus.Stopped:
					toolBarButton1.Enabled = true;
					toolBarButton2.Enabled = false;
					toolBarButton3.Enabled = false;
					toolBarButton4.Enabled = false;
					toolBarButton5.Enabled = true;
					break;
			}
		}

		private void ExitWin(object sender, System.EventArgs e)
		{
			this.Close();
		}
	}
}

⌨️ 快捷键说明

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