Jump to content

NotePad/Dual Monitors


Recommended Posts

I have written an AutoIt program that displays an input screen for the user to enter 4 lines of text and the Zebra printer to which the text is to be printed. The program then opens Notepad, copies the text along with some Zebra ZPL printer formatting commands to Notepad, opens the print dialog window, selects the user specified printer and prints the text. The program work fine on several desktops, but has a problem selecting the user specified printer if the program is executed on a Dell laptop that has dual monitors. I am able to duplicate this on 2 separate laptops and several desktop where I work.

Can anyone maybe tell me why AutoIt can't select the user specified printer and print the text on a laptop with dual monitors? It keeps saying the printer was not selected (ControlListView returns @Error = 1).

Below is a snippet of code that opens the Notepad print dialog and selects the printer. I appreciate any suggestions you might offer.

Run("Notepad.exe")

$hWnd = WinWait("[CLASS:Notepad]")

ControlSetText($hWnd,"","Edit1",$MsgTxt)

Sleep(500)

Send("!FP")

$hWnd = WinWaitActive("Print")

$Ret = ControlFocus($hWnd, "", "[CLASS:SysListView32; INSTANCE:1]")

ControlListView($hWnd, "", "[CLASS:SysListView32; INSTANCE:1]", "ViewChange", "list")

$ItmIdx = ControlListView($hWnd, "", "[CLASS:SysListView32; INSTANCE:1]", "FindItem", $PrtrNm)

IF $ItmIdx = -1 Then

MsgBox(0, $WinTitle, $PrtrNm & " is not installed on this computer.")

$Ret = ControlFocus($hWnd, "", "[CLASS:Button; INSTANCE:13]")

Sleep(500)

Send("{ESC}")

$hWnd = WinWait("[CLASS:Notepad]")

Send("!FX")

Exit

Endif

ControlListView($hWnd, "", "[CLASS:SysListView32; INSTANCE:1]", "Select", $ItmIdx)

IF @Error = 1 Then

MsgBox(0, $WinTitle, $PrtrNm & " was not selected.")

$Ret = ControlFocus($hWnd, "", "[CLASS:Button; INSTANCE:13]")

Sleep(500)

Send("{ESC}")

$hWnd = WinWait("[CLASS:Notepad]")

Send("!FX")

Exit

Endif

$Ret = ControlFocus($hWnd, "", "[CLASS:Button; INSTANCE:13]")

Sleep(500)

Send("!P")

Link to comment
Share on other sites

I can't think of a reason why a dual monitor setup would cause trouble, but you could try the _FilePrint() or _WordDocPrint() functions instead of simulating user interaction.

The _FilePrint function seems to use the default printer, while _WordDocPrint allows you to specify one.

P.s: When posting code you can use [ autoit] and [ /autoit] tags to keep it readable.

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...