The following is NOT working
Code: Select all
#z::
MsgBox,,MEMO,Pray everyday
Sleep 6000
WinActivate MEMO
WinMove MEMO,,1155,220,255,580
return
Code: Select all
#z::
MsgBox,,MEMO,Pray everyday
Sleep 6000
WinActivate MEMO
WinMove MEMO,,1155,220,255,580
return
The problem is that as soon as the code encounters the MsgBox the thread pauses while the message is open. Once you hit OK the thread continues and tries to move the box after it is closed.AmDeG 11 wrote:Code: Select all
#z:: MsgBox,,MEMO,Pray everyday Sleep 6000 WinActivate MEMO WinMove MEMO,,1155,220,255,580 return
Code: Select all
SetTimer, Move_MsgBox, -50
MsgBox,,MEMO,Pray everyday
ExitApp
Move_MsgBox:
WinActivate MEMO
WinMove MEMO,,1155,220
return
Code: Select all
MsgBox_XY(30,50, "Hello")
MsgBoxOpt_XY(100,100,,"MEMO","Pray everyday")
MsgBox_XY(X, Y, Text:="")
{
global MsgBox_X := X, MsgBox_Y := Y ; Make global for other function
OnMessage(0x44, "Move_MsgBox") ; When a dialog appears run Move_MsgBox
MsgBox, % Text
OnMessage(0x44, "") ; When a dialog appears do nothing special
}
MsgBoxOpt_XY(X, Y, Options:="", Title:="", Text:="", Timeout:="")
{
global MsgBox_X := X, MsgBox_Y := Y ; Make global for other function
OnMessage(0x44, "Move_MsgBox") ; When a dialog appears run Move_MsgBox
MsgBox, % Options, % Title, % Text, % Timeout
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
}
}
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 HCBT_CREATEWND := 3, WH_CBT := 5
, hHook := DllCall("SetWindowsHookEx", Int, WH_CBT
, Ptr, RegisterCallback("CBTProc", "Fast")
, Ptr, 0
, UInt, DllCall("GetCurrentThreadId") , Ptr)
if (nCode = HCBT_CREATEWND) {
VarSetCapacity(WinClass, 256)
DllCall("GetClassName", Ptr, hwnd := wp, Str, WinClass, Int, 256)
if (WinClass != "#32770")
Return
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") )
}
}
Yea, you could do it this way if you don't mind limiting perfectly valid message box titles.teadrinker wrote:One more example. Just add the function CBTProc() to your script, and then set coordinates of MsgBox like in the code below, if you need.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 HCBT_CREATEWND := 3, WH_CBT := 5 , hHook := DllCall("SetWindowsHookEx", Int, WH_CBT , Ptr, RegisterCallback("CBTProc", "Fast") , Ptr, 0 , UInt, DllCall("GetCurrentThreadId") , Ptr) if (nCode = HCBT_CREATEWND) { VarSetCapacity(WinClass, 256) DllCall("GetClassName", Ptr, hwnd := wp, Str, WinClass, Int, 256) if (WinClass != "#32770") Return 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") ) } }
teadrinker's code is probably better. It is simpler to use. You put their function in your script and all MsgBox commands in that script will behave as normal unless you put coordinates in the format of |x10 y20 at the end of the title for the message box.AmDeG 11 wrote:sorry, you are the experts I'm a layperson. Is it better to follow teadrinker code instead of FanatiGuru or teadrinker code could affect other MsgBoxes at other scripts?
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)
}
Code: Select all
SetTimer, Label, -1
MsgBox, Stuffs
Return
Label:
WinWaitActive, MsgTitle
WinMove, A position you want
Return
Can you show your full code?AmDeG 11 wrote:it is not working this: |x500 y0
Code: Select all
NumpadUp::
;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!"
MsgBox,, |x50 y70, RAlt-LWin Taskbar hide/unhide`n`n +^ESC TaskManager`n +^F1 Programs&Features
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, WinClas vs, 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)
}