Jump to content

Run Gui multiple times


jfcby
 Share

Recommended Posts

Hello,

I was wondering after the GUI has started and a button is clicked, how do you get the GUI to stop and run each time you click the button?

I'm creating a program that will print the active window but I can't figure out how after the active window is printed to stop the GUI and then when I click the print button again it prints the active window.

#include <GUIConstantsEx.au3>
#Include <WinAPI.au3>

Dim $GUI, $AppTitle 
Dim $fBold, $fArial 
Dim $btn_Print, $msg 

$AppTitle = "DWG TrueView Print"

 $GUI = GUICreate($AppTitle, 250, 100, 675, 50); will create a dialog box that when displayed is centered  
 HotKeySet("{ESC}", "_Quit") 
 ;Opt("GUICoordMode", 2)
 
 ;Main Label Control
 ;Main Label Title
  $fBold = "Arial Bold"
  GUISetFont(9, 400, 4, $fBold)  
  GUICtrlCreateLabel("Print DWG TrueView Active window.", 20, 10, 300, 15)
  
 ;Print
  $fArial = "Arial"
  GUISetFont(9, 400, 1, $fArial)
 ;GuiCtrlCreateGroup("STEP 1", 2, 115, 345, 30)  
  $btn_Print = GUICtrlCreateButton("Print", 150, 50, 75, 25);Left, Down, Width, Height
  
  GUISetState()  ; will display an dialog box with 3 button
  
 ; Run the GUI until the dialog is closed
  Opt('MustDeclareVars', 1)
  
  WinSetOnTop($AppTitle, "", 1);window stays on top
  
  While 1
    $msg = GUIGetMsg()  
  Select
   Case $msg = $GUI_EVENT_CLOSE
    ExitLoop
   Case $msg = $btn_Print       
    ;Print Active Page
        Send("{ALT}" & "{DOWN 5}")
        Sleep(2000)
        Send("{ENTER 2}");File > Plot(Print)
        Sleep(2000)
        Send("+{TAB 4}" & "{DOWN}" & "{ENTER}");Page Setup > Previous Plot(Print)       
    EndSelect       
  WEnd

Func _Quit()
     Exit
EndFunc

Thank you for your help,

jfcby

Determined -- Devoted -- Delivered Make your mind up -- to seriously apply yourself -- accomplishing the desired results. **** A soft answer turneth away wrath: but grievous words stir up anger. Proverbs 15:1 KJB ****

Link to comment
Share on other sites

I don't really understand your question so this might not be a good answer.

I don't see how your scipt will work so maybe that is your problem.

Maybe instead of setting your script on top you should just activate it after printing.

#include <GUIConstantsEx.au3>
#Include <WinAPI.au3>

Dim $GUI, $AppTitle
Dim $fBold, $fArial
Dim $btn_Print, $msg

$AppTitle = "DWG TrueView Print"

$GUI = GUICreate($AppTitle, 250, 100, 675, 50); will create a dialog box that when displayed is centered  
HotKeySet("{ESC}", "_Quit")
;Opt("GUICoordMode", 2)

;Main Label Control
;Main Label Title
  $fBold = "Arial Bold"
  GUISetFont(9, 400, 4, $fBold)  
  GUICtrlCreateLabel("Print DWG TrueView Active window.", 20, 10, 300, 15)
  
;Print
  $fArial = "Arial"
  GUISetFont(9, 400, 1, $fArial)
;GuiCtrlCreateGroup("STEP 1", 2, 115, 345, 30)  
  $btn_Print = GUICtrlCreateButton("Print", 150, 50, 75, 25);Left, Down, Width, Height
  
  GUISetState() ; will display an dialog box with 3 button
  
; Run the GUI until the dialog is closed
  Opt('MustDeclareVars', 1)
  
 ;WinSetOnTop($AppTitle, "", 1);window stays on top
  
  While 1
    $msg = GUIGetMsg()  
  Select
   Case $msg = $GUI_EVENT_CLOSE
    ExitLoop
   Case $msg = $btn_Print       
   ;Print Active Page
        WInActivate("DWG APP Title");whatever the title is of the app that does the printing
        sleep(200);might not be needed but need to make sure it is reday for the Sends
        Send("{ALT}" & "{DOWN 5}")
        Sleep(2000)
        Send("{ENTER 2}");File > Plot(Print)
        Sleep(2000)
        Send("+{TAB 4}" & "{DOWN}" & "{ENTER}");Page Setup > Previous Plot(Print) 
        WInWait("Sometitle which tells you printing has started",$maxWaitTime);might not be needed
        WInActivate($AppTitle);
    EndSelect       
  WEnd

Func _Quit()
     Exit
EndFunc
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

Hello,

I was wondering after the GUI has started and a button is clicked, how do you get the GUI to stop and run each time you click the button?

I'm creating a program that will print the active window but I can't figure out how after the active window is printed to stop the GUI and then when I click the print button again it prints the active window.

#include <GUIConstantsEx.au3>
#Include <WinAPI.au3>

Dim $GUI, $AppTitle 
Dim $fBold, $fArial 
Dim $btn_Print, $msg 

$AppTitle = "DWG TrueView Print"

 $GUI = GUICreate($AppTitle, 250, 100, 675, 50); will create a dialog box that when displayed is centered  
 HotKeySet("{ESC}", "_Quit") 
;Opt("GUICoordMode", 2)
 
;Main Label Control
;Main Label Title
  $fBold = "Arial Bold"
  GUISetFont(9, 400, 4, $fBold)  
  GUICtrlCreateLabel("Print DWG TrueView Active window.", 20, 10, 300, 15)
  
;Print
  $fArial = "Arial"
  GUISetFont(9, 400, 1, $fArial)
;GuiCtrlCreateGroup("STEP 1", 2, 115, 345, 30)  
  $btn_Print = GUICtrlCreateButton("Print", 150, 50, 75, 25);Left, Down, Width, Height
  
  GUISetState() ; will display an dialog box with 3 button
  
; Run the GUI until the dialog is closed
  Opt('MustDeclareVars', 1)
  
  WinSetOnTop($AppTitle, "", 1);window stays on top
  
  While 1
    $msg = GUIGetMsg()  
  Select
   Case $msg = $GUI_EVENT_CLOSE
    ExitLoop
   Case $msg = $btn_Print       
;Print Active Page
        Send("{ALT}" & "{DOWN 5}")
        Sleep(2000)
        Send("{ENTER 2}");File > Plot(Print)
        Sleep(2000)
        Send("+{TAB 4}" & "{DOWN}" & "{ENTER}");Page Setup > Previous Plot(Print)       
    EndSelect       
  WEnd

Func _Quit()
     Exit
EndFunc

Thank you for your help,

jfcby

Problem solved with the following code:

#include <GUIConstantsEx.au3>
#Include <WinAPI.au3>

Opt("GUIOnEventMode", 1) ; Change to OnEvent mode
$AppTitle = "DWG TrueView Print"
$mainwindow = GUICreate($AppTitle, 250, 100, 675, 50)
HotKeySet("{ESC}", "_Quit")
GUISetOnEvent($GUI_EVENT_CLOSE, "_Quit");"CLOSEClicked")
GUICtrlCreateLabel("Print DWG TrueView Active window.", 30, 10)
$printbutton = GUICtrlCreateButton("Print", 90, 50, 75, 25)
GUICtrlSetOnEvent($printbutton, "PrintButton")
GUISetState(@SW_SHOW)
WinSetOnTop($AppTitle, "", 1);window stays on top

While 1
  Sleep(1000) ; Idle around
WEnd

Func PrintButton()  
    WinActivate("DWG TrueView", "z:\")
    Sleep(2000)
    
;Print Active Page
    Send("{ALT}" & "{DOWN 5}" & "{ENTER}")
    Sleep(2000)
    Send("{ENTER}");File > Plot(Print)
    Sleep(2000)
    Send("+{TAB 4}" & "{DOWN}" & "{ENTER}");Page Setup > Previous Plot(Print)
    
EndFunc

Func _Quit();CLOSEClicked()
 ;Note: at this point @GUI_CTRLID would equal $GUI_EVENT_CLOSE, 
 ;and @GUI_WINHANDLE would equal $mainwindow 
  MsgBox(0, "GUI Event", "You clicked CLOSE! Exiting...")
  Exit
EndFunc

Thank you for your help,

jfcby

Determined -- Devoted -- Delivered Make your mind up -- to seriously apply yourself -- accomplishing the desired results. **** A soft answer turneth away wrath: but grievous words stir up anger. Proverbs 15:1 KJB ****

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