Guicontrol Move works for 2 buttons but NOT a third

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
jm_bilac
Posts: 2
Joined: 04 Jan 2018, 18:51
Contact:

Guicontrol Move works for 2 buttons but NOT a third

04 Jan 2018, 19:00

Hi All, lots of searches and I give up, I need to ask for help. I'm new to AHK and my first script works great except that 1 button on the gui just wont move... 2 do, 1 just won't. Have tried lots different names for the button, tried guicontrol,move and the anchor script, and this 1 control button just won't move...

The script is to allow us to view and edit text in the clipboard... Ahk2exe 1 1 26 01 compiled vers and vers run by AutohotkeyU64 both the same. Win7 x64 home prem ed..

ARGH!!!


The script
--------------

Code: Select all

#NoTrayIcon   ; stops script/program showing icon in system tray

;Generate the GUI with controls
;vClipEdit names our edit so we can alter it with GuiControl. %clipboard% inserts contents of clipboard
Gui, Add, Edit, x22 y10 w440 h309 vClipEdit, %Clipboard% 
Gui, Font, S12 CDefault Bold, Verdana
Gui, Add, Button, x22 y329 w100 h30 gSave, Save Clip
Gui, Add, Button, x125 y329 w120 h30 gProblemBtn, Save n Close
Gui, Add, Button, x272 y329 w200 h30 gCancel, Cancel

Gui, Show, x127 y87 h379 w489 , Clipboard Contents by John Bilac c.2018
Gui +Resize ; make it resizable
Send {Down}  ; send keystroke to edit control, which has default focus, so whole text no longer selected
Return

Save:
GuiControlGet, MyText,, ClipEdit
stringreplace, MyText, MyText, `n, `r`n, all  ; this adds linefeeds back in, the Edit control uses 'n 

instead of windows 'r'n
Clipboard:= MyText
return

Cancel:
ExitApp
return

ProblemBtn:
GuiControlGet, MyText,, ClipEdit
stringreplace, MyText, MyText, `n, `r`n, all
Clipboard:= MyText
ExitApp
return

GuiClose: ;Close app on exit
ExitApp
return

GuiSize: ; win resize event
	;function adapted from jonny's clip.ahk. thanx jonny!
	new_w := (A_GuiWidth - 44) 
	new_h := (A_GuiHeight - 69) 
	field_y := (A_GuiHeight - 50) 
	guicontrol,move,ClipEdit,w%new_w% h%new_h%
	Anchor("Save", "y") ; guicontrol,move,Save,y%field_y% 
	Anchor("ProblemBtn", "y")    ; guicontrol, move, ProblemBtn, y%field_y%
	Anchor("Cancel", "y")  ; guicontrol,move,Cancel,y%field_y% 
return

Anchor(i, a := "", r := false) {
    static c, cs := 12, cx := 255, cl := 0, g, gs := 8, gl := 0, gpi, gw, gh, z := 0, k := 0xffff, ptr
    if z = 0
        VarSetCapacity(g, gs * 99, 0), VarSetCapacity(c, cs * cx, 0), ptr := A_PtrSize ? "Ptr" : "UInt", z 

:= true
    if !WinExist("ahk_id" . i) {
        GuiControlGet t, Hwnd, %i%
        if ErrorLevel = 0
            i := t
        else ControlGet i, Hwnd,, %i%
    }
    VarSetCapacity(gi, 68, 0), DllCall("GetWindowInfo", "UInt", gp := DllCall("GetParent", "UInt", i), ptr, 

&gi)
        , giw := NumGet(gi, 28, "Int") - NumGet(gi, 20, "Int"), gih := NumGet(gi, 32, "Int") - NumGet(gi, 

24, "Int")
    if (gp != gpi) {
        gpi := gp
        loop %gl%
            if NumGet(g, cb := gs * (A_Index - 1), "UInt") == gp {
                gw := NumGet(g, cb + 4, "Short"), gh := NumGet(g, cb + 6, "Short"), gf := 1
                break
            }
        if !gf
            NumPut(gp, g, gl, "UInt"), NumPut(gw := giw, g, gl + 4, "Short"), NumPut(gh := gih, g, gl + 6, 

"Short"), gl += gs
    }
    ControlGetPos dx, dy, dw, dh,, ahk_id %i%
    loop %cl%
        if NumGet(c, cb := cs * (A_Index - 1), "UInt") == i {
            if (a = "") {
                cf := 1
                break
            }
            giw -= gw, gih -= gh, as := 1, dx := NumGet(c, cb + 4, "Short"), dy := NumGet(c, cb + 6, 

"Short")
                , cw := dw, dw := NumGet(c, cb + 8, "Short"), ch := dh, dh := NumGet(c, cb + 10, "Short")
            loop Parse, a, xywh
                if A_Index > 1
                    av := SubStr(a, as, 1), as += 1 + StrLen(A_LoopField)
                        , d%av% += (InStr("yh", av) ? gih : giw) * (A_LoopField + 0 ? A_LoopField : 1)
            DllCall("SetWindowPos", "UInt", i, "UInt", 0, "Int", dx, "Int", dy
                , "Int", InStr(a, "w") ? dw : cw, "Int", InStr(a, "h") ? dh : ch, "Int", 4)
            if r != 0
                DllCall("RedrawWindow", "UInt", i, "UInt", 0, "UInt", 0, "UInt", 0x0101) ; RDW_UPDATENOW | 

RDW_INVALIDATE
            return
        }
    if cf != 1
        cb := cl, cl += cs
    bx := NumGet(gi, 48, "UInt"), by := NumGet(gi, 16, "Int") - NumGet(gi, 8, "Int") - gih - NumGet(gi, 52, 

"UInt")
    if cf = 1
        dw -= giw - gw, dh -= gih - gh
    NumPut(i, c, cb, "UInt"), NumPut(dx - bx, c, cb + 4, "Short"), NumPut(dy - by, c, cb + 6, "Short")
        , NumPut(dw, c, cb + 8, "Short"), NumPut(dh, c, cb + 10, "Short")
    return true
}
User avatar
TheDewd
Posts: 1510
Joined: 19 Dec 2013, 11:16
Location: USA

Re: Guicontrol Move works for 2 buttons but NOT a third

05 Jan 2018, 09:45

You have to assign a variable to the buttons. See below (vSave, vProblemBtn, vCancel)...

Code: Select all

Gui, Add, Button, x22 y329 w100 h30 gSave vSave, Save Clip
Gui, Add, Button, x125 y329 w120 h30 gProblemBtn vProblemBtn, Save n Close
Gui, Add, Button, x272 y329 w200 h30 gCancel vCancel, Cancel
Using the GuiSize built-in function:

Code: Select all

#SingleInstance, Force

Gui, +Resize +MinSize340x100
Gui, Margin, 10, 10
Gui, Add, Edit, x10 y10 w440 r24 vEdit1
Gui, Add, Button, w80 h24 vButton1, Save Clip
Gui, Add, Button, x+10 w80 h24 vButton2, Save && Close
Gui, Add, Button, x+10 w80 h24 vButton3, Cancel
Gui, Show, AutoSize, Example
return

GuiSize(GuiHwnd, EventInfo, Width, Height) {
    GuiControlGet, Edit1, Pos
    GuiControl, MoveDraw, Edit1, % "w" Width - 20 " h" Height - 54
    GuiControl, MoveDraw, Button1, % "y" (Edit1Y + Edit1H) + 10
    GuiControl, MoveDraw, Button2, % "y" (Edit1Y + Edit1H) + 10
    GuiControl, MoveDraw, Button3, % "y" (Edit1Y + Edit1H) + 10
}
jm_bilac
Posts: 2
Joined: 04 Jan 2018, 18:51
Contact:

Re: Guicontrol Move works for 2 buttons but NOT a third

05 Jan 2018, 23:21

Thanks TheDewd! the example programs I was working from, from web searches, only had gName1 and gName2 style 'appendages' for buttons not both gName AND vName for each button control.... Many thanks mate and have a great 2018!
GreatGazoo
Posts: 69
Joined: 28 Dec 2017, 02:53

Re: Guicontrol Move works for 2 buttons but NOT a third

05 Jan 2018, 23:46

this is interesting... im just getting back into AHK after a few years (5) im trying to teach myself how to use this again, its a fun hobby

i never used GUI before and i just started to work on one for the first time, so this is nice seeing what it should look like

i might make a thread about mine because i really am in over my head lol

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: No registered users and 230 guests