Jump to content

while looping do something


chie
 Share

Recommended Posts

I dont know what should I search for(keywords I tried with ContinueCase & switch...but it was total miss...), but hire is the explanation:

code is inside a loop(sending keys)

is it possible to maximize it for example while its inside the loop?

Sample code:

#include <GuiConstants.au3>
Opt("WinTitleMatchMode", 2) ; use any part of the window name
Opt("TrayMenuMode",1)   ; Default tray menu items (Script Paused/Exit) will not be shown
;~ Gui Mainwindow
;~ ---------------------------------------------------------------------------------------------------------
$mainwindow = GUICreate("sample", 270, 195)
$OK = GUICtrlCreateButton("Start", 145, 55, 45, 23)   ;Button OK (left, top , width , height )
GUISetState(@SW_SHOW, $mainwindow)
;~ Tray MENU
;~ ---------------------------------------------------------------------------------------------------------
$Trayexit            = TrayCreateItem("Exit")
TraySetState(@SW_HIDE)
Run("Notepad.exe")

While 1
    $msg = GUIGetMsg()
    $msg1 = TrayGetMsg()
 Select
    Case $msg1 = $Trayexit
        exit
;~ ------------------------------------------------------
    case $msg = $OK
        GUISetState(@SW_HIDE,$mainwindow)
        While 1
            Sleep(1000)
            ControlSend("Untitled", "", "Edit1", "test ")
        WEnd
EndSelect
WEnd
Edited by chie
Link to comment
Share on other sites

if you do a $msg1 = Traygetmsg() and do an if $msg1 = $menu then blah im pretty sure it will work

This is what i tried so far(& more but i post only this to save space) & no progress..Am I missing something?..
#include <GuiConstants.au3>
Opt("WinTitleMatchMode", 2) ; use any part of the window name
Opt("TrayMenuMode",1)   ; Default tray menu items (Script Paused/Exit) will not be shown
Opt("GUIOnEventMode", 1)  ; Change to OnEvent mode

;~ Gui Mainwindow
;~ ---------------------------------------------------------------------------------------------------------
$mainwindow = GUICreate("sample", 270, 195)
$OK = GUICtrlCreateButton("Start", 145, 55, 45, 23)   ;Button OK (left, top , width , height )
GUISetState(@SW_SHOW, $mainwindow)

;~ Tray MENU
;~ ---------------------------------------------------------------------------------------------------------
$Trayexit            = TrayCreateItem("Exit")
TraySetState(@SW_HIDE)
Run("Notepad.exe")

GUICtrlSetOnEvent($Trayexit, "_Trayexit") 
GUICtrlSetOnEvent($OK, "_OK")  

While 1
  Sleep(10)
WEnd

Func _OK()   
    While 1
        Sleep(1000)
        ControlSend("Untitled", "", "Edit1", "test ")
    WEnd
EndFunc 

Func _Trayexit()   
  Exit
EndFuncoÝ÷ Ù«­¢+ØÍÀÌØíµÍôÀÌØí=,(]¡¥±Ä(M±À ÄÀÀÀ¤(
½¹Ñɽ±M¹ ÅÕ½ÐíU¹Ñ¥Ñ±ÅÕ½Ðì°ÅÕ½ÐìÅÕ½Ðì°ÅÕ½Ðí¥ÐÄÅÕ½Ðì°ÅÕ½ÐíÑÍÐÅÕ½Ðì¤($$%¥ÀÌØíµÍÄôÀÌØíQÉåá¥ÐÑ¡¸á¥Ð(]¹
Edited by chie
Link to comment
Share on other sites

I'm still not following what you are attempting. I see you want to make a GUI and have some controls in it. What I'm missing is just what you want the controls to do. You don't need more than one loop (while statement) if you are using GUIOnEventMode. Each control in the GUI would only need to be set so if clicked, something would happen. On your function _OK(), you have it so when ran, it loops with no way of getting out of it. ;) . That isn't good. Could you post your script, or if you rather, just PM me with the script and I'll see what I can do to help fix it.

Link to comment
Share on other sites

I'm still not following what you are attempting. I see you want to make a GUI and have some controls in it.

It would be better if I wont post my code because its around over 1000 lines long, I was concidering rewriting it....

I still need to experiment more, maybe I know how to do it, an idea came to me & i will try it out tomorrow, bed time today ;)

But Can you tell me why cant I $GUI_EVENT_MINIMIZE the Mainwindow while the code is looping ?

I forgot, How can I post my code so it wont take mutch space? (so the code will have scroll bar?)

Sample:

1. Run the code

2. press Start Button (The code will start looping)

4. Now try minimize the GUI (The code must @SW_HIDE the Mainwindow). But this is not happening...

#include <GuiConstants.au3>
Opt("WinTitleMatchMode", 2) ; use any part of the window name
Opt("TrayMenuMode",1)   ; Default tray menu items (Script Paused/Exit) will not be shown
Opt("GUIOnEventMode", 1)  ; Change to OnEvent mode
Opt("TrayOnEventMode",1)

;~ Tray MENU
;~ ---------------------------------------------------------------------------------------------------------
$maximize = TrayCreateItem("Maximize")
TrayItemSetOnEvent(-1, "_Maximize")
$minimize = TrayCreateItem("Minimize")
TrayItemSetOnEvent(-1, "_minimize")
TraySetState(@SW_HIDE)

;~ Gui Mainwindow
;~ ---------------------------------------------------------------------------------------------------------
$mainwindow = GUICreate("sample", 270, 195)
GUISetOnEvent($GUI_EVENT_MINIMIZE, "_minimize")
GUISetOnEvent($GUI_EVENT_CLOSE, "_close")

$OK = GUICtrlCreateButton("Start", 145, 55, 45, 23)   ;Button OK (left, top , width , height )
GUICtrlSetOnEvent(-1, "_OK")
GUISetState(@SW_SHOW, $mainwindow)

While 1
  Sleep(10)
WEnd

Func _OK()  
    Run("Notepad.exe")  
    While 1
        Sleep(1000)
        ControlSend("Untitled", "", "Edit1", "test ")
    WEnd
EndFunc 

Func _minimize()   
    GUISetState(@SW_HIDE, $mainwindow)
EndFunc

Func _Maximize()   
    GUISetState(@SW_SHOW, $mainwindow)
    GUISetState(@SW_RESTORE, $mainwindow)
EndFunc

Func _close()   
    Exit
EndFunc
Link to comment
Share on other sites

OnEvent mode calls a function. One single event is calling a function and for the function to return, so the script can be ready to perform the next event.

When you click the start button, the script calls the _OK function. The script has an endless loop in the function so it never returns. The script is trapped with the function (and trapped within that event).

Link to comment
Share on other sites

OnEvent mode calls a function. One single event is calling a function and for the function to return, so the script can be ready to perform the next event.

When you click the start button, the script calls the _OK function. The script has an endless loop in the function so it never returns. The script is trapped with the function (and trapped within that event).

I understand this, yet while it is trapped we can call other function at the same time using TrayItemSetOnEvent & it works, this way you can maximize & minimize the GUI as you saw in the previous example. but if GUISetOnEvent is used for some reason nor minimizing(nor any other on event action that is performed on main GUI) is not working. & this is what im trying to do: call a function & let it loop something(lets say forever or until _ispressed....) & at the same time call another function & let it loop something else for example, so now we have 2 functons that are looping somethig & yet we can still call any other function to perform any other action(show other GUIs, save info etc...)

So far I ve been making codes for 1 timeline(do only 1 thing at the time), Now I would like to create multiple timelines

I hope this was more informative about what im trying to do.

Edited by chie
Link to comment
Share on other sites

how many times do you need to do the control send to the notepad application? If just once, then do this

I was experimenting with addlib...thing today & was unable to make it work...but let me explane this differently then.

Run this code:

press START button

now press:

Button2 or Fail->Exit (How can you make it to show the messagebox if you press button2 or Fail->Exit ? )

yes first you must press Start.

Note! if you ckklick the tray meny show MsgBox after yo upressed start, the messagebox will be shown.

#include <GuiConstants.au3>
Opt("WinTitleMatchMode", 2) ; use any part of the window name
Opt("TrayMenuMode",1)   ; Default tray menu items (Script Paused/Exit) will not be shown
Opt("GUIOnEventMode", 1)  ; Change to OnEvent mode
Opt("TrayOnEventMode",1)

;~ Gui Mainwindow
;~ ---------------------------------------------------------------------------------------------------------
$mainwindow = GUICreate("sample", 270, 195)
GUISetOnEvent($GUI_EVENT_MINIMIZE, "_minimize")
GUISetOnEvent($GUI_EVENT_CLOSE, "_close")

$Button1 = GUICtrlCreateButton("Start", 145, 55, 45, 23)   ;start looping
GUICtrlSetOnEvent(-1, "_OK")
$Button2 = GUICtrlCreateButton("Button2", 195, 55, 45, 23)   ;show messagebox
GUICtrlSetOnEvent(-1, "_Button2")
GUISetState(@SW_SHOW, $mainwindow)

;~ File Menu START
;~ ---------------------------------------------------------------------------------------------------------
$filemenu = GUICtrlCreateMenu ("&File")
$exititem = GUICtrlCreateMenuitem ("Exit",$filemenu)
GUICtrlSetOnEvent(-1, "_Button2")
;~ Tray MENU
;~ ---------------------------------------------------------------------------------------------------------
    TrayCreateItem("Show MMesgbox")
TrayItemSetOnEvent(-1, "_Button2")
    TrayCreateItem("Maximize")
TrayItemSetOnEvent(-1, "_Maximize")
    TrayCreateItem("EXIT")
TrayItemSetOnEvent(-1, "_close")

TraySetState(@SW_HIDE)

Func _OK()  
    Run("Notepad.exe") 
        
    While 1
        Sleep(1000)
        ControlSend("Untitled", "", "Edit1", "test ")
    WEnd
EndFunc 


Func _Button2()   
    MsgBox(0, "", "Works")
EndFunc

Func _minimize()   
    GUISetState(@SW_HIDE, $mainwindow)
EndFunc

Func _Maximize()   
    GUISetState(@SW_SHOW, $mainwindow)
    GUISetState(@SW_RESTORE, $mainwindow)
EndFunc

Func _close()   
    Exit
EndFunc

While 1
  Sleep(20)
WEnd
Link to comment
Share on other sites

Your still doing the loop with no way out of it. Try this:

#include <GuiConstants.au3>
Opt("WinTitleMatchMode", 2) ; use any part of the window name
Opt("TrayMenuMode",1)   ; Default tray menu items (Script Paused/Exit) will not be shown
Opt("TrayOnEventMode",1)

;~ Gui Mainwindow
;~ ---------------------------------------------------------------------------------------------------------
$mainwindow = GUICreate("sample", 270, 195)
$Button1 = GUICtrlCreateButton("Start", 145, 55, 45, 23)   ;start looping
$Button2 = GUICtrlCreateButton("Button2", 195, 55, 45, 23)   ;show messagebox
GUISetState(@SW_SHOW, $mainwindow)

;~ File Menu START
;~ ---------------------------------------------------------------------------------------------------------
$filemenu = GUICtrlCreateMenu ("&File")
$exititem = GUICtrlCreateMenuitem ("Exit",$filemenu)
;~ Tray MENU
;~ ---------------------------------------------------------------------------------------------------------
    TrayCreateItem("Show MMesgbox")
TrayItemSetOnEvent(-1, "_Button2")
    TrayCreateItem("Maximize")
TrayItemSetOnEvent(-1, "_Maximize")
    TrayCreateItem("EXIT")
TrayItemSetOnEvent(-1, "_close")

TraySetState(@SW_HIDE)

Func _Button2()   
    MsgBox(0, "", "Works")
EndFunc

Func _Maximize()   
    GUISetState(@SW_SHOW, $mainwindow)
    GUISetState(@SW_RESTORE, $mainwindow)
EndFunc

Func _close()   
    Exit
EndFunc

While 1
    $msg = GuiGetMsg()
  Select
    case $msg = $Button1
        Run("Notepad.exe")
            do 
                sleep(1000)
                ControlSend("Untitled", "", "Edit1", "test ")
            until WinActivate("Untitled", "") = 0
        case $msg = $Button2    
            MsgBox(0, "", "Works")
        case $msg = $exititem
            _close()
        
    EndSelect       
WEnd
Link to comment
Share on other sites

Your still doing the loop with no way out of it. Try this:

In your example still nothing happens if you press $Button2 or $GUI_EVENT_CLOSE or Fail->Exit while Control sending

The script must be kept working in the background & if you maximize it (it must continue controlsending) & while doing so & it is maximized & you press button2 a message box must appear.(yes it will pause script but imagine GUI2 instead of a messagebox.....well its not working anyway....so the msgbox will do atm.)

I continued experimenting with AdlibEnable & it almost works...well I can post an example the way it should work(But the mouse coursor should not blink the way it does atm....) Also as mutch as I figured out AdlibEnable can be used only Once per code & AdlibDisable() will close any AdlibEnable & this means that AdlibEnable cant be used to loop more that 1 function...

Conclusion: this solution is no good ;)

SCROLL In the end Where many commented lines are....this is the spot I changed else is same.

CODE

#include <GuiConstants.au3>
Opt("WinTitleMatchMode", 2) ; use any part of the window name
Opt("TrayMenuMode",1)   ; Default tray menu items (Script Paused/Exit) will not be shown
Opt("TrayOnEventMode",1)

;~ Gui Mainwindow
;~ ---------------------------------------------------------------------------------------------------------
$mainwindow = GUICreate("sample", 270, 195)
$Button1 = GUICtrlCreateButton("Start", 145, 55, 45, 23)   ;start looping
$Button2 = GUICtrlCreateButton("Button2", 195, 55, 45, 23)   ;show messagebox
GUISetState(@SW_SHOW, $mainwindow)

;~ File Menu START
;~ ---------------------------------------------------------------------------------------------------------
$filemenu = GUICtrlCreateMenu ("&File")
$exititem = GUICtrlCreateMenuitem ("Exit",$filemenu)
;~ Tray MENU
;~ ---------------------------------------------------------------------------------------------------------
    TrayCreateItem("Show MMesgbox")
TrayItemSetOnEvent(-1, "_Button2")
    TrayCreateItem("Maximize")
TrayItemSetOnEvent(-1, "_Maximize")
    TrayCreateItem("EXIT")
TrayItemSetOnEvent(-1, "_close")
TraySetState(@SW_HIDE)

Func _Button2()   
    MsgBox(0, "", "Works")
EndFunc
;~ ------------------------------------------------------
Func _Maximize()   
    GUISetState(@SW_SHOW, $mainwindow)
    GUISetState(@SW_RESTORE, $mainwindow)
EndFunc
;~ ------------------------------------------------------
Func _close()   
    Exit
EndFunc
;~ ------------------------------------------------------
While 1
    $msg = GuiGetMsg()
  Select
        case $msg = $Button2    
            MsgBox(0, "", "Works")
        case $msg = $exititem or $msg = $GUI_EVENT_CLOSE
            Exit
;~ ------------------------------------------------------
;~ ------------------------------------------------------
;~ ------------------------------------------------------
;~ ------------------------------------------------------
;~ ------------------------------------------------------
        case $msg = $Button1
            AdlibEnable("_loop", 500)
    EndSelect      
WEnd
Func _loop()   
   ControlSend("Untitled", "", "Edit1", "test ")
EndFunc
;~ ------------------------------------------------------
;~ ------------------------------------------------------
;~ ------------------------------------------------------
;~ ------------------------------------------------------
;~ ------------------------------------------------------
Edited by chie
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...