在程序开始的地方: If App.PrevInstance=True then Msgbox "程序已经运行", else end if
Enumerate All Open Windows (Parent and Children) http://www.freevbcode.com/ShowCode.Asp?ID=701Enumerate All Windows http://www.planet-source-code.com/vb/scripts/ShowCode.asp?txtCodeId=3196&lngWId=1
你也可以使用 如下代码进行对指定Title 的窗体查询. '=====Bas module code======= Private Declare Function EnumWindows& Lib "user32" (ByVal lpEnumFunc As Long, ByVal lParam As Long) Private Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String, ByVal cch As Long) As Long Private Declare Function IsWindowVisible& Lib "user32" (ByVal hwnd As Long) Private Declare Function GetParent& Lib "user32" (ByVal hwnd As Long) Dim sPattern As String, hFind As Long Public Function EnumWinProc(ByVal hwnd As Long, ByVal lParam As Long) As Long Dim k As Long, sName As String If IsWindowVisible(hwnd) And GetParent(hwnd) = 0 Then sName = Space$(128) k = GetWindowText(hwnd, sName, 128) If k > 0 Then sName = Left$(sName, k) If lParam = 0 Then sName = UCase(sName) If sName Like sPattern Then hFind = hwnd EnumWinProc = 0 Exit Function End If End If End If EnumWinProc = 1 End Function Public Function FindWindowWild(sWild As String, Optional bMatchCase As Boolean = True) As Long sPattern = sWild If Not bMatchCase Then sPattern = UCase(sPattern) EnumWindows AddressOf EnumWinProc, bMatchCase FindWindowWild = hFind End Function =================================================================tmp_hWnd = FindWindowWild("YourAppTitle", False) If tmp_hWnd > 0 Then Msgbox "App Is Running!"
' Display the title bar text of all top-level windows. This ' task is given to the callback function, which will receive each handle individually. ' Note that if the window has no title bar text, it will not be displayed (for clarity's sake).' *** Place this code in a module. This is the callback function. *** ' This function displays the title bar text of the window identified by hwnd. Public Function EnumWindowsProc (ByVal hwnd As Long, ByVal lParam As Long) As Long Dim slength As Long, buffer As String ' title bar text length and buffer Dim retval As Long ' return value Static winnum As Integer ' counter keeps track of how many windows have been enumerated winnum = winnum + 1 ' one more window enumerated.... slength = GetWindowTextLength(hwnd) + 1 ' get length of title bar text If slength > 1 ' if return value refers to non-empty string buffer = Space(slength) ' make room in the buffer retval = GetWindowText(hwnd, buffer, slength) ' get title bar text Debug.Print "Window #"; winnum; " : "; ' display number of enumerated window Debug.Print Left(buffer, slength - 1) ' display title bar text of enumerated window End If EnumWindowsProc = 1 ' return value of 1 means continue enumeration End Function' *** Place this code wherever you want to enumerate the windows. *** Dim retval As Long ' return value' Use the above callback function to list all of the enumerated windows. Note that lParam is ' set to 0 because we don't need to pass any additional information to the function. retval = EnumWindows(AddressOf EnumWindowsProc, 0)
If App.PrevInstance=True then
Msgbox "程序已经运行",
else
end if
http://www.freevbcode.com/ShowCode.Asp?ID=701Enumerate All Windows
http://www.planet-source-code.com/vb/scripts/ShowCode.asp?txtCodeId=3196&lngWId=1
码名称 显示工作条上的运行窗口
代码类型 系统控制
运行环境 VB5.0/Win9x
授权方式 免费代码
代码大小 4K
代码评价
上传时间 2001-11-29
相关链接 主页
本日下载 1 本周:39 总计:65
下载地址1 下载
代码简介 显示工作条上的运行窗口,程序还获得每个运行窗口的图标,另外可以把选中的窗口放到最上http://www.dapha.net/soure/windows/TM%20(TaskManager).zip
码名称 又一个运行程序管理程序
代码类型 系统控制
运行环境 VB5.0/Win9x
授权方式 免费代码
代码大小 31K
代码评价
上传时间 2001-11-29
相关链接 主页
本日下载 1 本周:141 总计:141
下载地址1 下载
代码简介 又一个运行程序管理程序.不过内存管理用了图象来显示,比较酷的
'=====Bas module code=======
Private Declare Function EnumWindows& Lib "user32" (ByVal lpEnumFunc As Long, ByVal lParam As Long)
Private Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String, ByVal cch As Long) As Long
Private Declare Function IsWindowVisible& Lib "user32" (ByVal hwnd As Long)
Private Declare Function GetParent& Lib "user32" (ByVal hwnd As Long) Dim sPattern As String, hFind As Long Public Function EnumWinProc(ByVal hwnd As Long, ByVal lParam As Long) As Long
Dim k As Long, sName As String
If IsWindowVisible(hwnd) And GetParent(hwnd) = 0 Then
sName = Space$(128)
k = GetWindowText(hwnd, sName, 128)
If k > 0 Then
sName = Left$(sName, k)
If lParam = 0 Then sName = UCase(sName)
If sName Like sPattern Then
hFind = hwnd
EnumWinProc = 0
Exit Function
End If
End If
End If
EnumWinProc = 1
End Function Public Function FindWindowWild(sWild As String, Optional bMatchCase As Boolean = True) As Long
sPattern = sWild
If Not bMatchCase Then sPattern = UCase(sPattern)
EnumWindows AddressOf EnumWinProc, bMatchCase
FindWindowWild = hFind
End Function
=================================================================tmp_hWnd = FindWindowWild("YourAppTitle", False)
If tmp_hWnd > 0 Then Msgbox "App Is Running!"
' task is given to the callback function, which will receive each handle individually.
' Note that if the window has no title bar text, it will not be displayed (for clarity's sake).' *** Place this code in a module. This is the callback function. ***
' This function displays the title bar text of the window identified by hwnd.
Public Function EnumWindowsProc (ByVal hwnd As Long, ByVal lParam As Long) As Long
Dim slength As Long, buffer As String ' title bar text length and buffer
Dim retval As Long ' return value
Static winnum As Integer ' counter keeps track of how many windows have been enumerated winnum = winnum + 1 ' one more window enumerated....
slength = GetWindowTextLength(hwnd) + 1 ' get length of title bar text
If slength > 1 ' if return value refers to non-empty string
buffer = Space(slength) ' make room in the buffer
retval = GetWindowText(hwnd, buffer, slength) ' get title bar text
Debug.Print "Window #"; winnum; " : "; ' display number of enumerated window
Debug.Print Left(buffer, slength - 1) ' display title bar text of enumerated window
End If EnumWindowsProc = 1 ' return value of 1 means continue enumeration
End Function' *** Place this code wherever you want to enumerate the windows. ***
Dim retval As Long ' return value' Use the above callback function to list all of the enumerated windows. Note that lParam is
' set to 0 because we don't need to pass any additional information to the function.
retval = EnumWindows(AddressOf EnumWindowsProc, 0)