作者chinoyan (chino)
看板Visual_Basic
标题Re: [VB6 ] 如何侦测某一个桯式(如小画家)已经结束?
时间Thu Oct 6 02:07:18 2011
※ 引述《kandrew (蓝天白云~~)》之铭言:
: Hi chino,谢谢您提供此方法!!
: 我利用此方法,确实可以侦测到特定的程式是否结束,
: 但如果标题会改变的程式,就比较难侦测到了,
: 例如要侦测小画家是否结束,当你开新档时小画家的标题为"未命名-小画家"
: 然後再开另一个图档则标题则变为"xxxx-小画家",这样就会判断失败了。
: 是否还有别的函数可以判断部分标题名称的函式,例如只判断"小画家"
: 如果如此,这样就可以正确的侦测出程式是否结束了。
: ※ 引述《chinoyan (chino)》之铭言:
: : 'API宣告
: : Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal
: : lpClassName As String, ByVal lpWindowName As String) As Long
: : ' 视窗的class ,"XXX"视窗标题,不知class填vbNullString即可
: : ' 传回值为window hwnd, 不存在传回 0
: : If FindWindow(vbNullString, "XXX") <> 0 Then
: : End If
'方法一
Dim Pid as long
pid = GetPsPid("小画家.exe")
If pid <> 0 Then
End If
Option Explicit ' IN 模组
Private Declare Function CreateToolhelp32Snapshot Lib "kernel32" (ByVal
dwFlags As Long, ByVal th32ProcessID As Long) As Long
Private Declare Function Process32First Lib "kernel32" (ByVal hSnapShot As
Long, lppe As PROCESSENTRY32) As Long
Private Declare Function Process32Next Lib "kernel32" (ByVal hSnapShot As
Long, lppe As PROCESSENTRY32) As Long
Public Declare Function TerminateProcess Lib "kernel32" (ByVal hProcess As
Long, ByVal uExitCode As Long) As Long
Private Declare Function OpenProcess Lib "kernel32" (ByVal dwDesiredAccess As
Long, ByVal bInheritHandle As Long, ByVal dwProcessId As Long) As Long
Private Declare Sub CloseHandle Lib "kernel32" (ByVal hPass As Long)
Private Const TH32CS_SNAPPROCESS = &H2&
Private Type PROCESSENTRY32
dwSize As Long
cntUsage As Long
th32ProcessID As Long
th32DefaultHeapID As Long
th32ModuleID As Long
cntThreads As Long
th32ParentProcessID As Long
pcPriClassBase As Long
dwFlags As Long
szExeFile As String * 260
End Type
Const PROCESS_TERMINATE = 1
Function GetPsPid(sProcess As String) As Long
Dim lSnapShot As Long
Dim lNextProcess As Long
Dim tPE As PROCESSENTRY32
lSnapShot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0&)
If lSnapShot <> -1 Then
tPE.dwSize = Len(tPE)
lNextProcess = Process32First(lSnapShot, tPE)
Do While lNextProcess
If LCase$(sProcess) = LCase$(Left(tPE.szExeFile, InStr(1,
tPE.szExeFile, Chr(0)) - 1)) Then
Dim lProcess As Long
Dim lExitCode As Long
GetPsPid = tPE.th32ProcessID
CloseHandle lProcess
End If
lNextProcess = Process32Next(lSnapShot, tPE)
Loop
CloseHandle (lSnapShot)
End If
End Function
=============================================================================
'方法二
EnumWindows AddressOf EnumWindowsProc, 0& '引用
'in 模组
Public Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA"
(ByVal hwnd As Long, ByVal lpString As String, ByVal cch As Long) As Long
Public Declare Function EnumWindows Lib "user32" (ByVal lpEnumFunc As Long,
ByVal lParam As Long) As Long
Function EnumWindowsProc(ByVal hwnd As Long, ByVal lParam As Long) As Boolean
On Error Resume Next
Dim S As String
S = String(40, 0)
Call GetWindowText(hwnd, S, 40)
S = Left(S, InStr(S, Chr(0)) - 1)
If Len(S) > 0 Then
If InStr(S, "小画家") > 0 Then '
End If
End If
EnumWindowsProc = True ' 表示继续列举 hWnd
End Function
--
████ █ ★ ████ █ █ █
█ █ █ █ █ █ 超 级 热 烈 欢 迎
█ ████ █ █ █ ████ █
█ █ █ █ ███★ █ █ 欢迎到嘉义版!
★███ █ █ █ █ █ █ █
讯驰电脑-路径 →
嘉义市林森西路496号 →
(05)2244-526 →
顺发斜对面
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 114.33.214.160
1F:推 JacobTai:就是想推原po的热心 10/06 09:38
2F:推 kandrew:我利用方法二,成功侦测出特定程式是否结束。感谢C大!!! 10/06 17:27
3F:推 MacPerson:太热心了 ~~~ 推 10/06 21:32
4F:→ MacPerson:有code128的经验谈分享吗 @@ 10/06 21:33
5F:→ chinoyan:CODE 128 是什麽?? 10/06 21:36
6F:→ MacPerson:code 128 条码字型 最近光搞这就饱了..... 10/06 21:42
7F:→ chinoyan:RS232 没玩过.SORRY 10/07 01:40