Moving MSGBOX to different monitor.
Moving MSGBOX to different monitor.
I have a couple of scripts. Evertime there is an Input box, it always pops up on my main monitor (center) I would like to move it to my Right side monitor.
Any ideas?
thanks in advance, you all sexy AHK coders.
Any ideas?
thanks in advance, you all sexy AHK coders.
Re: Moving MSGBOX to different monitor.
Your title says "MSGBOX" but your post says "Input box". If it's an InputBox, it's very easy to have it appear exactly where you want by specifying the x and y coordinates in the InputBox command:
InputBox, OutputVar , Title, Prompt, HIDE, Width, Height, X, Y, Font, Timeout, Default
A MsgBox can also be moved, although not as straightforward, but I can show you if you need to move a MsgBox as well.
InputBox, OutputVar , Title, Prompt, HIDE, Width, Height, X, Y, Font, Timeout, Default
A MsgBox can also be moved, although not as straightforward, but I can show you if you need to move a MsgBox as well.
Re: Moving MSGBOX to different monitor.
Here is a method for moving a MsgBox:
It creates a second thread via SetTimer that will act after MsgBox appears. You can't simply put the WinMove immediately after the MsgBox command because it won't get to that line until the MsgBox is dismissed.
Code: Select all
SetTimer, MoveMsgBox, -50
MsgBox, I have been moved to 0,0
return
MoveMsgBox:
WinWait, ahk_class #32770 ahk_exe AutoHotkey.exe
WinMove, ahk_class #32770 ahk_exe AutoHotkey.exe,, 0, 0
return
Re: Moving MSGBOX to different monitor.
I'm interested in any responses to the OP.
Can I display the InputBox on on my second monitor?
It defaults to the main monitor.
Maybe a way to have it displayed on the monitor where the mouse is currently?
Can I display the InputBox on on my second monitor?
It defaults to the main monitor.
Maybe a way to have it displayed on the monitor where the mouse is currently?
Re: Moving MSGBOX to different monitor.
@EnjoyRC - Try the script below. I was only able to test it on a single-monitor setup, but I believe it should work.
Code: Select all
Name := InputBoxOnMouseMonitor("Welcome", "Please enter your name:")
MsgBox, % "Hello, " Name
return
InputBoxOnMouseMonitor(Title:="", Prompt:="", Hide:="", Width:="", Height:="", Font:="", Locale:="", Timeout:="", Default:="") {
; centers InputBox on monitor where mouse is located
; returns value entered by user
CM := A_CoordModeMouse
CoordMode, Mouse, Screen
MouseGetPos, MX, MY
CoordMode, Mouse, % CM
SysGet, MonCount, MonitorCount
loop, % MonCount {
SysGet, Mon, Monitor, % A_Index
if (MX >= MonLeft) && (MX <= MonRight) && (MY >= MonTop) && (MY <= MonBottom) {
MonNum := A_Index
break
}
}
X := (MonRight - MonLeft) / 2 - (Width = "" ? 375 : Width) / 2
Y := (MonBottom - MonTop) / 2 - (Height = "" ? 189 : Height) / 2
InputBox, Output, % Title, % Prompt, % Hide, Width, Height, X, Y, % Locale, Timeout, % Default
return Output
}
Re: Moving MSGBOX to different monitor.
I can see what you're trying to do here. But, it pops up on the main monitor regardless of where the mouse is. What a great start/idea you're engineering here. I'm gonna see if I can make it work too.
- FanaticGuru
- Posts: 1906
- Joined: 30 Sep 2013, 22:25
Re: Moving MSGBOX to different monitor.
boiler wrote: ↑18 Sep 2019, 17:41Here is a method for moving a MsgBox:It creates a second thread via SetTimer that will act after MsgBox appears. You can't simply put the WinMove immediately after the MsgBox command because it won't get to that line until the MsgBox is dismissed.Code: Select all
SetTimer, MoveMsgBox, -50 MsgBox, I have been moved to 0,0 return MoveMsgBox: WinWait, ahk_class #32770 ahk_exe AutoHotkey.exe WinMove, ahk_class #32770 ahk_exe AutoHotkey.exe,, 0, 0 return
Just because I already have it.
Here is a cool (cool meaning complex and hard to understand) method of putting a MsgBox where you want it. It is like magic: most people don't understand how the trick is done, it just seems to happen.
Code: Select all
MsgBox, This MessageBox will appear in the centre of screen, as usual
MsgBox,, |x50 y70, This MessageBox will appear in coords x = 50 y = 70 without a title.
MsgBox,, Hello!|x500 y0, This MessageBox will appear in coords x = 500 y = 0 with the title "Hello!"
Return
CBTProc(nCode, wp, lp) {
static WH_CBT := 5, HCBT_CREATEWND := 3
, dummy := OnExit( Func("CBTProc").Bind("OnExit") )
, hHook := DllCall("SetWindowsHookEx", Int, WH_CBT
, Ptr, RegisterCallback("CBTProc", "Fast")
, Ptr, 0
, UInt, DllCall("GetCurrentThreadId") , Ptr)
if (nCode = "OnExit") {
DllCall("UnhookWindowsHookEx", Ptr, hHook)
return
}
if (nCode = HCBT_CREATEWND) {
VarSetCapacity(WinClass, 256)
DllCall("GetClassName", Ptr, hwnd := wp, Str, WinClass, Int, 256)
if (WinClass = "#32770") {
pCREATESTRUCT := NumGet(lp+0)
sTitle := StrGet( pTitle := NumGet(pCREATESTRUCT + A_PtrSize * 5 + 4 * 4), "UTF-16" )
RegExMatch(sTitle, "^(.*)\|(?:x(\d+)\s?)?(?:y(\d+))?$", match)
( !(match2 = "" && match3 = "") && StrPut(match1, pTitle, "UTF-16") )
( match2 != "" && NumPut(match2, pCREATESTRUCT + A_PtrSize * 4 + 4 * 3, "Int") )
( match3 != "" && NumPut(match3, pCREATESTRUCT + A_PtrSize * 4 + 4 * 2, "Int") )
}
}
Return DllCall("CallNextHookEx", Ptr, 0, Int, nCode, Ptr, wp, Ptr, lp)
}
FG
Edit: Cool Magic MsgBox by @teadrinker here viewtopic.php?p=172566#p172566
Last edited by FanaticGuru on 12 Aug 2022, 17:11, edited 1 time in total.
Hotkey Help - Help Dialog for Currently Running AHK Scripts
AHK Startup - Consolidate Multiply AHK Scripts with one Tray Icon
Hotstring Manager - Create and Manage Hotstrings
[Class] WinHook - Create Window Shell Hooks and Window Event Hooks
AHK Startup - Consolidate Multiply AHK Scripts with one Tray Icon
Hotstring Manager - Create and Manage Hotstrings
[Class] WinHook - Create Window Shell Hooks and Window Event Hooks
Re: Moving MSGBOX to different monitor.
That is cool. Thanks!FanaticGuru wrote: ↑ Here is a cool (cool meaning complex and hard to understand) method of putting a MsgBox where you want it. It is like magic: most people don't understand how the trick is done, it just seems to happen.
...
You put this function anywhere in the script and suddenly MsgBox has a new parameter syntax. And you don't even have to ever call the function.
Re: Moving MSGBOX to different monitor.
I suggest using the self-deleting timer object method Lexikos described here:
viewtopic.php?t=13010#p66731
It's v2 friendly and useful with many other scenarios.
I used this to move MsgBox around as in:
viewtopic.php?t=13010#p66731
It's v2 friendly and useful with many other scenarios.
I used this to move MsgBox around as in:
Code: Select all
; MASTER OBJECT https://www.autohotkey.com/boards/viewtopic.php?t=13010#p66731
class SelfDeletingTimer {
__New(period, fn, prms*) {
this.fn := IsObject(fn) ? fn : Func(fn)
this.prms := prms
SetTimer % this, % period
}
Call() {
this.fn.Call(this.prms*)
SetTimer % this, Delete
}
}
;WINDOW MOVE FUNCTION
windowMoveFunction(windowname,windowx,windowy,windowl,windowh){
WinMove, %windowname%,,%windowx%,%windowy%,%windowl%,%windowh%
}
F10::
new SelfDeletingTimer(-100, "windowMoveFunction", "A","100","300","","")
MsgBox
- FanaticGuru
- Posts: 1906
- Joined: 30 Sep 2013, 22:25
Re: Moving MSGBOX to different monitor.
b0dhimind wrote: ↑11 Aug 2022, 23:06I suggest using the self-deleting timer object method Lexikos described here:
viewtopic.php?t=13010#p66731
It's v2 friendly and useful with many other scenarios.
I used this to move MsgBox around as in:
Code: Select all
; MASTER OBJECT https://www.autohotkey.com/boards/viewtopic.php?t=13010#p66731 class SelfDeletingTimer { __New(period, fn, prms*) { this.fn := IsObject(fn) ? fn : Func(fn) this.prms := prms SetTimer % this, % period } Call() { this.fn.Call(this.prms*) SetTimer % this, Delete } } ;WINDOW MOVE FUNCTION windowMoveFunction(windowname,windowx,windowy,windowl,windowh){ WinMove, %windowname%,,%windowx%,%windowy%,%windowl%,%windowh% } F10:: new SelfDeletingTimer(-100, "windowMoveFunction", "A","100","300","","") MsgBox
A fancier SetTimer and Move that is an interesting technique but far from cool magic.
Cool magic is mind controlling AutoHotkey so that it puts the MsgBox where you want in the first place. No moving, just creating a MsgBox at a location without any visual ugliness.
FG
Hotkey Help - Help Dialog for Currently Running AHK Scripts
AHK Startup - Consolidate Multiply AHK Scripts with one Tray Icon
Hotstring Manager - Create and Manage Hotstrings
[Class] WinHook - Create Window Shell Hooks and Window Event Hooks
AHK Startup - Consolidate Multiply AHK Scripts with one Tray Icon
Hotstring Manager - Create and Manage Hotstrings
[Class] WinHook - Create Window Shell Hooks and Window Event Hooks