Jump to content

controlmove troubles


sandin
 Share

Recommended Posts

this is script example:

#include <GUIConstants.au3>
Global $i = 0, $j = 0, $k = 0
$Form1 = GUICreate("Title", 633, 447, 193, 115)
$Button1 = GUICtrlCreateButton("AButton1", 184, 240, 225, 49, 0)
GUICtrlSetResizing(-1,$GUI_DOCKTOP+$GUI_DOCKSIZE)
$Button2 = GUICtrlCreateButton("AButton2", 184, 300, 225, 49, 0)
GUICtrlSetResizing(-1,$GUI_DOCKTOP+$GUI_DOCKSIZE)
$Label1 = GUICtrlCreateLabel("ALabel1", 64, 80, 43, 17)
GUICtrlSetResizing(-1,$GUI_DOCKTOP+$GUI_DOCKSIZE)
GUISetState(@SW_SHOW)

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case  $Button1
            call("Func1")
        case $Button2
            call("Func2")
    EndSwitch
WEnd

func adlib1 ()
    $pos = ControlGetPos("Title", "", $Label1)
    if $j = 0 then
        call("right")
        $pos = ControlGetPos("Title", "", $Label1)
        if $pos[0] > 400 then $j = 1
    Else
        call("left")
        $pos = ControlGetPos("Title", "", $Label1)
        if $pos[0] < 64 then $j = 0
    EndIf
EndFunc

func right()
    $pos = ControlGetPos("Title", "", $Label1)
    ControlMove("Title", "", $Label1, $pos[0]+1, $pos[1])
EndFunc

func left ()
    $pos = ControlGetPos("Title", "", $Label1)
    ControlMove("Title", "", $Label1, $pos[0]-1, $pos[1])
EndFunc

func func1 ()
    if $i = 0 Then
        AdlibEnable("adlib1", 10)
        $i = 1
    Else
        AdlibDisable()
        $i = 0
    EndIf
EndFunc

func func2()
    if $k = 0 Then
        $pos = WinGetPos("Title")
        WinMove("Title", "", $pos[0], $pos[1], $pos[2], $pos[3]-50)
        $k = 1
    Else
        $pos = WinGetPos("Title")
        WinMove("Title", "", $pos[0], $pos[1], $pos[2], $pos[3]+50)
        $k = 0
    EndIf
EndFunc

my problem is following: if I launch adlib func with first button, the label will go right-left-right, etc... but if I try to change the size of the GUI (with second button), the label resets it's position on the beginning one (the one it had at the launching of the script). Can any1 help me change this so it will continue to work without reseting it's position if I change GUI's size?

Link to comment
Share on other sites

this is script example:

#include <GUIConstants.au3>
Global $i = 0, $j = 0, $k = 0
$Form1 = GUICreate("Title", 633, 447, 193, 115)
$Button1 = GUICtrlCreateButton("AButton1", 184, 240, 225, 49, 0)
GUICtrlSetResizing(-1,$GUI_DOCKTOP+$GUI_DOCKSIZE)
$Button2 = GUICtrlCreateButton("AButton2", 184, 300, 225, 49, 0)
GUICtrlSetResizing(-1,$GUI_DOCKTOP+$GUI_DOCKSIZE)
$Label1 = GUICtrlCreateLabel("ALabel1", 64, 80, 43, 17)
GUICtrlSetResizing(-1,$GUI_DOCKTOP+$GUI_DOCKSIZE)
GUISetState(@SW_SHOW)

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case  $Button1
            call("Func1")
        case $Button2
            call("Func2")
    EndSwitch
WEnd

func adlib1 ()
    $pos = ControlGetPos("Title", "", $Label1)
    if $j = 0 then
        call("right")
        $pos = ControlGetPos("Title", "", $Label1)
        if $pos[0] > 400 then $j = 1
    Else
        call("left")
        $pos = ControlGetPos("Title", "", $Label1)
        if $pos[0] < 64 then $j = 0
    EndIf
EndFunc

func right()
    $pos = ControlGetPos("Title", "", $Label1)
    ControlMove("Title", "", $Label1, $pos[0]+1, $pos[1])
EndFunc

func left ()
    $pos = ControlGetPos("Title", "", $Label1)
    ControlMove("Title", "", $Label1, $pos[0]-1, $pos[1])
EndFunc

func func1 ()
    if $i = 0 Then
        AdlibEnable("adlib1", 10)
        $i = 1
    Else
        AdlibDisable()
        $i = 0
    EndIf
EndFunc

func func2()
    if $k = 0 Then
        $pos = WinGetPos("Title")
        WinMove("Title", "", $pos[0], $pos[1], $pos[2], $pos[3]-50)
        $k = 1
    Else
        $pos = WinGetPos("Title")
        WinMove("Title", "", $pos[0], $pos[1], $pos[2], $pos[3]+50)
        $k = 0
    EndIf
EndFunc

my problem is following: if I launch adlib func with first button, the label will go right-left-right, etc... but if I try to change the size of the GUI (with second button), the label resets it's position on the beginning one (the one it had at the launching of the script). Can any1 help me change this so it will continue to work without reseting it's position if I change GUI's size?

#include <GUIConstants.au3>
Global $i = 0, $j = 0, $k = 0
$Form1 = GUICreate("Title", 633, 447, 193, 115)
$Button1 = GUICtrlCreateButton("AButton1", 184, 240, 225, 49, 0)
GUICtrlSetResizing(-1,$GUI_DOCKTOP+$GUI_DOCKSIZE)
$Button2 = GUICtrlCreateButton("AButton2", 184, 300, 225, 49, 0)
GUICtrlSetResizing(-1,$GUI_DOCKTOP+$GUI_DOCKSIZE)
$Label1 = GUICtrlCreateLabel("ALabel1", 64, 80, 43, 17)
GUICtrlSetResizing(-1,$GUI_DOCKTOP+$GUI_DOCKSIZE)
GUISetState(@SW_SHOW)

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case  $Button1
            call("Func1")
        case $Button2
            call("Func2")
    EndSwitch
WEnd

func adlib1 ()
    $pos = ControlGetPos("Title", "", $Label1)
    if $j = 0 then
        call("right")
        $pos = ControlGetPos("Title", "", $Label1)
        if $pos[0] > 400 then $j = 1
    Else
        call("left")
        $pos = ControlGetPos("Title", "", $Label1)
        if $pos[0] < 64 then $j = 0
    EndIf
EndFunc

func right()
    $pos = ControlGetPos("Title", "", $Label1)
    ControlMove("Title", "", $Label1, $pos[0]+1, $pos[1])
EndFunc

func left ()
    $pos = ControlGetPos("Title", "", $Label1)
    ControlMove("Title", "", $Label1, $pos[0]-1, $pos[1])
EndFunc

func func1 ()
    if $i = 0 Then
        AdlibEnable("adlib1", 10)
        $i = 1
    Else
        AdlibDisable()
        $i = 0
    EndIf
EndFunc

func func2()
    if $k = 0 Then
        $posX = ControlGetPos("Title", "", $Label1)
        $pos = WinGetPos("Title")
        WinMove("Title", "", $pos[0], $pos[1], $pos[2], $pos[3]-50)
        $k = 1
        ControlMove("Title", "", $Label1, $posX[0], $posX[1], $posX[2], $posX[3])
    Else
    $posX = ControlGetPos("Title", "", $Label1)
        $pos = WinGetPos("Title")
        WinMove("Title", "", $pos[0], $pos[1], $pos[2], $pos[3]+50)
        $k = 0
        ControlMove("Title", "", $Label1, $posX[0], $posX[1], $posX[2], $posX[3])
    EndIf
EndFunc

صرح السماء كان هنا

 

Link to comment
Share on other sites

  • Moderators

The code is full of Errors really... I was confused on what exactly you were trying to do, so I took a guess (added some error checking too because it was throwing errors)

#include <GUIConstants.au3>
Opt("GUIResizeMode", 802)
Global $pos
Global $i = 0, $j = 0, $k = 0
$Form1 = GUICreate("Title", 633, 447, 193, 115)
$Button1 = GUICtrlCreateButton("AButton1", 184, 240, 225, 49, 0)
GUICtrlSetResizing(-1,$GUI_DOCKTOP+$GUI_DOCKSIZE)
$Button2 = GUICtrlCreateButton("AButton2", 184, 300, 225, 49, 0)
GUICtrlSetResizing(-1,$GUI_DOCKTOP+$GUI_DOCKSIZE)
$Label1 = GUICtrlCreateLabel("ALabel1", 64, 80, 43, 17)
GUICtrlSetResizing(-1,$GUI_DOCKTOP+$GUI_DOCKSIZE)
GUISetState(@SW_SHOW)

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case  $Button1
            call("Func1")
        case $Button2
            call("Func2")
    EndSwitch
WEnd

func adlib1 ()
    $pos = ControlGetPos($Form1, "", $Label1)
    If IsArray($pos) Then
        if $j = 0 then
            call("right")
            $pos = ControlGetPos($Form1, "", $Label1)
            If IsArray($pos) And $pos[0] > 400 then $j = 1
        Else
            call("left")
            $pos = ControlGetPos($Form1, "", $Label1)
            If IsArray($pos) And $pos[0] < 64 then $j = 0
        EndIf
    EndIf   
EndFunc

func right()
    $pos = ControlGetPos($Form1, "", $Label1)
    If IsArray($pos) Then ControlMove($Form1, "", $Label1, $pos[0]+1, $pos[1])
EndFunc

func left ()
    $pos = ControlGetPos($Form1, "", $Label1)
    If IsArray($pos) Then ControlMove($Form1, "", $Label1, $pos[0]-1, $pos[1])
EndFunc

func func1 ()
    if $i = 0 Then
        AdlibEnable("adlib1", 10)
        $i = 1
    Else
        AdlibDisable()
        $i = 0
    EndIf
EndFunc

func func2()
    if $k = 0 Then
        $pos = WinGetPos($Form1)
        If IsArray($pos) Then 
            WinMove($Form1, "", $pos[0], $pos[1], $pos[2], $pos[3]-50)
            $k = 1
        EndIf
    Else
        $pos = WinGetPos($Form1)
        If IsArray($pos) Then 
            WinMove($Form1, "", $pos[0], $pos[1], $pos[2], $pos[3]+50)
            $k = 0
        EndIf
    EndIf
EndFunc
I don't like the way you have everything named $pos though, and I changed the title "Title" you were using to the GUI's HWND

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

  • Moderators

thank you smoken, but in your script example 2nd button resets label's position, and in woolves scrip it does exaclty what I need.

Ok, I see what you wanted from his code... but I still suggest you do error checking, because I got GPF'd on both of your scripts because at some point, there wasn't an array.

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

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