Microsoft KB Archive/242401

= How To Use a Timer With A Visual Basic SnapIn Project =

Article ID: 242401

Article Last Modified on 7/13/2004

-

APPLIES TO


 * Microsoft Management Console 1.1
 * Microsoft Management Console 1.2
 * Microsoft Visual Basic 6.0 Professional Edition
 * Microsoft Visual Basic 6.0 Enterprise Edition

-



This article was previously published under Q242401



SUMMARY
This article demonstrates how to use a Timer object in a SnapIn project developed with the MMC Snap-in Designer For Visual Basic.



Steps 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 </li> 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.</li> When MMC loads, load the test SnapIn into the console.</li> Select the SnapIn1 ScopePaneItem.</li> 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.</li></ol>

Additional query words: snapin designer mmc

Keywords: kbhowto kbsnapin kbdswmanage2003swept KB242401

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.