看了N多关于C#的书上都没有介绍过,郁闷!要使用COM??还是winAPI?

解决方案 »

  1.   

    using System;
    using System.Drawing;
    using System.Collections;
    using System.ComponentModel;
    using System.Windows.Forms;
    using System.Data;
    using System.Runtime.InteropServices;namespace APImciTest
    {
    /// <summary>
    /// Form1 的摘要说明。
    /// </summary>
    /// 
    public class LibWrap
    {
            [DllImport(("winmm.dll"), EntryPoint="mciSendString", CharSet=CharSet.Auto )]
    public static extern int mciSendString
    ( string lpszCommand, string lpszReturnString, uint cchReturn, int hwndCallback);
    }  //此处为API函数声明部分
    public class Form1 : System.Windows.Forms.Form
    {
    private System.Windows.Forms.PictureBox pictureBox1;
    /// <summary>
    /// 必需的设计器变量。
    /// </summary>
    private System.ComponentModel.Container components = null; public Form1()
    {
    //
    // 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.pictureBox1 = new System.Windows.Forms.PictureBox();
    this.SuspendLayout();
    // 
    // pictureBox1
    // 
    this.pictureBox1.BackColor = System.Drawing.SystemColors.ControlText;
    this.pictureBox1.Dock = System.Windows.Forms.DockStyle.Fill;
    this.pictureBox1.Name = "pictureBox1";
    this.pictureBox1.Size = new System.Drawing.Size(292, 273);
    this.pictureBox1.TabIndex = 0;
    this.pictureBox1.TabStop = false;
    this.pictureBox1.DoubleClick += new System.EventHandler(this.pictureBox1_DoubleClick);
    // 
    // Form1
    // 
    this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
    this.ClientSize = new System.Drawing.Size(292, 273);
    this.Controls.AddRange(new System.Windows.Forms.Control[] {
      this.pictureBox1});
    this.Name = "Form1";
    this.Text = "Form1";
    this.ResumeLayout(false); }
    #endregion /// <summary>
    /// 应用程序的主入口点。
    /// </summary>
    [STAThread]
    static void Main() 
    {
    Application.Run(new Form1());
    } private void pictureBox1_DoubleClick(object sender, System.EventArgs e)   //此处为双击播放应用部分,mciCommand中注意空格
    {
    PictureBox PlayScreen = new PictureBox();
    PlayScreen = this.pictureBox1;
    string mciCommand;
    mciCommand = "open " + "H:\\12.asf" + " alias MyAVI";
    mciCommand = mciCommand + " parent " + PlayScreen.Handle.ToInt32() + " style child";     
    LibWrap.mciSendString(mciCommand, null, 0,0);
    Rectangle r = PlayScreen.ClientRectangle;
    mciCommand = "put MyAVI window at 0 0 "+r.Width +" "+r.Height ;
    LibWrap.mciSendString( mciCommand, null, 0, 0);
    LibWrap.mciSendString ("play MyAVI", null, 0, 0); }
    }
    }
      

  2.   

    没看代码。
    他俩不怎么相关把。感觉就directx和多媒体搭点边。
      

  3.   

    ms网站上早就可以下载directx9.0 for .net的sdk下载,其中包含有帮助和代码示例。只要安装,directx9.0会自动嵌入.net ide中,甚至欢迎屏上都可以看到.
    http://www.codeproject.com/cs/media/#DirectX
      

  4.   

    using System;
    using System.ComponentModel;
    using System.Drawing;
    using System.Windows.Forms;
    using DxVBLib;public class Sample1Form : Form
    {
    private Container components = null;
    private Panel Panel1 = null; private DirectX7 DirectX = null;
    private DirectDraw7 DirectDraw = null;
    private DirectDrawSurface7 Surface = null;
    private DirectDrawSurface7 PrimarySurface = null;
    private DDSURFACEDESC2 Surface1; 
    private DDSURFACEDESC2 Surface2;
    private DirectDrawClipper Clipper = null; private Boolean bInit; public Sample1Form()
    {
    InitializeComponent();
    DirectX = new DirectX7();
    InitializeDirectX();
    } private void InitializeComponent()
    {
    this.components = new Container();
    this.Panel1 = new Panel(); Panel1.Location = new Point(0, 0);
    Panel1.Size = new Size(255, 255);
    Panel1.TabStop = false; this.Controls.Add(Panel1);
    this.Text = "Interoperability with DirectX";
    this.ClientSize = new Size(255, 255);

    // Event handlers
    this.Resize += new EventHandler(this.Form_Resize);
    Panel1.Paint += new PaintEventHandler(this.Panel1_Paint);
    } private void Form_Resize (System.Object sender, System.EventArgs e)
    {
        Panel1.Width = this.ClientSize.Width;
        Panel1.Height = this.ClientSize.Height;
        Blt();
    }

    //
    // Called during run-time when the form is moved or resized.
    //
    public void Panel1_Paint(System.Object sender, PaintEventArgs e)
    {
        DirectDraw.RestoreAllSurfaces();
        Blt();
    } private void Blt()
    {
        // Has DirectX been initialized? If not, exit.
        if (bInit == false)
    return; DxVBLib.RECT r1 = new DxVBLib.RECT();
        DxVBLib.RECT r2 = new DxVBLib.RECT();     // Gets the bounding rectangle for the entire window handle and stores it in r1
        DirectX.GetWindowRect(Panel1.Handle.ToInt32(), ref r1);
        
        r2.Bottom = Surface2.lHeight;
        r2.Right = Surface2.lWidth;
        
        PrimarySurface.Blt(ref r1, Surface, ref r2, CONST_DDBLTFLAGS.DDBLT_WAIT);
    } private void InitializeDirectX()
    {
        // The empty string parameter means to use the active display driver
        DirectDraw = DirectX.DirectDrawCreate("");
            
        // Indicate that this will be a normal windowed application
        // with the same display depth as the current display
        DirectDraw.SetCooperativeLevel(this.Handle.ToInt32(), CONST_DDSCLFLAGS.DDSCL_NORMAL);
        
    // Indicate that the ddsCaps member is valid
    Surface1.lFlags = CONST_DDSURFACEDESCFLAGS.DDSD_CAPS;

    // This surface is the primary surface (the one visible to the user)
    Surface1.ddsCaps.lCaps = CONST_DDSURFACECAPSFLAGS.DDSCAPS_PRIMARYSURFACE; // Create the primary surface with the surface description we just set
    PrimarySurface = DirectDraw.CreateSurface(ref Surface1);

    // Set the second surface description
    Surface2.lFlags = CONST_DDSURFACEDESCFLAGS.DDSD_CAPS; // This is going to be a plain off-screen surface
    Surface2.ddsCaps.lCaps = CONST_DDSURFACECAPSFLAGS.DDSCAPS_OFFSCREENPLAIN; //Create the off-screen surface try
    {
    Surface = DirectDraw.CreateSurfaceFromFile("background.bmp", ref Surface2);
    }
    catch(System.Runtime.InteropServices.COMException e)
    {
    // File Not Found
    if ( (uint)e.ErrorCode == 0x800A0035)
    {
    MessageBox.Show("Could not find the file 'background.bmp'.  This must be placed in the current directory.", "Picture Not Found");
    }
    else
    {
    MessageBox.Show("Unexpected exception: " + e.ToString(), "Unexpected Exception");
    }
    Application.Exit();
    Application.DoEvents();
    } Clipper = DirectDraw.CreateClipper(0);
    Clipper.SetHWnd(Panel1.Handle.ToInt32());
    PrimarySurface.SetClipper(Clipper); // We've finished initialization
    bInit = true;
    Blt();
    } [STAThread()]
    public static void Main()
    {
    Application.Run(new Sample1Form());
    }}