So I found a post about how to move a msgbox and it apparently solved someone's problem.
But I can't get it to work. FanaticGuru has a lot of code in his function and I really don't understand why it is all there. If I call a simple function:
MoveMsgBox(WinName)
{
Sleep 1000
IfWinExist, %WinName%
{
WinMove, %WinName%,,%SetHi%, %SetWd%
}
}
IfWinExist is never validated and the WinMove code never executes. Is this something about the function I don't understand?
Moving a Msgbox (revisited)
-
- Posts: 4
- Joined: 15 Feb 2016, 15:15
Re: Moving a Msgbox (revisited)
Is this an AHK MsgBox?
How are you calling the function?
Seeing the code you execute would be a good idea. I'd also like to see what the original code was, because I don't know where the SetHi and SetWd values are coming from? I assume they're set somewhere outside the function as [super-global](https://autohotkey.com/docs/Functions.htm#Locals) variables?
Regardless, here's one way to move the MsgBox:
How are you calling the function?
Seeing the code you execute would be a good idea. I'd also like to see what the original code was, because I don't know where the SetHi and SetWd values are coming from? I assume they're set somewhere outside the function as [super-global](https://autohotkey.com/docs/Functions.htm#Locals) variables?
Regardless, here's one way to move the MsgBox:
Code: Select all
^6::
SetTimer, MoveBox, -50
MsgBox,,MyTitle, Hello
return
MoveBox:
WinMove, MyTitle,, 400, 400, 500, 500
return
-
- Posts: 4
- Joined: 15 Feb 2016, 15:15
Re: Moving a Msgbox (revisited)
So there is a fair amount of code in this whole process, but my problem is since this is being deployed on some tablets, the users are changing the screen % and although I can set the input popups to always be visible, if there is an error message displayed with Msgbox, it can end up off the screen or under the onscreen keyboard. I really wish you could control it's location when you call it. So first I declare these values (used for all input boxes)
......
SetTitleMatchMode, 2 ;Match any portion of the Window title string
SetWorkingDir, C:\DBA Help ;Used for ini file
SetHi=15
SetWd=200
Then when I check an Input box value one of the things I check and want to respond to:
..........................
If (Empnum = "")
{
WinName = Employee Number Missing
MssText = Please start again`nEnter an Employee Number
OnMessage(0x44, "MoveMsgBox")
MsgBox, 0, %WinName%,%MssText%
Exit
}
So OnMessage (which gets called with no problem) using my function
MoveMsgBox is:
.................................................
MoveMsgBox(WinName)
{
Sleep 1000
IfWinExist, %WinName%
{
WinMove, %WinName%,,%SetHi%, %SetWd%
}
}
This, I thought, is following the format of the SOLVED issue I found on this board about moving a Msgbox. But as I said, it doesn't work.
Does all that help?
Thanks for responding.
......
SetTitleMatchMode, 2 ;Match any portion of the Window title string
SetWorkingDir, C:\DBA Help ;Used for ini file
SetHi=15
SetWd=200
Then when I check an Input box value one of the things I check and want to respond to:
..........................
If (Empnum = "")
{
WinName = Employee Number Missing
MssText = Please start again`nEnter an Employee Number
OnMessage(0x44, "MoveMsgBox")
MsgBox, 0, %WinName%,%MssText%
Exit
}
So OnMessage (which gets called with no problem) using my function
MoveMsgBox is:
.................................................
MoveMsgBox(WinName)
{
Sleep 1000
IfWinExist, %WinName%
{
WinMove, %WinName%,,%SetHi%, %SetWd%
}
}
This, I thought, is following the format of the SOLVED issue I found on this board about moving a Msgbox. But as I said, it doesn't work.
Does all that help?
Thanks for responding.
-
- Posts: 319
- Joined: 23 Jan 2016, 23:03
Re: Moving a Msgbox (revisited)
SetHi and SetWd are being treated as local variables
Code: Select all
SetTitleMatchMode, 2 ;Match any portion of the Window title string
SetWorkingDir, C:\DBA Help ;Used for ini file
SetHi=15
SetWd=200
Then when I check an Input box value one of the things I check and want to respond to:
..........................
If (Empnum = "")
{
WinName = Employee Number Missing
MssText = Please start again`nEnter an Employee Number
OnMessage(0x44, "MoveMsgBox")
MsgBox, 0, %WinName%,%MssText%
Exit
}
So OnMessage (which gets called with no problem) using my function
MoveMsgBox is:
.................................................
MoveMsgBox(WinName)
{
global ; ASSUME GLOBAL VARIABLES
Sleep 1000
IfWinExist, %WinName%
{
WinMove, %WinName%,,%SetHi%, %SetWd%
}
}
-
- Posts: 4
- Joined: 15 Feb 2016, 15:15
Re: Moving a Msgbox (revisited)
wizardzedd,
I added the 'global' reference as you suggested. I didn't make any difference, the WinMove action still does not get executed.
I added the 'global' reference as you suggested. I didn't make any difference, the WinMove action still does not get executed.
-
- Posts: 319
- Joined: 23 Jan 2016, 23:03
Re: Moving a Msgbox (revisited)
We fixed one problem with adding global, but the problem now seems to be with the message. I'm still not sure what the 0x44 message is... but it is called before the window exists. Here is a way that works by using a timer instead.
Code: Select all
SetHi=15
SetWd=200
WinName = Employee Number Missing
MssText = Please start again`nEnter an Employee Number
setTimer, MoveMsgBox, -50
MsgBox, 0, %WinName%,%MssText%
Exit
MoveMsgBox()
{
global
IfWinExist, %WinName%
WinMove, %WinName%,,%SetHi%, %SetWd%
}
-
- Posts: 4
- Joined: 15 Feb 2016, 15:15
Re: Moving a Msgbox (revisited)
What I understood is that OnMessage was a standard way to execute code when a message, like a Msgbox, popped up on the screen. Apparently 0x44 references the Msgbox type of popup. But since no one has come forward to comment on that I'll try the setTimer method. It will require dozens of setTimer calls because I need to setTimer off after every Msgbox appears. Thanks for your help.
- FanaticGuru
- Posts: 1945
- Joined: 30 Sep 2013, 22:25
Re: Moving a Msgbox (revisited)
If you just want a function that puts msgbox dialogs at an X, Y when created using OnMessage:
With lots of comments.
This is kind of overkill for a simple move of one dialog but the power of the 0x44 method is that you can create a function that will figure out where to put an msgbox dialog when it is created.
It is like creating a special rule for where to put dialogs. In my example I turn on the special rule OnMessage(0x44, "Move_MsgBox") right before creating a msgbox and then turn it back off. But you could turn on the rule at the top of a script and never turn it off and then all dialogs could be moved based on code in the function called. The function code could be very sophisticated and always put the dialogs in the perfect place. Which sounds like what you need to do if you are trying to get dialogs to appear properly in different circumstances.
FG
Code: Select all
MsgBox_XY("Hello", 30,50)
MsgBox_XY(Message, X, Y)
{
global MsgBox_X := X, MsgBox_Y := Y ; Make global for other function
OnMessage(0x44, "Move_MsgBox") ; When a dialog appears run Move_MsgBox
MsgBox, % Message
OnMessage(0x44, "") ; When a dialog appears do nothing special
}
Move_MsgBox(P)
{
global MsgBox_X, MsgBox_Y ; Have to be global to get value set in other function
if (P = 1027) ; Make sure it is a AHK dialog
{
Process, Exist ; Get the Process PID into ErrorLevel
DetectHiddenWindows, % (Setting_A_DetectHiddenWindows := A_DetectHiddenWindows) ? "On" : ; Round about way of changing DetectHiddenWindows settting and saving the setting all in one line
if WinExist("ahk_class #32770 ahk_pid " ErrorLevel) ; Make sure dialog still exist
WinMove, MsgBox_X, MsgBox_Y ; Move the default window from above WinExist
DetectHiddenWindows, %Setting_A_DetectHiddenWindows% ; Set the DetectHiddenWindows setting back to what it was before function changed it
}
}
This is kind of overkill for a simple move of one dialog but the power of the 0x44 method is that you can create a function that will figure out where to put an msgbox dialog when it is created.
It is like creating a special rule for where to put dialogs. In my example I turn on the special rule OnMessage(0x44, "Move_MsgBox") right before creating a msgbox and then turn it back off. But you could turn on the rule at the top of a script and never turn it off and then all dialogs could be moved based on code in the function called. The function code could be very sophisticated and always put the dialogs in the perfect place. Which sounds like what you need to do if you are trying to get dialogs to appear properly in different circumstances.
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
- FanaticGuru
- Posts: 1945
- Joined: 30 Sep 2013, 22:25
Re: Moving a Msgbox (revisited)
For example you could put the below code in the top of everyone of your scripts and it would have very little effect on any MsgBox commands throughout the script UNLESS a Outlook email was open then it would center any MsgBox on the Outlook email.
Maybe you don't like the middle of the screen as the default.
All the MsgBox in this script will be at 25,25.
FG
Code: Select all
OnMessage(0x44, "Center_MsgBox_Email")
Center_MsgBox_Email(P)
{
if (P = 1027)
{
if WinExist("ahk_class rctrl_renwnd32")
{
WinGet, State, MinMax
if !(State = -1)
{
WinGetPos, eX, eY, eW, eH
Process, Exist
DetectHiddenWindows, % (Setting_A_DetectHiddenWindows := A_DetectHiddenWindows) ? "On" :
if WinExist("ahk_class #32770 ahk_pid " ErrorLevel)
{
WinGetPos,,,mW,mH
WinMove, (eW-mW)/2 + eX, (eH-mH)/2 + eY
}
DetectHiddenWindows, %Setting_A_DetectHiddenWindows%
}
}
}
}
Code: Select all
OnMessage(0x44, "Move_MsgBox")
Move_MsgBox(P)
{
if (P = 1027)
{
Process, Exist
DetectHiddenWindows, % (Setting_A_DetectHiddenWindows := A_DetectHiddenWindows) ? "On" :
if WinExist("ahk_class #32770 ahk_pid " ErrorLevel)
WinMove, 25, 25
DetectHiddenWindows, %Setting_A_DetectHiddenWindows%
}
}
MsgBox Put All MsgBox at 25,25
MsgBox Yea, All of them
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
Re: Moving a Msgbox (revisited)
This is a much better solution than timers!
Any idea what the message being sent from InputBox is?
I know I can use the parameter for all the dozens of inputboxes I have in my AHK but this would be a cool global fix.
I'm trying to learn from the tutorial how to find that out but got stuck.
OnMessage(0x??, "Move_InputBox")
Any idea what the message being sent from InputBox is?
I know I can use the parameter for all the dozens of inputboxes I have in my AHK but this would be a cool global fix.
I'm trying to learn from the tutorial how to find that out but got stuck.
OnMessage(0x??, "Move_InputBox")
Who is online
Users browsing this forum: AlFlo and 133 guests