GUI move pic function

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
Trigg
Posts: 97
Joined: 07 Apr 2017, 19:43

GUI move pic function

15 Jul 2017, 22:23

Before I tried making this into a function.

Code: Select all

; Read picture positions
IniRead, Pic1x, GUI.ini, PicPositions, Pic1x
IniRead, Pic1y, GUI.ini, PicPositions, Pic1y
IniRead, Pic2x, GUI.ini, PicPositions, Pic2x
IniRead, Pic2y, GUI.ini, PicPositions, Pic2y
IniRead, Pic3x, GUI.ini, PicPositions, Pic3x
IniRead, Pic3y, GUI.ini, PicPositions, Pic3y

							; GUI
Gui, Add, Picture, w150 h150 x%Pic1x% y%Pic1y% hWndPic1, earth-img.jpg
Gui, Add, Picture, w150 h150 x%Pic2x% y%Pic2y% hWndPic2, earth-img.jpg
Gui, Add, Picture, w150 h150 x%Pic3x% y%Pic3y% hWndPic3, earth-img.jpg
Gui, Add, DropDownList, vDropDown gMovePicture, 1|2|3
Gui, Show, W640 h500

							; Move wanted picture
MovePicture:
Gui, Submit, NoHide
If ( DropDown = 1 )
PostMessage, 0x112, 0xF010,,, ahk_id %Pic1%
If ( DropDown = 2 )
PostMessage, 0x112, 0xF010,,, ahk_id %Pic2%
If ( DropDown = 3 )
PostMessage, 0x112, 0xF010,,, ahk_id %Pic3%
Return



GuiCLose:						; Save picture positions
IniWrite, %Pic1x%, GUI.ini, PicPositions, Pic1y
IniWrite, %Pic1y%, GUI.ini, PicPositions, Pic1y
IniWrite, %Pic2x%, GUI.ini, PicPositions, Pic2x
IniWrite, %Pic2y%, GUI.ini, PicPositions, Pic2y
IniWrite, %Pic3x%, GUI.ini, PicPositions, Pic3x
IniWrite, %Pic3y%, GUI.ini, PicPositions, Pic3y
ExitApp
Return

EDIT for function:
I cannot seem to get PostMessage to work with my GUI pictures inside of a function.

I'm trying to hold the RButton to move a picture, and I'm vaguely new to using this method.

No matter what I try to do, I can't get PostMessage to work in this function.

Code: Select all

Gui, Add, Picture, vPic1 hWndPic1 w100 h100, Pic1.png
Gui, Add, Picture, vPic2 hWndPic2 w100 h100, Pic2.png
Gui, Show, w300 h300
OnMessage(0x204, "WM_RBUTTONDOWN")
return

WM_RBUTTONDOWN()
{
	;static CurrControl, _rbdn
	;CurrControl := A_GuiControl

	ClickTime := A_TickCount
	KeyWait, RButton
	If A_TickCount - ClickTime > 1000
	MouseGetPos,,,,ControlName
	GuiControlGet, PicName, Name, % ControlName
	;MsgBox % PicName
	PostMessage, 0x112, 0xF010,,, ahk_id %PicName%		; I can't figure out how to make the variable accurate
}
return

GuiClose:
ExitApp
Last edited by Trigg on 18 Jul 2017, 12:05, edited 9 times in total.
User avatar
Masonjar13
Posts: 1555
Joined: 20 Jul 2014, 10:16
Location: Не Россия
Contact:

Re: GUI move pic and save pos

15 Jul 2017, 22:42

See GuiControlGet and note that the INI key for the first IniWrite after the GuiClose is incorrect, should be Pic1x.

There's a great number of ways you can save data to disk for later, and INI's are the typically the easiest to work with in AHK, but they do have character limits per value (around 2^16-1). Not that you'll exceed that in this case.
OS: Windows 10 Pro | Editor: Notepad++
My Personal Function Library | Old Build - New Build
Trigg
Posts: 97
Joined: 07 Apr 2017, 19:43

Re: GUI move pic and save pos

16 Jul 2017, 12:13

Masonjar13 wrote:See GuiControlGet and note that the INI key for the first IniWrite after the GuiClose is incorrect, should be Pic1x.

There's a great number of ways you can save data to disk for later, and INI's are the typically the easiest to work with in AHK, but they do have character limits per value (around 2^16-1). Not that you'll exceed that in this case.

Thank you! And I know, I just want to keep it easy for now :) but I will definitely change it in the future.

And thanks for finding that mistake for me!
garry
Posts: 3760
Joined: 22 Dec 2013, 12:50

Re: GUI move pic and save pos

17 Jul 2017, 05:15

thank you
how can I move pictures inside GUI ?

Code: Select all

;-------- https://autohotkey.com/boards/viewtopic.php?f=5&t=34550 ---

pictini=%a_scriptdir%\pictures.ini
ifnotexist,%pictini%
{
IniWrite, 10   , %pictini%, PicPositions, Pic1x
IniWrite, 10   , %pictini%, PicPositions, Pic1y
IniWrite, 220  , %pictini%, PicPositions, Pic2x
IniWrite, 10   , %pictini%, PicPositions, Pic2y
IniWrite, 440  , %pictini%, PicPositions, Pic3x
IniWrite, 10   , %pictini%, PicPositions, Pic3y
}

IniRead, Pic1x, %pictini%, PicPositions, Pic1x
IniRead, Pic1y, %pictini%, PicPositions, Pic1y
IniRead, Pic2x, %pictini%, PicPositions, Pic2x
IniRead, Pic2y, %pictini%, PicPositions, Pic2y
IniRead, Pic3x, %pictini%, PicPositions, Pic3x
IniRead, Pic3y, %pictini%, PicPositions, Pic3y

Gui, Add, Picture, w200 h150 x%Pic1x% y%Pic1y% hWndPic1, 1.jpg
Gui, Add, Picture, w200 h150 x%Pic2x% y%Pic2y% hWndPic2, 2.jpg
Gui, Add, Picture, w200 h150 x%Pic3x% y%Pic3y% hWndPic3, 3.jpg
Gui, Add, DropDownList, vDropDown gMovePicture, 1|2|3
Gui, Show, W640 h500
return

						; Move wanted picture
MovePicture:
Gui, Submit, NoHide
If ( DropDown = 1 )
  PostMessage, 0x112, 0xF010,,, ahk_id %Pic1%
If ( DropDown = 2 )
  PostMessage, 0x112, 0xF010,,, ahk_id %Pic2%
If ( DropDown = 3 )
  PostMessage, 0x112, 0xF010,,, ahk_id %Pic3%
Return


GuiCLose:						; Save picture positions
IniWrite, %Pic1x%, %pictini%, PicPositions, Pic1x
IniWrite, %Pic1y%, %pictini%, PicPositions, Pic1y
IniWrite, %Pic2x%, %pictini%, PicPositions, Pic2x
IniWrite, %Pic2y%, %pictini%, PicPositions, Pic2y
IniWrite, %Pic3x%, %pictini%, PicPositions, Pic3x
IniWrite, %Pic3y%, %pictini%, PicPositions, Pic3y
ExitApp
Trigg
Posts: 97
Joined: 07 Apr 2017, 19:43

Re: GUI move pic and save pos

17 Jul 2017, 10:44

garry wrote:thank you
how can I move pictures inside GUI ?
Choose 1-3 in the dropdownlist. and you hit any arrow key to start moving the picture. CTRL + arrow key will be more precise and goes by 1 pixel. After pressing an arrow key you can use your mouse to move the GUI picture.
Last edited by Trigg on 18 Jul 2017, 07:11, edited 1 time in total.
Trigg
Posts: 97
Joined: 07 Apr 2017, 19:43

Re: GUI move pic function

18 Jul 2017, 09:46

I changed the function a little by adding GuiControlGet, but PostMessage still does not work.

Code: Select all

WM_RBUTTONDOWN()
{
	;static CurrControl, _rbdn
	;CurrControl := A_GuiControl

	ClickTime := A_TickCount
	KeyWait, RButton
	If A_TickCount - ClickTime > 1000
	MouseGetPos,,,,ControlName
	GuiControlGet, PicName, Name, % ControlName
	;MsgBox % PicName
	PostMessage, 0x112, 0xF010,,, ahk_id %PicName%
}
garry
Posts: 3760
Joined: 22 Dec 2013, 12:50

Re: GUI move pic function

20 Jul 2017, 10:24

thank you Trigg
with RBUTTON seems to work , just not get the X/Y position from the picture after moved

Code: Select all

;https://autohotkey.com/boards/viewtopic.php?f=5&t=34550
;https://autohotkey.com/docs/commands/GuiControlGet.htm

;- How to use :
;- (select with DropDownList) new with RBUTTON the picture and move with arrow  ( ctrl+arrow more precise )
;- don't know how to get the new x/y position from the moved picture
;- with WM_RBUTTONDOWN I see vPic1a  and not hwndpic1

OnMessage(0x204, "WM_RBUTTONDOWN")

pictini=%a_scriptdir%\pictures.ini
ifnotexist,%pictini%
{
IniWrite, 10   , %pictini%, PicPositions, Pic1x
IniWrite, 10   , %pictini%, PicPositions, Pic1y
IniWrite, 220  , %pictini%, PicPositions, Pic2x
IniWrite, 10   , %pictini%, PicPositions, Pic2y
IniWrite, 440  , %pictini%, PicPositions, Pic3x
IniWrite, 10   , %pictini%, PicPositions, Pic3y
}
IniRead, Pic1x, %pictini%, PicPositions, Pic1x
IniRead, Pic1y, %pictini%, PicPositions, Pic1y
IniRead, Pic2x, %pictini%, PicPositions, Pic2x
IniRead, Pic2y, %pictini%, PicPositions, Pic2y
IniRead, Pic3x, %pictini%, PicPositions, Pic3x
IniRead, Pic3y, %pictini%, PicPositions, Pic3y

Gui, Add, Picture, w200 h150 x%Pic1x% y%Pic1y% hWndPic1 vPic1a, 1.jpg
Gui, Add, Picture, w200 h150 x%Pic2x% y%Pic2y% hWndPic2 vPic2a, 2.jpg
Gui, Add, Picture, w200 h150 x%Pic3x% y%Pic3y% hWndPic3 vPic3a, 3.jpg
;Gui, Add, DropDownList, vDropDown gMovePicture, 1|2|3
Gui, Show, W640 h500
return
Guiclose:
exitapp

/*
MovePicture:
Gui, Submit, NoHide
If ( DropDown = 1 )
  PostMessage, 0x112, 0xF010,,, ahk_id %Pic1%
If ( DropDown = 2 )
  PostMessage, 0x112, 0xF010,,, ahk_id %Pic2%
If ( DropDown = 3 )
  PostMessage, 0x112, 0xF010,,, ahk_id %Pic3%
return
*/

aa:
MouseGetPos,,,,ControlName
GuiControlGet, N, Name, % ControlName
;GuiControlGet, P, Pos, %N%
;msgbox, 262208, ,NAME=%n%`nX=%px%`nY=%py%`nW=%pw%`nH=%ph%,3

if (n="pic1a")
 PostMessage, 0x112, 0xF010,,, ahk_id %Pic1%
if (n="pic2a")
 PostMessage, 0x112, 0xF010,,, ahk_id %Pic2%
if (n="pic3a")
 PostMessage, 0x112, 0xF010,,, ahk_id %Pic3%

;- problem here : the position is the same after moved

GuiControlGet, P, Pos, %N%
msgbox, 262208, ,NAME=%n%`nX=%px%`nY=%py%`nW=%pw%`nH=%ph%,3

return


WM_RBUTTONDOWN()
{
gosub,aa
}
;==============================================================

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Exies, Google [Bot], JoeWinograd, scriptor2016 and 96 guests