Screen Capture tutorial

Picture
For this tutorial you will need to place the following controls onto your form which will be used as follows:

  • Button1 - Start Recording
  • Button2 - Stop Recording
  • Button3 - Watch Recording
  • TextBox1 - Name of save file
  • Checkbox1 - Select Low or High quality recording
  • WindowsMediaPlayer Control
OK after you have done that you need to add references to some .DLL files and you can download those here: DOWNLOAD

You will also need to download Media Player 9 Encoder and SDK from microsoft website and you can get those here:
Encoder
SDK

Once you have done that just copy and paste this code into your form using code-view:

Imports System.IO
Public Class Form1

Dim Encoder As WMEncoder
Dim quality = "Windows Media Video 8 for Local Area Network (384 Kbps)"
Dim savefold

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
If TextBox1.Text = ""Then
MsgBox("Please type a file name")
Else
Button1.Enabled = False
Button2.Enabled = True
MakeVideo()
End If
End Sub

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Button2.Enabled = False
Button1.Enabled = True
Encoder.Stop()
End Sub


Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
Try
AxWindowsMediaPlayer1.URL = "C:\SCVids\" + TextBox1.Text + ".avi"
Catch ex As Exception
End Try
End Sub

Private Sub CheckBox1_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CheckBox1.CheckedChanged
If CheckBox1.Checked = True Then
quality = "Screen Video/Audio High (CBR)"
Else
quality = "Windows Media Video 8 for Local Area Network (384 Kbps)"
End If
End Sub

Private Sub MakeVideo()
Encoder =
New WMEncoder
' Retrieve the source group collection and add a source group.
Dim SrcGrp As IWMEncSourceGroup2
Dim SrcGrpColl As IWMEncSourceGroupCollection
SrcGrpColl = Encoder.SourceGroupCollection
SrcGrp = SrcGrpColl.Add(
"SG_1")
' Add a video and audio source to the source group.
Dim SrcVid As IWMEncVideoSource2
Dim SrcAud As IWMEncAudioSource
SrcVid = SrcGrp.AddSource(WMENC_SOURCE_TYPE.WMENC_VIDEO)
SrcAud = SrcGrp.AddSource(WMENC_SOURCE_TYPE.WMENC_AUDIO)
' Identify the source files to encode.
SrcVid.SetInput("ScreenCap://ScreenCapture1")
SrcAud.SetInput(
"Device://Default_Audio_Device")
' Choose a profile from the collection.
Dim ProColl As IWMEncProfileCollection
Dim Pro As IWMEncProfile
Dim i As Integer
Dim lLength As Long
ProColl = Encoder.ProfileCollection
lLength = ProColl.Count
For i = 0 To lLength - 1
Pro = ProColl.Item(i)
If Pro.Name = quality Then
SrcGrp.Profile = Pro
Exit For
End If
Next
' Specify a file object in which to save encoded content.
Dim File As IWMEncFile
File = Encoder.File
File.LocalFileName =
"C:\SCVids\" + TextBox1.Text + ".avi"
' Crop 2 pixels from each edge of the video image.
SrcVid.CroppingBottomMargin = 2
SrcVid.CroppingTopMargin = 2
SrcVid.CroppingLeftMargin = 2
SrcVid.CroppingRightMargin = 2
' Start the encoding process.
Encoder.Start()
End Sub

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Button2.Enabled =
False
If Dir("C:\SCVids", vbDirectory) = ""Then MkDir("C:\SCVids")
End Sub
End
Class

 

 

dllfiles.zip
File Size: 127 kb
File Type: zip
Download File