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 INFORMATION

Steps To Reproduce Sample


  1. Start Visual Basic and create a new SnapIn project from the New Project dialog box.


  2. Open the SnapIn1 Designer and add a new URLView Result View to the Static Node. By default the new URLView is named URLView1.


  3. View the properties of the URLView and set it's URL property to a valid website (http://example.microsoft.com) and click Ok.


  4. View the SnapIn1 Designer properties, and set the Default Result View property to URLView1 and click Ok.


  5. 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 


  6. Add a new Module to the project. By default this new module is named Module1.


  7. 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 


  8. 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.


  9. When MMC loads, load the test SnapIn into the console.


  10. Select the SnapIn1 ScopePaneItem.


  11. 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


Last Reviewed: January 10, 2000
© 2000 Microsoft Corporation. All rights reserved. Terms of Use.