Original http://hi.baidu.com/wcsjsdn/item/b2af6de7fefa8a334ddcafb9
View Interface:
This is mainly implemented using the library files provided by Microsoft. (First install the decoder WMEncoder_cn.exe on the local machine. Note: This is the decoder of the XP system. If necessary, you can download the decoder installed with Windows 7) and add reference: Interop. WMEncoderLib. dll, add the namespace: using WMEncoderLib;
There is nothing to say about it. paste the Code directly:
First define a WMEncoderManage class
Public class WMEncoderManage
{
Private static WMEncoder _ encoder = null;
Public static WMEncoder GetWMEncoder
{
Get
{
If (_ encoder = null)
{
_ Encoder = new WMEncoder ();
}
Return _ encoder;
}
}
Private static string _ defaultFormat = "screen video/audio-height (CBR )";
Public static string DefaultFormat
{
Get
{
Return _ defaultFormat;
}
Set {_ defaultFormat = value ;}
}
}
Then start:
/// <Summary>
/// Video Recording Method
/// </Summary>
Private void Coder ()
{
Try
{
WMEncoder Encoder = WMEncoderManage. GetWMEncoder;
IWMEncSourceGroup srmrm;
IWMEncSourceGroupCollection srckgcoll;
Srckgcoll = Encoder. SourceGroupCollection;
Srmrm = srcgr. Add ("SG_1 ");
IWMEncSource SrcVid;
IWMEncSource SrcAud;
SrcVid = srmrm. AddSource (WMENC_SOURCE_TYPE.WMENC_VIDEO );
SrcAud = srmrm. AddSource (WMENC_SOURCE_TYPE.WMENC_AUDIO );
SrcAud. SetInput ("Default_Audio_Device", "Device ","");
SrcVid. SetInput ("ScreenCapture1", "ScreenCap ","");
IWMEncProfileCollection ProColl;
IWMEncProfile Pro;
Int I;
Long lLength;
ProColl = Encoder. ProfileCollection;
LLength = ProColl. Count;
For (I = 0; I <lLength-1; I ++)
{
Pro = ProColl. Item (I );
If (Pro. Name = WMEncoderManage. DefaultFormat)
{
Srmrm. set_Profile (Pro );
Break;
}
}
IWMEncDisplayInfo Descr;
Descr = Encoder. DisplayInfo;
Descr. Author = "wangchao ";
Descr. Copyright = "wangchao ";
Descr. Description = "wangchao ";
Descr. Rating = "wangchao ";
Descr. Title = "wangchao ";
IWMEncAttributes Attr;
Attr = Encoder. Attributes;
Attr. Add ("URL", "www.920wc.cn ");
IWMEncFile File;
File = Encoder. File;
File. LocalFileName = this. saveFileDialog1.FileName;
Encoder. Start ();
}
Catch (Exception)
{
Throw;
}
}
/// <Summary>
/// Browse
/// </Summary>
/// <Param name = "sender"> </param>
/// <Param name = "e"> </param>
Private void button#click (object sender, EventArgs e)
{
If (DialogResult. OK = this. saveFileDialog1.ShowDialog ())
{
This. tbFileSave. Text = saveFileDialog1.FileName;
}
}
In the "Start recording" button event:
Private void button2_Click (object sender, EventArgs e)
{
If (string. IsNullOrEmpty (this. tbFileSave. Text ))
{
MessageBox. Show ("select the video file storage path first ");
Return;
}
Coder ();
Label3.Text = "recording ...";
}
/// <Summary>
/// Stop recording
/// </Summary>
/// <Param name = "sender"> </param>
/// <Param name = "e"> </param>
Private void button3_Click (object sender, EventArgs e)
{
WMEncoderManage. GetWMEncoder. Stop ();
}
/// <Summary>
/// Pause recording
/// </Summary>
/// <Param name = "sender"> </param>
/// <Param name = "e"> </param>
Private void button4_Click (object sender, EventArgs e)
{
If (string. IsNullOrEmpty (tbFileSave. Text ))
{
MessageBox. Show ("please start recording and pause ");
Return;
}
If (this. button4.Text = "Pause recording ")
{
WMEncoderManage. GetWMEncoder. Pause ();
This. button4.Text = "Continue recording ";
Label3.Text = "Recording temporarily ...";
}
Else
{
WMEncoderManage. GetWMEncoder. Start ();
This. button4.Text = "Pause recording ";
Label3.Text = "recording ...";
}
}
}
Now, start the program and select the Save path and format to directly record the screen. Try it. The effect is good.