Solved

Is Printing Finished?

Posted on 1999-01-07
10
297 Views
Last Modified: 2012-06-21
I am looking for some code to determine if my computer has finished printing, not necessarily if the the paper is out of the printer, but when the computer has done "processing" it. I am not sure if I worded this correctly. Thanks.
0
Comment
Question by:newyorker
  • 4
  • 3
  • 3
10 Comments
 
LVL 12

Expert Comment

by:mark2150
ID: 1454634
Umm, this is fairly well hidden (I think there's a status item you can check) but there is really no need for this info as printing is handled by the OS. It's all going to a queue and then being shipped out to the physical device. Depending on the context it can be multiply buffered. In a LAN your app prints to a spooler that forwards it to the LAN spooler that sends it to the print server spooler that sends it to the printer memory that finally prints it. At what point in this chain do you decide that "processing" is completed? Or why do you care as long as it works?

If you're giving a "Printing" progress bar, don't worry about the OS/LAN queues, simply indicate how far your app is doing, the OS may queue the file indefinately and you don't want your app to be blocked on the OS queuing the file. This also causes confusion when printing to a file and/or Adobe Acrobat.

M

0
 

Author Comment

by:newyorker
ID: 1454635
I am printing from a third party application.  This application produces  one of those little pop up screens(the ones that specify printer name, document being printed, etc.) every time it prints, like most apps do.  My app must cover this application when it prints.  I am using the SetWindowPos(TOPMOST) function to do this.  If I don't my application falls behind the third party application window.  I want to know when I am able to use the SetWindowPos to stop my app from being the TOPMOST window.
0
 

Author Comment

by:newyorker
ID: 1454636
I am printing from a third party application.  This application produces  one of those little pop up screens(the ones that specify printer name, document being printed, etc.) every time it prints, like most apps do.  My app must cover this application when it prints.  I am using the SetWindowPos(TOPMOST) function to do this.  If I don't my application falls behind the third party application window when it prints.  I want to know when I am able to use the SetWindowPos to stop my app from being the TOPMOST window.
0
 
LVL 12

Expert Comment

by:mark2150
ID: 1454637
Ok, then you don't really care about the *printer* status, you want to know the status of the 3rd party window - a much different question! There is a API call that will give you the state of their window - I don't have it at my fingertips, but there *IS* one (I saw it in Appleman's book). Anyway, you watch the state of that window and when it drops, you drop yours too.

M

0
 

Author Comment

by:newyorker
ID: 1454638
mark2150,
That last idea you stated about checking the state of that window is will solve my problemn.  Thanks.  Answer the question again so I can give you the points you deserve.
0
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 

Expert Comment

by:JimmieToo
ID: 1454639
Hello newyorker,

The following code can be modified to do many useful things.  Start a new project with one form and one module so you can play with this.  Add a command button, a label and a list.

In your app, run LoadTaskList at the appropriate time.

The LoadTaskList sub is set up to find the window of interest, in your case, a window with the caption "Printing...".  The third party software might possibly modify this so you need to be aware of the required caption.  Once it finds it, then the WaitUntilDone routine runs until the window disappears.

There are other ways to tackle this but this approach offers many other possible functions.

Good luck.

Jim


FORM CODE
***********************************************************************

Option Explicit

Dim CurrWnd As Long
Dim Length As Long
Dim TaskName As String
'Dim Parent As Long

Dim PrintWindowHandle As Long

Private Sub Command1_Click()

    LoadTaskList
    If PrintWindowHandle <> 0 Then
        WaitUntilDone
    End If
   
End Sub

Private Sub LoadTaskList()
   
    CurrWnd = GetWindow(Me.hwnd, GW_HWNDFIRST)
   
    While CurrWnd <> 0
'        Parent = GetParent(CurrWnd)
        Length = GetWindowTextLength(CurrWnd)
        TaskName = Space$(Length + 1)
        Length = GetWindowText(CurrWnd, TaskName, Length + 1)
        TaskName = Left$(TaskName, Len(TaskName) - 1)
        'get the window handle for the print window (or whatever)
        If Length > 0 Then
            If TaskName = "Printing..." Then    'you must know the correct caption, this is the typical default
                PrintWindowHandle = CurrWnd
                Exit Sub
            End If
        End If
        'if you want to show the tasks in the list for some other application
        'then comment out the above lines and use these
'        If Length > 0 Then
'           List1.AddItem TaskName
'        End If
       
        CurrWnd = GetWindow(CurrWnd, GW_HWNDNEXT)
        DoEvents
    Wend
End Sub


Private Sub WaitUntilDone()

Dim PrintWindowGone As Boolean

    Do Until PrintWindowGone
   
        Length = GetWindowTextLength(PrintWindowHandle)
        If Length = 0 Then
            PrintWindowGone = True
            Label1.Caption = "Print window is gone"
        End If
        DoEvents
    Loop

End Sub


END OF FORM CODE

*********************************************************************
*********************************************************************

MODULE CODE
*********************************************************************

Option Explicit

Public Declare Function GetWindow Lib "user32" (ByVal hwnd As Long, ByVal wCmd As Long) As Long
Public Declare Function GetParent Lib "user32" (ByVal hwnd As Long) As Long
Public Declare Function GetWindowTextLength Lib "user32" Alias "GetWindowTextLengthA" (ByVal hwnd As Long) As Long
Public Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String, ByVal cch As Long) As Long
Public Const GW_HWNDFIRST = 0
Public Const GW_HWNDNEXT = 2


END OF MODULE CODE
*********************************************************************
*********************************************************************


0
 
LVL 12

Expert Comment

by:mark2150
ID: 1454640
Be glad to, but you've gotta reject JimmieToo's answer first! (grin)

M

0
 

Expert Comment

by:JimmieToo
ID: 1454641
I figure first come, first served (grinToo)
0
 

Expert Comment

by:JimmieToo
ID: 1454642
What was the basis for rejection, i.e., why does this not address your requirement?

Jim
0
 
LVL 12

Accepted Solution

by:
mark2150 earned 100 total points
ID: 1454643
Thanx for the points!

M

0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

706 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now