WinMove: can't configure GUI button to change monitor Topic is solved

Get help with using AutoHotkey and its commands and hotkeys
User avatar
KRG-23
Posts: 19
Joined: 07 Jun 2016, 05:45
Location: France

WinMove: can't configure GUI button to change monitor

21 Aug 2018, 08:21

Hello all,

I'm facing a conditional test problem I can't figure out ... It's certainly obvious to more trained eyes than mine so this might be a quick fix from anyone who'd fancy help me ;)

When I click on my button Send_to_Next_Monitor, it sends my GUI to monitor 2. When I click it again, it should send it back to monitor 1. And I can't make it work ...

Here's the complete code for my tests :

Code: Select all

#NoEnv
#SingleInstance force
#Warn


; ===============================================
; Variables
; ===============================================


; Main UI settings
; ===============================================
Gui_Number := 1
OffsetX := 50, OffsetY := 25
Xpos := 1000, Ypos := 100
MarginY := 10
Font_Face := "Verdana" ; main font name


; ===============================================
; Main Gui layout
; ===============================================
Gosub, Create_Window ; Jumps to the 'Create_Window' label and continues execution until Return is encountered
Gui, 1:Add, Button, -Tabstop ys wp hp gButton_Settings, Settings
Gui, 1:Show, AutoSize
Return


; ===============================================
;Labels
; ===============================================


;New popup
; ===============================================
Button_NewWindow: 
	WinGetPos, Xpos, Ypos
	Xpos += OffsetX, Ypos += OffsetY

; GUI generation code
; ===============================================
Create_Window:
	Gui, Margin,, 10
	Gui, %Gui_Number%:Default
	Gui, -Caption +Border +AlwaysOnTop
	Gui, Color, cFFFFFF
	Gui, Font, , %Font_Face%
	Gui, Add, Text, xm ym +BackgroundTrans, SCH - [Instance%Gui_Number%]
	Gui, Add, Edit, xm y+10 Uppercase limit10 w80 h25 vIM, IM	
	Gui, Add, Button, Section xs w100 h25 gButton_NewWindow, New Window
	Gui, Font,s15, Wingdings 3
	Gui, Add, Button, -Tabstop ys wp hp gSend_to_Next_Monitor, D
	Gui, Font, ,
	Gui, Font, , %Font_Face%
	Gui, Add, Button, ys wp hp gGuiClose, &Close
	Gui, Show, x%Xpos% y%Ypos% AutoSize, Test
	Gui_Number++
return	
	
GuiClose:
	if (A_GUI = 1)
		ExitApp
	PostMessage, 0x112, 0xF060 
return
	
Button_Settings:	
Return

; Move Windows - switch monitor
; ===============================================
Send_to_Next_Monitor:
Gui, Submit, NoHide
Monitor_pos := 1
If(Monitor_pos = 2)
{
	WinGetPos, Xpos
	Xpos := Xpos - 1000
	WinMove, % Xpos
	Monitor_pos := 1
	; Tooltip, Xpos = %Xpos% -- Monitor = %Monitor_pos% -- 
	; Sleep 5000
	; Tooltip,
}
Else
{
	WinGetPos, Xpos
	Xpos := Xpos + 1000
	WinMove, % Xpos
	Monitor_pos := 2
	; Tooltip, Xpos = %Xpos% -- Monitor = %Monitor_pos% -- 
	; Sleep 5000
	; Tooltip,
}

Return
	
; ===============================================	
;Functions
; ===============================================

; ===============================================
; Hotkeys
; ===============================================
f11::listvars


Basically, I thought that using a flag (Monitor_pos) should be enough to do the job. Getting into SysGetwas too confusing for my declaining wits ...

Thank you very much for your help!
swagfag
Posts: 2610
Joined: 11 Jan 2017, 17:59

Re: WinMove: can't configure GUI button to change monitor  Topic is solved

21 Aug 2018, 08:59

LN 73: Monitor_pos := 1

ure redefining this variable every time the button is pressed. the if-branch is unreachable code
User avatar
KRG-23
Posts: 19
Joined: 07 Jun 2016, 05:45
Location: France

Re: WinMove: can't configure GUI button to change monitor

21 Aug 2018, 09:17

Good lord ... This made the trick, I put Monitor_post := 1 at the end of my GUI creation sub so it's initialised upon launching my script.

Thank you very much Swagfag!
asad41163
Posts: 245
Joined: 29 Jul 2014, 14:31

Re: WinMove: can't configure GUI button to change monitor

22 Aug 2018, 07:51

Welcome my dear colleagues
Please Mr. KRG-23, put the final code here so I can learn from it, because my experience is little.
Thanks

Return to “Ask For Help”

Who is online

Users browsing this forum: Bing [Bot], Google [Bot] and 157 guests