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

Get help with using AutoHotkey and its commands and hotkeys
WeThotUWasAToad
Posts: 295
Joined: 19 Nov 2013, 08:44

Set MsgBox to display at non-center position

24 Dec 2016, 16:41

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
A ------------------------------ [A LOT OF SPACE] ------------------------------ LOT

"ALOT" is not a word. It never has been a word and it never will be a word.
"A LOT" is 2 words. Remember it as though there's [A LOT OF SPACE] between them.
User avatar
Exaskryz
Posts: 2876
Joined: 17 Oct 2015, 20:28

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

24 Dec 2016, 19:21

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.
WeThotUWasAToad
Posts: 295
Joined: 19 Nov 2013, 08:44

Re: Set MsgBox to display at non-center position

24 Dec 2016, 20:03

Thank you mate.
A ------------------------------ [A LOT OF SPACE] ------------------------------ LOT

"ALOT" is not a word. It never has been a word and it never will be a word.
"A LOT" is 2 words. Remember it as though there's [A LOT OF SPACE] between them.
FanaticGuru
Posts: 1410
Joined: 30 Sep 2013, 22:25

Re: Set MsgBox to display at non-center position

24 Dec 2016, 22:09

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
Hotkey Help - Help Dialog for Currently Running AHK Scripts

AHK Startup - Consolidate Multiply AHK Scripts with one Tray Icon

[Function] Timer - Create and Manage Timers
hunter99
Posts: 128
Joined: 20 Jan 2014, 17:57

Re: Set MsgBox to display at non-center position

24 Dec 2016, 23:32

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

Return to “Ask For Help”

Who is online

Users browsing this forum: Alexander2, Epialis, ILP0000 and 56 guests