Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Is Printing Finished?

Posted on 1999-01-07
10
Medium Priority
?
308 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
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
 

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 400 total points
ID: 1454643
Thanx for the points!

M

0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses

636 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