Alternative method to determine whether the printer is offline

Source: Internet
Author: User

'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 ~

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.