So I have a script to create an email in Outlook, then ask the user if they'd like to add an attachment.
How can I get the message box to open on top of the email itself wherever it is on the screen, as in my case my emails are loaded on my second monitor and the message box always opens on the default monitor which is my left screen. Likewise some people may have it create the email on their left monitor so I don't want it to just default to the right monitor, instead I would like a way to have it always open on top of the email. Is this even possible?
**EDITED FOR CLARITY**
[SOLVED] MsgBox in center of active window?
- Iomega0318
- Posts: 83
- Joined: 06 Apr 2015, 14:56
- Facebook: jonimpson
- Google: jonimpson
- GitHub: Iomega0318
- Location: Wolfforth, TX
- Contact:
[SOLVED] MsgBox in center of active window?
Last edited by Iomega0318 on 13 Apr 2015, 12:50, edited 2 times in total.
Re: MsgBox in center of active window?
The answer to this is easily found by reading the Help Files:
http://ahkscript.org/docs/commands/MsgBox.htm
Hint: System Modal
http://ahkscript.org/docs/commands/MsgBox.htm
Hint: System Modal
- Iomega0318
- Posts: 83
- Joined: 06 Apr 2015, 14:56
- Facebook: jonimpson
- Google: jonimpson
- GitHub: Iomega0318
- Location: Wolfforth, TX
- Contact:
Re: MsgBox in center of active window?
Thank you, I know about that. However it is not what I wanted. I edited my post for clarity that was my mistake :)ahkcoder wrote:The answer to this is easily found by reading the Help Files:
http://ahkscript.org/docs/commands/MsgBox.htm
Hint: System Modal
- FanaticGuru
- Posts: 1830
- Joined: 30 Sep 2013, 22:25
Re: MsgBox in center of active window?
MsgBox is not really designed for positioning. Creating your own GUI allows for a lot more control.Iomega0318 wrote:So I have a script to create an email in Outlook, then ask the user if they'd like to add an attachment.
How can I get the message box to open on top of the email itself wherever it is on the screen, as in my case my emails are loaded on my second monitor and the message box always opens on the default monitor which is my left screen. Likewise some people may have it create the email on their left monitor so I don't want it to just default to the right monitor, instead I would like a way to have it always open on top of the email. Is this even possible?
**EDITED FOR CLARITY**
But out of amusement here is a script to change the position where MsgBox will appear.
Code: Select all
F12::
OnMessage(0x44, "Center_MsgBox_Email")
MsgBox, 4096, Email Centering Script, Center of Email if exist and not minimized
OnMessage(0x44,"")
MsgBox, 4096, Email Centering Script, Back to default of center of screen
return
Center_MsgBox_Email(P)
{
if (P = 1027)
{
if WinExist("ahk_class rctrl_renwnd32") ; Window to Center In
{
WinGet, State, MinMax
if !(State = -1)
{
WinGetPos, eX, eY, eW, eH
Process, Exist
DetectHiddenWindows, On
if WinExist("ahk_class #32770 ahk_pid " ErrorLevel)
{
WinGetPos,,,mW,mH
WinMove, (eW-mW)/2 + eX, (eH-mH)/2 + eY
}
}
}
}
}
Esc::ExitApp
It should work on multiply monitors but I cannot test it.
It can easily be changed to center in any Window if you know the WinTitle to locate it.
FG
Last edited by FanaticGuru on 10 Apr 2015, 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
[Class] WinHook - Create Window Shell Hooks and Window Event Hooks
[Function] Timer - Create and Manage Timers
AHK Startup - Consolidate Multiply AHK Scripts with one Tray Icon
[Class] WinHook - Create Window Shell Hooks and Window Event Hooks
[Function] Timer - Create and Manage Timers
Re: MsgBox in center of active window?
Haha. You beat me to it Guru. Anyway, here's my implementation.
Code: Select all
Gui, +AlwaysOnTop +ToolWindow -Caption +Border
Gui, Color, White
Gui, Font, s11, Segoe UI
Gui, Add, Text,, % "Do you want to add an attachment?"
Gui, Add, Text ; spacer
Gui, Add, Button, Section w50 gYes, Yes
Gui, Add, Button, ys w50 gNo, No
return
F1::
{
WinGetPos, mX, mY, mW, mH, Untitled - Message (HTML)
Gui, Show, % "x" mX+(mW/2)-100 " y" mY+(mH/2)-50 " w300 h125"
return
}
Yes:
{
; attachment business here
return
}
No:
{
Gui, Hide
; return
ExitApp ; uncomment line above and comment this out to keep this active
}
Re: MsgBox in center of active window?
Code: Select all
attachment:
WinGetPos, outlookX, outlookY, outlookW, outlookH, Inbox
WinActivate, Inbox
SetTimer, CenterMsgBox, 10
Msgbox, 4, Add an attachment?, would you like to add an attachment?
IfMsgBox No
{
SetTimer, CenterMsgBox, Off
return
}
;...
return
CenterMsgBox:
IfWinExist, Add an attachment?
{
WinGetPos, , , msg_W, msg_H, Add an attachment?
SetTimer, CenterMsgBox, Off
WinMove, Add an attachment?, , (outlookW/2+outlookX-(msg_W/2)), (outlookH/2+outlookY-(msg_H/2))
}
return
- Iomega0318
- Posts: 83
- Joined: 06 Apr 2015, 14:56
- Facebook: jonimpson
- Google: jonimpson
- GitHub: Iomega0318
- Location: Wolfforth, TX
- Contact:
Re: MsgBox in center of active window?
You guys are awesome! and fast :)
I ended up going with FanaticGuru's example as I liked the way it still used the standard windows type message box, but fischgeek yours was nice as well! Other than that it works great and does exactly what I need. I think I am just about done with this script! Now I just have to decide which one of these to use lol-or-
I ended up going with FanaticGuru's example as I liked the way it still used the standard windows type message box, but fischgeek yours was nice as well! Other than that it works great and does exactly what I need. I think I am just about done with this script! Now I just have to decide which one of these to use lol
Code: Select all
SendInput, {Alt}n
SendInput, AF
Sleep, 1000
SendInput, M:\Folder To Open
SendInput, {Enter}
Code: Select all
Run, M:\Folder To Open