Page 1 of 1

Set MsgBox to display at non-center position

Posted: 24 Dec 2016, 16:41
by WeThotUWasAToad
Hello,

How do you script a MsgBox to display at a specific screen location?

I use the folllowing script to obtain window information as shown:

Code: Select all

^F7::			; Get active window's title & coords		
WinGetActiveStats, `Title, Width, Height, X, Y
MsgBox, Title/Position = "%Title%" `(%X%`, %Y%`, %Width%`, %Height%`)
Return
But I want to be able to specify x & y coords for the MsgBox to open elsewhere rather than at its default center screen positionn.

I tried the following but it only changes the position of the window, not the MsgBox:

Code: Select all

^F7::			; Get active window's title & coords		
WinGetActiveStats, `Title, Width, Height, X, Y
MsgBox, Title/Position = "%Title%" `(%X%`, %Y%`, %Width%`, %Height%`)
	Sleep, 500
WinGetActiveTitle, Title	; want to get the MsgBox title
WinMove, %Title%,, 900, 900	; move the MsgBox
Return
Thanks

Re: Set MsgBox to display at non-center position  Topic is solved

Posted: 24 Dec 2016, 19:21
by Exaskryz

Code: Select all

^2::
WinGetActiveStats, `Title, Width, Height, X, Y
SetTimer, MoveMsgBox, -50
MsgBox, Title/Position = "%Title%" `(%X%`, %Y%`, %Width%`, %Height%`)
return

MoveMsgBox:
WinGetActiveTitle, Title
WinMove, %Title%,, 0, 0
return
You need to use a timer to launch another thread, as the current thread is otherwise paused by MsgBox.

Re: Set MsgBox to display at non-center position

Posted: 24 Dec 2016, 20:03
by WeThotUWasAToad
Thank you mate.

Re: Set MsgBox to display at non-center position

Posted: 24 Dec 2016, 22:09
by FanaticGuru
If you want to place a message box before it appears you can do it with an OnMessage technique as in the thread below:
https://autohotkey.com/boards/viewtopic ... 307#p73307

With this technique you can basically create a special function that is called any time a message box is created. This function can then make all kinds of decisions about how and where message boxes are displayed.

It allows for a lot of possibilities for customizing how message boxes display.

FG

Re: Set MsgBox to display at non-center position

Posted: 24 Dec 2016, 23:32
by hunter99
Hi WeThotUWasAToad ,
FanaticGuru beat me to it, as I was going to post this:

You may want to look at this.
"Moving a Msgbox (revisited)"
Post by FanaticGuru of Feb. 24 2016: https://autohotkey.com/boards/viewtopic.php?t=14303
Which I believe was based on this.
Post by Lexikos of May 2009: https://autohotkey.com/board/topic/4094 ... ntry256089

While you are at it maybe see how to change button labels in msgboxes.
Post by hamlin of July 2010: https://autohotkey.com/board/topic/5627 ... el-change/

Merry Christmas to All , hunter99