'Get the form handle
Public Declare Function GetWindow Lib "user32" (ByVal hwnd As Integer, ByVal wCmd As Integer) As Integer
Public Const GW_HWNDPREV As Short = 3
Public Const GW_HWNDNEXT As Short = 2
Public Const GW_HWNDFIRST As Short = 0
Public Const GW_OWNER As Short = 4
'Get form text
Public Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hwnd As Integer, ByVal lpString As String, ByVal cch As Integer) As Integer
'Find the program with the specified title in the running program list
Public Function FindRunningProgram (ByVal PrgName As String, Optional ByVal ExtString As String = "") As Integer
Dim RenHWND As Integer
Dim RetValue As Integer
Dim WinText As New VB. Compatibility. VB6.FixedLengthString (256)
Dim fgFindRunningProgram As Integer
'Get the first Hwnd
RenHWND = GetWindow (Form7.Handle. ToInt32, GW_HWNDFIRST)
Do
'Get the title
RetValue = GetWindowText (RenHWND, WinText. Value, 256)
'If successful
If RetValue <> 0 Then
'Determine whether the program is to be found
If ExtString = "" Then
If InStr (1, WinText. Value, PrgName)> 0 Then
FgFindRunningProgram = 1
Exit Do
End If
Else
If InStr (1, WinText. Value, PrgName)> 0 AndAlso InStr (1, WinText. Value, ExtString)> 0 Then
FgFindRunningProgram = 1
Exit Do
End If
End If
End If
'Find the next
RenHWND = GetWindow (RenHWND, GW_HWNDNEXT)
Loop Until RenHWND = 0
Return fgFindRunningProgram
End Function
Public Function IsOffline (ByVal PrinterName As String) As Integer
If FindRunningProgram (PrinterName)> 0 Then
If FindRunningProgram (PrinterName, "use printer offline")> 0 Then
Return 1
Else
Return 0
End If
Else
Return-1
End If
End Function
Oh, isn't it a hooligans ~