Jump to content
Sign in to follow this  
Kidney

help on working with variables using #include <>

Recommended Posts

Kidney

ok so i am trying to get the variable $Focus from the first code to control a While loop in the second code but im not sure how to do so.

;Updated 5/24/2012
#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_UseX64=n
#AutoIt3Wrapper_Res_requestedExecutionLevel=asInvoker
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
#RequireAdmin
#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
;#include-once
;#include <Frozen.au3>
AutoItSetOption("WinTitleMatchMode", 3)

$Form1 = GUICreate("Focus3", 400, 200, @DesktopWidth - 410, @DesktopHeight - 275)
GUISetBkColor(0x0000FF)
GUISetState(@SW_SHOW)
HotKeySet("{F1}", "GetFocus")


$x2 = 0
$y2 = 0

Global $Focus = False
$Exists = 0

Run("Frozen.exe", @ScriptDir)
While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit

    EndSwitch
WEnd

Func Focus()

    While $Focus = True
        $Exists = WinExists("New Text Document - Notepad")
        if $Exists = 0 Then
            Send("e")
            Launch()
        Else
            WinActivate("New Text Document - Notepad")
            Sleep(250)
            ShowFocus()
        EndIf
    WEnd
EndFunc


Func GetFocus()
    $Focus = Not $Focus
    ShowFocus()
    Focus()
EndFunc

Func ShowFocus()
    If $Focus = True Then
        ToolTip("Notepad has focus.", @DesktopWidth/2, @DesktopHeight/2)
    Else
        ToolTip("")
    EndIf
EndFunc

;#include-once
#include <Timers.au3>
#include <ScreenCapture.au3>
#include <Focus3.au3>
$CrashCount = 0

While 1
While $Focus = True
    Sleep(1000)
    If _Timer_GetIdleTime() > 5000 Then
        ToolTip(_Timer_GetIdleTime(), 0, 0);Remove the ";" from the beginning of this line to display the idle timer
    Else
        ToolTip("")
    EndIf
    If _Timer_GetIdleTime() >= 90000 Then
        If WinExists("New Text Document - Notepad") Then
            ;ScreenCapture()
            ;Remove the ";" from the line above to enable the screenshot feature
            WinClose("New Text Document - Notepad")
            Local $file = FileOpen("log.txt", 1)
            $time = Time()
            FileWriteLine($file, $time & "-- Notepad was closed.")
            FileClose($file)
        EndIf
    EndIf
WEnd
WEnd


Func ScreenCapture()
    $Screen = _ScreenCapture_Capture("")
    _ScreenCapture_SaveImage(@ScriptDir & "\Screen Logs\" & "Capture" & $CrashCount & ".jpg", $Screen)
    $CrashCount += 1
EndFunc   ;==>ScreenCapture

Func Time()
    $DAY = @WDAY

    Select
        Case $DAY = 1
            $DAY = "SUN"
        Case $DAY = 2
            $DAY = "MON"
        Case $DAY = 3
            $DAY = "TUE"
        Case $DAY = 4
            $DAY = "WED"
        Case $DAY = 5
            $DAY = "THU"
        Case $DAY = 6
            $DAY = "FRI"
        Case $DAY = 7
            $DAY = "SAT"
    EndSelect

    Return ($DAY & " " & @MDAY & "/" & @MON & "/" & @YEAR & " " & @HOUR & ":" & @MIN & ":" & @SEC & " ")
EndFunc   ;==>Time

whenever i run either code, and i press F1, the first code gets infinitely compiled and the second code i cant see it even work.

i would love to combine both of these scripts together but then that limits me to only one ToolTip (i think).

i guess the main question is, which file do i need to include in and which one do i just leave without the include. i get an error if i put include in both files saying it already declared the variables.

Share this post


Link to post
Share on other sites
martin

Treat each script as totally separate, ie don't include one in the other. Compile the one which is called by the other to make it easy to run.

There are lots of ways to get the value of a variable from another script. Messages is a good and simple way. Here's an example in pseudo code

script A

#include <winapi.au3>
$Ga = GUICreate("justsowecangetmessages");create a window. It won't be shown but without a window we can't receive a message

$msgNum = _WinAPI_RegisterWindowMessage("ytcfhgctf");get a unique message number tied to a particular string
GUIRegisterMsg($msgNum, "funcABC");when we get this message it will call this function

Global $AnyInteger = 9;some variable which we will send to the other program when it asks for it
Run("m2.exe");run the other program
Sleep(2000);wait some time to let m2 staret

While 1
    Sleep(20)
    If Not ProcessExists("m2.exe") Then Exit
WEnd

Func funcABC($hW, $iM, $P, $L)
    $AnyInteger = $AnyInteger + 5; change the value of the variable just to show that this program is doing something every time the message is sent to it
    Return $AnyInteger
EndFunc   ;==>funcABC
[code]

This is the second script. Compile it to m2.exe and make sure that m2.exe is in th esame folder as the first script

[code]
#include <sendmessage.au3>
#include <winapi.au3>
$g1 = GUICreate("example")
$ed = GUICtrlCreateEdit("", 20, 20, 100, 20)
$btn = GUICtrlCreateButton("Get value", 60, 80, 50, 20)
GUISetState()

$msgNum = _WinAPI_RegisterWindowMessage("ytcfhgctf")
$hWndA = WinGetHandle("justsowecangetmessages");find the handle of the window in the first program so we can send a message to it

While 1
    $mg = GUIGetMsg()
    Switch $mg
        Case -3
            Exit
        Case $btn
            $val = _SendMessage($hWndA, $msgNum, 1);send the message and get the value of $AnyInteger. The parameter for wParam isn't used in my example, but could be a way of saying which variable is wanted.
            GUICtrlSetData($ed, $val);show the new value
    EndSwitch
WEnd

If you need any explanation of that then just ask.

Edited by martin

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.

Share this post


Link to post
Share on other sites
Kidney

So does that send the value of a variable to another script or does it change the value of a variable in that script it is sending to? And its kinda confusing which part of the script does the actual message and if I need all those other variables. Can you put some comments on the lines so I can see what you r doin?

Share this post


Link to post
Share on other sites
martin

Comments added.


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.

Share this post


Link to post
Share on other sites
Kidney

Ok ill try this out once I get home. But is there a reason why the funcABC has variables in its params? I don't see them used anywhere else.

Also, I want the first program to "control" the second program. Which program would be doing the asking and which would be the sending in my case?

Share this post


Link to post
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
Sign in to follow this  

×