VBGood网站全文搜索 Google

首页 - 经验之谈 - Find out if an application is running in the IDE
发表评论(0)作者:不详, 平台:VB6.0+Win98, 阅读:8208, 日期:2001-04-17
Find out if an application is running in the IDE

In a recent project I was working on, I had to find out if the application was running in the VB IDE or in compiled form.

VB doesn注释:t, to my knowledge, have any built in function to find this out so I wrote a small function my self.

This function works on the fact that the class name of a VB form is "ThunderFormDC" when it runs in the IDE and "ThunderRT6FormDC" when it runs in compiled form. So the function simply calls the FindWindowEx and passes ThunderFormDC as the class name and the form caption as the window name. It then checks if the return value equals the form window handle.

To try this out simply copy the following code to the main form of any application:

注释:form code
Option Explicit

Private Declare Function FindWindowEx _
Lib "user32" Alias "FindWindowExA" ( _
ByVal hWnd1 As Long, _
ByVal hWnd2 As Long, _
ByVal lpsz1 As String, _
ByVal lpsz2 As String) As Long

Private Function RunningInIDE() As Boolean
    Dim hWnd As Long
    hWnd = FindWindowEx(0&, 0&, "ThunderFormDC", Me.Caption)
    RunningInIDE = (hWnd = Me.hWnd)
End Function

Private Sub Form_Load()
    If RunningInIDE = True Then
        MsgBox "The application runs in the VB IDE"
        MsgBox "The application runs in compiled form"
    End If
End Sub
注释:end form code