HOWTO: Use a Timer With A Visual Basic SnapIn Project
ID: Q242401
|
The information in this article applies to:
-
Microsoft Management Console, versions 1.1, 1.2
-
Microsoft Visual Basic Professional and Enterprise Editions for Windows, version 6.0
SUMMARY
This article demonstrates how to use a Timer object in a SnapIn project developed with the MMC Snap-in Designer For Visual Basic.
MORE INFORMATIONSteps To Reproduce Sample
- Start Visual Basic and create a new SnapIn project from the New Project dialog box.
- Open the SnapIn1 Designer and add a new URLView Result View to the Static Node. By default the new URLView is named URLView1.
- View the properties of the URLView and set it's URL property to a valid website (http://example.microsoft.com) and click Ok.
- View the SnapIn1 Designer properties, and set the Default Result View property to URLView1 and click Ok.
- Open the SnapIn1 Designer code window and paste in the following code:
Private Sub ResultViews_Deactivate(ByVal ResultView As SnapInLib.ResultView, Keep As Boolean)
' stop the timer object
If (ResultView.Tag) Then
Call KillTimer(0, ResultView.Tag)
End If
End Sub
Private Sub ResultViews_Initialize(ByVal ResultView As SnapInLib.ResultView)
' start the timer object
ResultView.Tag = SetTimer(0, 0, 1000, AddressOf TestTmrProc)
' if timer object failed, present a dialog to the user
If (ResultView.Tag = 0) Then
SnapIn.ConsoleMsgBox "Error Creating Timer Object", vbOKOnly + vbCritical, "Timer Object Error"
End If
End Sub
- Add a new Module to the project. By default this new module is named Module1.
- Open the Module1 code window and past in the following code:
Option Explicit
Public Declare Function SetTimer Lib "user32" (ByVal hwnd As Long, ByVal nIDEvent As Long, ByVal uElapse As Long, ByVal lpTimerFunc As Long) As Long
Public Declare Function KillTimer Lib "user32" (ByVal hwnd As Long, ByVal nIDEvent As Long) As Long
Public Declare Function Beep Lib "kernel32" (ByVal dwFreq As Long, ByVal dwDuration As Long) As Long
Public Sub TestTmrProc(ByVal hwnd As Long, ByVal uMsg As Long, ByVal iEvent As Long, ByVal iTime As Long)
' enable error handling here. this is important : any error which
' is not handled in the module may cause the Snapin to stop
' responding
On Error Resume Next
' print current time information to debug window
Debug.Print Now
End Sub
- Press F5 to run the SnapIn project from within the IDE. When the debugging dialog box appears, select the Start Program option and type MMC into the text field and click ok.
- When MMC loads, load the test SnapIn into the console.
- Select the SnapIn1 ScopePaneItem.
- Switch to the Visual Basic IDE, and examine the Immediate Window. The current time is printed once a second until another ScopeItem is selected or MMC is closed.
Additional query words:
snapin designer mmc
Keywords : kbMMC kbVBp600 kbGrpPlatform kbDSupport kbSnapIn
Version : WINDOWS:1.1,1.2,6.0
Platform : WINDOWS
Issue type : kbhowto
|