如何通过程序标题检查程序是否正在运行? (使用VB6)

发布于 2024-10-10 00:16:10 字数 252 浏览 3 评论 0原文

如何通过程序标题检查程序是否正在运行? (使用 vb6)

示例:

'check if there is a program contain a "Notepad" in its title

if (does "Notepad" running now ?) then 

end if

alt text

How to check if a program is running now or not by its title ? (using vb6)

Example :

'check if there is a program contain a "Notepad" in its title

if (does "Notepad" running now ?) then 

end if

alt text

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

星星的轨迹 2024-10-17 00:16:10
''# preparation (in a separate module)
Private Declare Function FindWindow Lib "user32.dll" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long

Public Function FindWindowHandle(Caption As String) As Long
  FindWindowHandle = FindWindow(vbNullString, Caption)
End Function

''# use (anywhere)
MsgBox FindWindowHandle("Untitled - Notepad")

上面的代码基本上取自此处

必须知道确切的窗口标题为了这。该函数将返回 <>如果找到具有给定标题的窗口,则为 0,否则为 0。

要查找标题包含特定字符串的窗口,您需要枚举所有窗口并自行查找正确的窗口。这个过程有点复杂,但在这里有非常详细的解释:everythingaccess.com - 将外部应用程序窗口置于前台

''# preparation (in a separate module)
Private Declare Function FindWindow Lib "user32.dll" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long

Public Function FindWindowHandle(Caption As String) As Long
  FindWindowHandle = FindWindow(vbNullString, Caption)
End Function

''# use (anywhere)
MsgBox FindWindowHandle("Untitled - Notepad")

Code above basically taken from here.

The exact window caption must be known for this. The function will return <> 0 if a window with the given caption was found, 0 otherwise.

To find a window whose caption contains a certain string, you will need to enumerate all windows and look for the correct one yourself. This process is a little more complicated, but explained in great detail here: everythingaccess.com - Bring an external application window to the foreground.

So尛奶瓶 2024-10-17 00:16:10

Karl Peterson 在他优秀的 VB6 网站上有一些很棒的代码。它使用 EnumWindows 就像 Tomalak 的答案(在链接中)

Karl Peterson has some great code for this on his excellent VB6 website. It uses EnumWindows like Tomalak's answer (in the link)

青萝楚歌 2024-10-17 00:16:10

传入应用程序的句柄和部分标题。如果找到则返回true。

Public Function GetHandleFromPartialCaption(ByRef lWnd As Long, ByVal sCaption As String) As Boolean

Dim lhWndP            As Long
Dim sStr              As String

GetHandleFromPartialCaption = False
lhWndP = FindWindow(vbNullString, vbNullString)                                      'PARENT WINDOW

Do While lhWndP <> 0
    sStr = String(GetWindowTextLength(lhWndP) + 1, Chr$(0))
    GetWindowText lhWndP, sStr, Len(sStr)
    sStr = Left$(sStr, Len(sStr) - 1)
    If InStr(1, sStr, sCaption) > 0 Then
        GetHandleFromPartialCaption = True
        lWnd = lhWndP
        Exit Do
    End If
    lhWndP = GetWindow(lhWndP, GW_HWNDNEXT)
Loop

结束功能

Pass in the handle of your app and a partial caption. It will return true if found.

Public Function GetHandleFromPartialCaption(ByRef lWnd As Long, ByVal sCaption As String) As Boolean

Dim lhWndP            As Long
Dim sStr              As String

GetHandleFromPartialCaption = False
lhWndP = FindWindow(vbNullString, vbNullString)                                      'PARENT WINDOW

Do While lhWndP <> 0
    sStr = String(GetWindowTextLength(lhWndP) + 1, Chr$(0))
    GetWindowText lhWndP, sStr, Len(sStr)
    sStr = Left$(sStr, Len(sStr) - 1)
    If InStr(1, sStr, sCaption) > 0 Then
        GetHandleFromPartialCaption = True
        lWnd = lhWndP
        Exit Do
    End If
    lhWndP = GetWindow(lhWndP, GW_HWNDNEXT)
Loop

End Function

冷心人i 2024-10-17 00:16:10

现在右键单击任务栏并单击任务管理器。现在显示您正在运行的程序。

Now right click on taskbar and click task manager. Now show your running program.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文