Determine whether the VB IDE is the foreground process

At times you may need to verify that the VB IDE is the current process. This is necessary, for example, when you are notified that the user has presses a given hotkey and you want to ensure that this hotkey should be processed by your addin (if the VB IDE is the active process) or just ignored. Here’s a simple routine that does the job:’ return True if the VBIDE is the foreground process” This code only works inside a VB add-in and’ assumes that the VBInstance global variable holds’ a reference to the VBE root objectFunction VisualBasicIsActiveProcess() As Boolean Dim vbProcessID As Long Dim currProcessID As Long ‘ get ProcessID of Visual Basic GetWindowThreadProcessId VBInstance.MainWindow.hwnd, vbProcessID ‘ get processID of active Window GetWindowThreadProcessId GetForegroundWindow(), currProcessID ‘ return True if they match VisualBasicIsActiveProcess = (vbProcessID = currProcessID) End Function

Share the Post:
Share on facebook
Share on twitter
Share on linkedin


Recent Articles: