Jump to content

Moving a Icon


OminousIdol
 Share

Recommended Posts

I made a icon moveable in a GUI... In order to move left right up down had to recreate the GUI every time so when I moved the icon up down left right it would blink for a second and then show new GUI! I have already tired to move it in one GUI but could not get it to work. If somone could tell me how I can do this all in 1 GUI so their is no Blinking between moves that would be great!!

My Code

;CONTROLS
HotKeySet("{DOwn}", "movedown")
HotKeySet("{UP}", "moveup")
HotKeySet("{LEFT}", "moveleft")
HotKeySet("{RIGHT}", "moveright")

;VARS
$x = 10
$y = 60
$t = 0
$i = 0


call("moveup")

;MOVE LEFT



func moveleft()
$x = $x - 30
$i = 0
GuiCreate("test", 800, 600)


$chara = GuiSetControl("icon", "shell32.dll|7", $x, $y, 50, 30)

while $i = 0
guishow()
wend

endfunc

;MOVE UP

func moveup()
$y = $y - 30
$t = 0
GuiCreate("test", 800, 600)

$chara = GuiSetControl("icon", "shell32.dll|7", $x, $y, 50, 30)

while $t = 0
guishow()
wend

endfunc


;MOVE RIGHT

func moveright()
$i = 10
$x = $x + 30

GuiCreate("test", 800, 600)

$chara = GuiSetControl("icon", "shell32.dll|7", $x, $y, 50, 30)

while $i = 10
GuiShow(0)
Wend

endfunc

;MOVE DOWN

func movedown()
$t = 10
$y = $y + 30


GuiCreate("test",800,600)
$chara = GuiSetControl("icon", "shell32.dll|7", $x, $y, 50, 30)

while $t = 10
GuiShow()
wend

endfunc

Thanks

OminousIdol

ALSO... Is their a way to know if the icon moves off the GUI and then make it so it cant move off the GUI!

Link to comment
Share on other sites

Supports both arrow keys and mouse; however, the mouse will let you drag the icon off the window...

#cs - ### Generated by AutoBuilder 0.4 -- do not modify ###
394 278
0   0   0   0   0   0   0   1   0   0   0   0   0   0   0   0   
icon    $icon_1 Icon 1  30  30  50  50  0   0   
#ce - ### End of Dump ###

;Script generated by AutoBuilder 0.4 but modified

Global $icon_1, $x = 30, $y = 40, $w = 32, $h = 32
Global $guiWidth = 400, $guiHeight = 300

Global $mouseMode = 0 ;0 means stationary, 1 means moving

Opt("MouseCoordMode", 0) ;relative to window

HotKeySet("{DOWN}", "movedown")
Func movedown()
   $y = $y + 10
  ; Bounds check to make sure icon does not move off of GUI:
   If ($y + $h) > $guiHeight Then $y = $guiHeight - $h
   GUISetControl($icon_1, "shell32.dll|7", $x, $y, $w, $h)
EndFunc

HotKeySet("{UP}", "moveup")
Func moveup()
   $y = $y - 10
   If $y < 0 Then $y = 0 ; bounds check
   GUISetControl($icon_1, "shell32.dll|7", $x, $y, $w, $h)
EndFunc

HotKeySet("{LEFT}", "moveleft")
Func moveleft()
   $x = $x - 10
   If $x < 0 Then $x = 0
   GUISetControl($icon_1, "shell32.dll|7", $x, $y, $w, $h)
EndFunc

HotKeySet("{RIGHT}", "moveright")
Func moveright()
   $x = $x + 10
   If ($x + $w) > $guiWidth Then $x = $guiWidth - $w
   GUISetControl($icon_1, "shell32.dll|7", $x, $y, $w, $h)
EndFunc

Opt("GUICoordMode", 1)
Opt("GUINotifyMode", 1)
GuiCreate("Click on icon to move... then click again.", $guiWidth, $guiHeight, (@DesktopWidth-392)/2, (@DesktopHeight-273)/2 , 0x04CF0000)

$icon_1 = GUISetControl("icon", "shell32.dll|7", 30, 30, $w, $h)

GuiShow()

While 1
    sleep(100)
    $msg = GuiMsg(0)
    Select
    Case $msg = -3
        Exit
    Case $msg = $icon_1
        $mouseMode = NOT $mouseMode;toggle
    EndSelect
     
    If $mouseMode Then
      $pos = MouseGetPos()
      $x = $pos[0] - $w/2
      $y = $pos[1] - $h;TECHNICALLY SHOULD SUBTRACT HALF THE HEIGHT, BUT THIS LOOSELY APPROXIMATES FOR THE TITLE BAR....
     ;  Problem is that Opt("MouseCoordMode", 0) is for the window instead of the client area of the window....
     ;  Somewhere, I have code that calculates the difference....
      GUISetControl($icon_1, "shell32.dll|7", $x, $y, $w, $h)
     ; subtract half the width or height of the icon so that the icon is centered over the mouse cursor
    EndIf
WEnd
Exit
Use Mozilla | Take a look at My Disorganized AutoIt stuff | Very very old: AutoBuilder 11 Jan 2005 prototype I need to update my sig!
Link to comment
Share on other sites

Some key points about GUI controls:

First instance:

$icon_1 = GUISetControl("icon", "shell32.dll|7", 30, 30, $w, $h)

Subsequent instances:

GUISetControl($icon_1, "shell32.dll|7", 30, 30, $w, $h)

As far as bounds checking goes, if the $x or $y coordinate would ever exceed the boundary, you reset it's value to the threshold....

When you click the icon, the main message loop of the the program (While 1... WEnd) checks to see if you are in move mode. When you are in move mode, the icon is positioned to appear under the mouse cursor.

Hope that helps

Use Mozilla | Take a look at My Disorganized AutoIt stuff | Very very old: AutoBuilder 11 Jan 2005 prototype I need to update my sig!
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...