OnStateChange()

Tome`

Member
Joined
Jun 7, 2004
Messages
9
I’ve been creating a simple Media Encoder program and it seems to work fine except the following. Can someone tell me why I can’t get an event to fire under OnStateChange? Here’s my code.



Private Sub MyEncoder_OnStateChange(ByVal enumState As WMEncoderLib.WMENC_ENCODER_STATE)

‘even this won’t fire

MyState.Text = "Hello World"

Select Case enumState

Case WMENC_ENCODER_RUNNING

MyState.Text = "Running"

Case WMENC_ENCODER_STOPPED

MyState.Text = "Stopped"

End Select

End Sub





Thanks
 

mzim

Well-known member
Joined
Jun 3, 2004
Messages
187
Location
Other side of the rock
Programming Experience
1-3
Tome` said:
Sorry I am really new to this so I don't follow what you are saying.
what ayan is trying to figure out is...
put an event in your:
Private Sub MyEncoder_OnStateChange(ByVal enumState As WMEncoderLib.WMENC_ENCODER_STATE)

and put an add handler..for example.. Handles button1.click to trigger your function.

hope it helps...if not sorry
 

Tome`

Member
Joined
Jun 7, 2004
Messages
9
It just doesn't seem to work for me, I wonder what I am doing worng. Sorry this editor sucks.

WMEncoder.OnStateChange
The OnStateChange event receives an event notice indicating whether the encoding process has been started or stopped.


Syntax

WMEncoder.OnStateChange(enumState)
Parameters


enumState

[in] Member of a WMENC_ENCODER_STATE enumeration type to specify the operating state.

Return Values

This event does not return a value.

Remarks

Use the OnStateChange method to respond to encoding state event notices. For example, use this callback to determine when to enable or disable UI command buttons that depend upon whether the encoding process is running or stopped.

Example Code

VB.NET:
Private Sub Encoder_OnStateChange(ByVal enumState As WMEncoderLib.WMENC_ENCODER_STATE)[/size][/font][/b]

[b][font=Courier New][size=2]	Select Case enumState
		Case WMENC_ENCODER_STARTING
			' Process the case.
		Case WMENC_ENCODER_RUNNING
			' Process the case.
		Case WMENC_ENCODER_STOPPING
			' Process the case.
		Case WMENC_ENCODER_STOPPED
			' Process the case.[/size][/font][/b]

[b][font=Courier New][size=2]	End Select
End Sub
 

Paszt

Staff member
Joined
Jun 3, 2004
Messages
1,500
Location
Raleigh, NC - USA
Programming Experience
Beginner
It needs to have a handles clause.
To try and explain, I'll show the code for the click event handler for a button named button1:

VB.NET:
Private Sub Button1_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles Button1.Click
    'Code goes here
End Sub

Unlike VB6 (and previous versions), VB.NET needs the 'Handles' clause after the procedure declaration. Without this, the code is never executed. In VB6, the event handler (procedure) would have the name of the object followed by an underscore then the event name. This would let the compiler know what to do with the code.

Try this in your procedure declaration:

VB.NET:
Private Sub Encoder_OnStateChange( _
ByVal enumState As WMEncoderLib.WMENC_ENCODER_STATE) Handles Encoder.OnStateChange

I don't have access to the Windows Media encoder, so I can't verify the correct syntax.
 

Tome`

Member
Joined
Jun 7, 2004
Messages
9
Paszt, and everyone else!

That did the trick, thanks a lot. It is too bad that the examples given within the Help feature of .NET does not have the code documented correctly. It makes it harder to learn something. Thanks again
 
Top Bottom