看了N多关于C#的书上都没有介绍过,郁闷!要使用COM??还是winAPI?
解决方案 »
- 如何获得类中的private成员列表
- 怎么读取WindowsUpdate.log中内容
- 关于dataGirdView设置分页问题
- 如何获取远程计算机的文件信息
- 急问,怎么得到配置文件中的configSections下的组的名称?
- C#的一个程序里是否可以这么做?
- 图片定时转换功能如何实现?在线及等!!!
- 我用 vs.net 生成sqlconnection 后,在图形界面生成字符串 连接正常,但是放到web.config中总报sql拒绝访问!
- vb.net里面的mustoverride在c#里面的语法是什么?谢谢
- 小弟我用一个timer控件控制每过一秒就给一个类的成员变量的值增加一,可是没有用???
- 在C#中调用ORACLE的存储过程,怎么会出错?? 请大家帮我更改代码?
- C#中如何创建exe文件?
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); }
}
}
他俩不怎么相关把。感觉就directx和多媒体搭点边。
http://www.codeproject.com/cs/media/#DirectX
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());
}}