Messagebox stays in front Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
foxhunter
Posts: 72
Joined: 04 Aug 2016, 04:27

Messagebox stays in front

14 Oct 2016, 12:20

I've this example for a messagebox with specific buttontexts (using functions without global variables). Unfortunalely it stays always in front, as the SetTimer, %obj% , off doesn't work as expected. Does somebody has a hint?

Code: Select all



MyMsgBox(4, "Add or Delete", "Choose a button:", "&Add|Delete")

IfMsgBox, YES

    MsgBox, You chose Add.

else

    MsgBox, You chose Delete.



ChangeMyMsgBoxButtonNames(obj)

{

                IfWinNotExist, % obj.MyButtonTitle

                               return  ; Keep waiting.

                              

                SetTimer, %obj% , off          ;<<---- Somewhere here is the problem....

                WinActivate

 

                Loop, % obj.MyButtonText0

                               ControlSetText, Button%a_index%, % obj.MyButtonText[a_index]

}

 

MyMsgBox(options="", Title="", Text="", ButtonNames="", timeout="")

{

                ;global ; make vars global

                MyOptions := options 

                MyButtonText := []

               

                StringSplit MyButtonText, ButtonNames, |

                MyButtonTitle := title

 

                payload:={}

                payload.MyButtonTitle := MyButtonTitle

                payload.MyOptions := MyOptions

                payload.MyButtonText0 := MyButtonText0

                Loop, % MyButtonText0

                               payload.MyButtonText[a_index] := MyButtonText%A_index%

               

                fn := Func("ChangeMyMsgBoxButtonNames").bind(payload)

                SetTimer, %fn%, 1

                MsgBox, % options,% Title,% Text,% Timeout

}


User avatar
Capn Odin
Posts: 1352
Joined: 23 Feb 2016, 19:45
Location: Denmark
Contact:

Re: Messagebox stays in front  Topic is solved

14 Oct 2016, 13:14

From the SetTimer documentation:
[v1.1.01+]: If Label is omitted, A_ThisLabel will be used. For example, SetTimer,, Off can be used inside a timer subroutine to turn off the timer, while SetTimer,, 1000 would either update the current timer's Period or set a new timer using the label which is currently running.
[v1.1.24+]: If A_ThisLabel is empty but the current thread was launched by a timer, that timer is used. This is useful for timers which launch functions or function objects.
Try using SetTimer, , off.

Code: Select all

MyMsgBox(4, "Add or Delete", "Choose a button:", "&Add|Delete")

IfMsgBox, YES
    MsgBox, You chose Add.
else
    MsgBox, You chose Delete.

ChangeMyMsgBoxButtonNames(obj){
	ToolTip, hej
	IfWinNotExist, % obj.MyButtonTitle
		return  ; Keep waiting.
	
	SetTimer, , off          ;<<---- Somewhere here is the problem....
	WinActivate
	Loop, % obj.MyButtonText0
		ControlSetText, Button%a_index%, % obj.MyButtonText[a_index]
}

MyMsgBox(options="", Title="", Text="", ButtonNames="", timeout=""){
	;global ; make vars global

	MyOptions := options 
	MyButtonText := []

	StringSplit MyButtonText, ButtonNames, |
	
	MyButtonTitle := title
	
	payload:={}

	payload.MyButtonTitle := MyButtonTitle
	payload.MyOptions := MyOptions
	payload.MyButtonText0 := MyButtonText0

	Loop, % MyButtonText0
		payload.MyButtonText[a_index] := MyButtonText%A_index%

	fn := Func("ChangeMyMsgBoxButtonNames").bind(payload)
	
	SetTimer, %fn%, 1

	MsgBox, % options,% Title,% Text,% Timeout
}
Please excuse my spelling I am dyslexic.
foxhunter
Posts: 72
Joined: 04 Aug 2016, 04:27

Re: Messagebox stays in front

15 Oct 2016, 04:23

Thanks for the help..I was sure I tested Settimer,,off , but obviously not...

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: No registered users and 169 guests