Jump to content

Can hide main app window, not Print dialog


Recommended Posts

I'm working on a script that uses the open-source Evince PDF viewer to print a file in the background, and sets some options in the Print dialog. I can use @SW_HIDE to hide the main Evince window, but the Print dialog always appears. Is there any way around this?

Here's my first draft of the code that does this job:

Opt("WinTextMatchMode", 2)
$pdffile = "c:\temp\test.pdf"
$pdftitle = "test.pdf"
Run("c:\printwp\evince\bin\evince.exe " & $pdffile,"",@SW_HIDE)
WinWait($pdftitle,"", 2)
If WinExists ($pdftitle) Then
    WinActivate ($pdftitle)
    Send ("^p")
    WinWait ("Print","",4)
    Send ("^{TAB}")
    Send ("{Tab 3}")
    Send ("{SPACE}")
    Send ("!p")
    Sleep (1000)
    WinClose ($pdftitle)
Else
    MsgBox(0,"","Error")
EndIf

I've tried adding this line after the WinWait("Print",...) line:

WinMove ("Print", "", @DesktopWidth+1, @DesktopHeight+1)

But the Print window appears briefly anyway, Is there any other trick I can try?

Obviously, I'm going to replace all the filenames in the final code, and the current code is only for testing.

Thanks for any advice.

Edited by Edward Mendelson
Link to comment
Share on other sites

You could try detecting th ewindow faster and moving it but that might still not do what you want.

Presumably the PDF is displayed in the Evince window when you send ^p?

If you are happy for the Evince window to be displayed but just don't want the print dialog to be shown then maybe something like this would do want you want.

; *** Start added by AutoIt3Wrapper ***
#include <WindowsConstants.au3>
#include <screencapture.au3>
; *** End added by AutoIt3Wrapper ***

#AutoIt3Wrapper_Add_Constants=n
Opt("WinTextMatchMode", 2)
$pdffile = "c:\temp\test.pdf"
$pdftitle = "test.pdf"
Run("c:\printwp\evince\bin\evince.exe " & $pdffile,"",@SW_HIDE)

WinWait($pdftitle, "", 2)
$wsize = WinGetPos($pdftitle)
_ScreenCapture_Capture("screen1.jpg", $wsize[0], $wsize[1],$wsize[0] + $wsize[2],$wsize[1] + $wsize[3], False)


If WinExists($pdftitle) Then
    $fake = GUICreate("fake", $wsize[2], $wsize[3], $wsize[0], $wsize[1], $WS_POPUP)
    $Img = GUICtrlCreatePic("screen1.jpg", 0, 0, $wsize[2], $wsize[3])
    GUISetState()
    WinSetOnTop($fake,"",1)
    sleep(9000)
    exit
    WinActivate($pdftitle)
    Send("^p")
    WinWait("Print", "", 4)
    Send("^{TAB}")
    Send("{Tab 3}")
    Send("{SPACE}")
    Send("!p")
    Sleep(1000)
    GUIDelete($fake)
    WinClose($pdftitle)
    GUIDelete($fake)
Else
    MsgBox(0, "", "Error")
EndIf

It's a fairly awful approach but has been useful before.

Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
Link to comment
Share on other sites

Martin,

Thank you for that. I've experimented with your answer, and - as you say - it certainly works, but I'm not certain I want to mask the screen. By luck, I found a simpler solution, which seems as if it should NOT work, but it does. I simply remove the @WinWait statement, and the Print window never appears:

If WinExists($pdftitle) Then
    WinActivate($pdftitle)
    Send("^p")
    WinMove("Print", "", @DesktopWidth + 1, @DesktopHeight + 1)
    Send("^{TAB}")
    Send("{Tab 3}")
    Send("{SPACE}")
    Send("!p")
    Sleep(1000)
    WinClose($pdftitle)
    Exit    
Else
    MsgBox(0, "", "Error")
EndIf

I didn't think it would be physically possible to move the "Print" window immediately after sending Ctrl-P, but it certainly works, at least on my system, without making the Print window visible at all.

I didn't make clear enough what I was trying to do with this. I don't want any window to appear at all during silent printing. I use @SW_HIDE to hide the main Evince window; I use the code above to keep the Print window from appearing when I print.

This now works, but I've encountered another problem with the script, which I'll write about in a different thread.

Thank you again!

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...