Jump to content
Sign in to follow this  
rliiack

Constantly updating variable

Recommended Posts

rliiack

I am trying to continue update mouse position and icon position until Quit on the GUI menu is pressed. Here is my code:

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <SliderConstants.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <GuiListView.au3>
#include <Array.au3>
Global $finalDistance, $msg, $desktop, $iconNumber, $x, $y, $pos, $iconPos

$SI = GUICreate("Smart Icons", 625, 445, 192, 124,$WS_MINIMIZEBOX)
GUISetFont(20, 800, 0, "Australian Sunrise")
$Group1 = GUICtrlCreateGroup("Sound Options", 168, 32, 297, 105)
$Slider1 = GUICtrlCreateSlider(184, 80, 193, 49)
$Checkbox1 = GUICtrlCreateCheckbox("Checkbox1", 384, 96, 17, 17)
$Label1 = GUICtrlCreateLabel("Mute", 400, 96, 32, 19)
GUICtrlSetFont(-1, 10, 800, 0, "Times New Roman")

$Group2 = GUICtrlCreateGroup("Magnifying Size", 168, 168, 297, 105)
GUICtrlCreateInput("", 216, 208, 97, 32)
$Label2 = GUICtrlCreateLabel("X", 320, 224, 13, 19)
GUICtrlSetFont(-1, 10, 800, 0, "Times New Roman")

$Quit = GUICtrlCreateButton("Quit", 240, 304, 145, 57, $WS_GROUP)
GUICtrlSetFont(-1, 28, 800, 0, "Australian Sunrise")
GUISetState(@SW_SHOW)

$msg = GUIGetMsg()

While $msg=$Quit

getMousePosition()
getIconPositions()

Global $distance[$iconNumber]
Global $distance2[$iconNumber]
For $i=0 To UBound($iconPos) -1
    $distance[$i]=((($iconPos[$i][0]-$x)*($iconPos[$i][0]-$x))+(($iconPos[$i][1]-$y)*($iconPos[$i][1]-$y)))^(1/2)
Next
For $i=0 To UBound($distance) -1
    If $distance[$i]<=100 Then
        $distance2[$i]=$distance[$i]
    EndIf
Next
If (UBound($distance2) -1) = 1 Then
    $distance2[0]=$finalDistance
    MsgBox(64,"Icon","Yeah")
EndIf
WEnd


Func getMousePosition()
$pos=MouseGetPos()
$x=$pos[0]
$y=$pos[1]
EndFunc

Func getIconPositions()
    $desktop=ControlGetHandle("[CLASS:Progman]","","[CLASS:SysListView32;INSTANCE:1]")
    $iconNumber=_GUICtrlListView_GetItemCount($desktop)
    If $iconNumber>0 Then
         Global $iconPos[$iconNumber][2]
     For $i=0 To UBound($iconPos) -1
         $iconPos[$i][0]=_GUICtrlListView_GetItemPositionX($desktop, $i)
         $iconPos[$i][1]=_GUICtrlListView_GetItemPositionY($desktop, $i)
     Next
    Else
        MsgBox(64,"Error","No icons on desktop.", 3)
    EndIf

    _ArrayDisplay($iconPos, "Icon X Position - Icon Y Position")
EndFunc

The menu only flashed for a moment then the program stopped running.


My Projects:Smart Icons

Share this post


Link to post
Share on other sites
TurionAltec

A couple problems with your code,

$msg = GUIGetMsg()

While $msg=$Quit

-The GUIGetMsg needs to be inside the While loop to update.

-With the While statement you have, it will not execute the loop unless the quit button is being pressed. Change the "=" to "<>"

I found even putting GuiGetMsg in the loop it wasn't reliably pulling button presses, so I switched to onevent mode. (I commented out _ArrayDisplay too so it won't keep popping up)

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <SliderConstants.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <GuiListView.au3>
#include <Array.au3>
Global $finalDistance, $msg, $desktop, $iconNumber, $x, $y, $pos, $iconPos

opt("GUIOnEventMode",1)
$SI = GUICreate("Smart Icons", 625, 445, 192, 124,$WS_MINIMIZEBOX)
GUISetFont(20, 800, 0, "Australian Sunrise")
$Group1 = GUICtrlCreateGroup("Sound Options", 168, 32, 297, 105)
$Slider1 = GUICtrlCreateSlider(184, 80, 193, 49)
$Checkbox1 = GUICtrlCreateCheckbox("Checkbox1", 384, 96, 17, 17)
$Label1 = GUICtrlCreateLabel("Mute", 400, 96, 32, 19)
GUICtrlSetFont(-1, 10, 800, 0, "Times New Roman")

$Group2 = GUICtrlCreateGroup("Magnifying Size", 168, 168, 297, 105)
GUICtrlCreateInput("", 216, 208, 97, 32)
$Label2 = GUICtrlCreateLabel("X", 320, 224, 13, 19)
GUICtrlSetFont(-1, 10, 800, 0, "Times New Roman")

$Quit = GUICtrlCreateButton("Quit", 240, 304, 145, 57, $WS_GROUP)
GUICtrlSetFont(-1, 28, 800, 0, "Australian Sunrise")
GUICtrlSetOnEvent($Quit, "Quit")

GUISetState(@SW_SHOW)

;$msg = GUIGetMsg()

;While While $msg<>$Quit

While 1

getMousePosition()
getIconPositions()

Global $distance[$iconNumber]
Global $distance2[$iconNumber]
For $i=0 To UBound($iconPos) -1
    $distance[$i]=((($iconPos[$i][0]-$x)*($iconPos[$i][0]-$x))+(($iconPos[$i][1]-$y)*($iconPos[$i][1]-$y)))^(1/2)
Next
For $i=0 To UBound($distance) -1
    If $distance[$i]<=100 Then
        $distance2[$i]=$distance[$i]
    EndIf
Next
If (UBound($distance2) -1) = 1 Then
    $distance2[0]=$finalDistance
    MsgBox(64,"Icon","Yeah")
EndIf
;$msg = GUIGetMsg()
WEnd


Func getMousePosition()
$pos=MouseGetPos()
$x=$pos[0]
$y=$pos[1]
EndFunc

Func getIconPositions()
    $desktop=ControlGetHandle("[CLASS:Progman]","","[CLASS:SysListView32;INSTANCE:1]")
    $iconNumber=_GUICtrlListView_GetItemCount($desktop)
    If $iconNumber>0 Then
         Global $iconPos[$iconNumber][2]
     For $i=0 To UBound($iconPos) -1
         $iconPos[$i][0]=_GUICtrlListView_GetItemPositionX($desktop, $i)
         $iconPos[$i][1]=_GUICtrlListView_GetItemPositionY($desktop, $i)
     Next
    Else
        MsgBox(64,"Error","No icons on desktop.", 3)
    EndIf

;    _ArrayDisplay($iconPos, "Icon X Position - Icon Y Position")
EndFunc

Func Quit()
    Exit
EndFunc
Edited by TurionAltec

Share this post


Link to post
Share on other sites
rliiack

Thanks, it now quits when quit is pressed. But the message box is not showing at

While 1

getMousePosition()
getIconPositions()

Global $distance[$iconNumber]
Global $distance2[$iconNumber]
For $i=0 To UBound($iconPos) -1
    $distance[$i]=((($iconPos[$i][0]-$x)*($iconPos[$i][0]-$x))+(($iconPos[$i][1]-$y)*($iconPos[$i][1]-$y)))^(1/2)
Next
For $i=0 To UBound($distance) -1
    If $distance[$i]<=100 Then
        $distance2[$i]=$distance[$i]
    EndIf
Next
If (UBound($distance2) -1) = 1 Then
    $distance2[0]=$finalDistance
    MsgBox(64,"Icon","Yeah") ;HERE
EndIf
WEnd

Is my algorithm wrong? Or is it simply not executing this part?

P.S. Sorry I don't know how to put the code in color.

Edited by rliiack

My Projects:Smart Icons

Share this post


Link to post
Share on other sites
TurionAltec

If (UBound($distance2) -1) = 1

This statement must be false, so it's not executing "$distance2[0]=$finalDistance

" or the Msgbox.

I don't know whether or not the algorithm is correct or not

To get code in colour, wrap it in "autoit" instead of "code":

Share this post


Link to post
Share on other sites
rliiack

I added the accessArrayData function, but the menu, again, refused to open.

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <SliderConstants.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <GuiListView.au3>
#include <Array.au3>
Global $finalDistance, $msg, $desktop, $iconNumber, $x, $y, $pos, $iconPos, $counter2, $counter

opt("GUIOnEventMode",1)
$SI = GUICreate("Smart Icons", 625, 445, 192, 124,$WS_MINIMIZEBOX)
GUISetFont(20, 800, 0, "Australian Sunrise")
$Group1 = GUICtrlCreateGroup("Sound Options", 168, 32, 297, 105)
$Slider1 = GUICtrlCreateSlider(184, 80, 193, 49)
$Checkbox1 = GUICtrlCreateCheckbox("Checkbox1", 384, 96, 17, 17)
$Label1 = GUICtrlCreateLabel("Mute", 400, 96, 32, 19)
GUICtrlSetFont(-1, 10, 800, 0, "Times New Roman")

$Group2 = GUICtrlCreateGroup("Magnifying Size", 168, 168, 297, 105)
GUICtrlCreateInput("", 216, 208, 97, 32)
$Label2 = GUICtrlCreateLabel("X", 320, 224, 13, 19)
GUICtrlSetFont(-1, 10, 800, 0, "Times New Roman")

$Quit = GUICtrlCreateButton("Quit", 240, 304, 145, 57, $WS_GROUP)
GUICtrlSetFont(-1, 28, 800, 0, "Australian Sunrise")
GUICtrlSetOnEvent($Quit, "Quit")

GUISetState(@SW_SHOW)

While 1

getMousePosition()
getIconPositions()

Global $distance[$iconNumber]
Global $distance2[$iconNumber]
For $i=0 To UBound($iconPos) -1
    $distance[$i]=((($iconPos[$i][0]-$x)*($iconPos[$i][0]-$x))+(($iconPos[$i][1]-$y)*($iconPos[$i][1]-$y)))^(1/2)
Next
For $i=0 To UBound($distance) -1
    If  $distance[$i]<=100 Then
        $distance2[$i]=$distance[$i]
    EndIf
Next
accessArrayData()
For $i=0 To UBound($counter2) -1
    ToolTip("Hi",$iconPos[$counter2[$i]][0],$iconPos[$counter2[$i]][1])
Next
WEnd


Func getMousePosition()
$pos=MouseGetPos()
$x=$pos[0]
$y=$pos[1]
EndFunc

Func getIconPositions()
    $desktop=ControlGetHandle("[CLASS:Progman]","","[CLASS:SysListView32;INSTANCE:1]")
    $iconNumber=_GUICtrlListView_GetItemCount($desktop)
    If $iconNumber>0 Then
         Global $iconPos[$iconNumber][2]
     For $i=0 To UBound($iconPos) -1
         $iconPos[$i][0]=_GUICtrlListView_GetItemPositionX($desktop, $i)
         $iconPos[$i][1]=_GUICtrlListView_GetItemPositionY($desktop, $i)
     Next
    Else
        MsgBox(64,"Error","No icons on desktop.", 3)
    EndIf

;    _ArrayDisplay($iconPos, "Icon X Position - Icon Y Position")
EndFunc

Func Quit()
    Exit
EndFunc

Func accessArrayData()
    $counter=0
    Global $counter2[$distance2]
    for $i=0 To UBound($distance2) -1
        If $distance2[$i]>0 Then
             $counter2[$counter]=$i
             $counter=$counter+1
         EndIf
     Next
EndFunc

My Projects:Smart Icons

Share this post


Link to post
Share on other sites
rliiack

(93) : ==> Array variable subscript badly formatted.:

Global $counter2[$distance2]

Global $counter2[^ ERROR

What does this error mean? It only comes out when I run the program not when I compile it.

Edited by rliiack

My Projects:Smart Icons

Share this post


Link to post
Share on other sites
TurionAltec

Global $counter2[$distance2]

In this line $distance2 must be equivalent to a number to be correct. $distance2 is defined earlier on as:

Global $distance[$iconNumber]

So it's actually an array. So it's completely nonsensical, as it's like saying

Global $counter2[45,12,35,63,12]

If you want $counter2 to be the same size as $distance2, you could do something like:

Global $counter2[ubound($distance2)]

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  

×