Jump to content

Move MsgBox


eltorro
 Share

Recommended Posts

I see people asking how to put a message box somewhere other than the screen center.

Here is yet another way to do it.

Add the globals to your script and call the _MessageBox function.

The first four parameters are the same as MsgBox. The last two are the x and y pos to move the MsgBox to.

_MessageBox(0,"Test","This is just a test :)",0,10,10) ;move the MsgBox to 10,10
oÝ÷ Ù8b²ç_§$²Ê&yê뢷!yÉ"ájwex%G¢¶Úv)éºÚ.¶Û¢éݱënël¥vè¾'^zz.h©Ü!jܨ»§µ«­¢+Ø)±½°
½¹ÍÐÀÌØíAA}Q%5I}%ôääää)±½°
½¹ÍÐÀÌØí]5}Q%5HôÁàÀÄÄÌ)±½°ÀÌØíQ%5I9   1ô±Í)±½°ÀÌØí5½Ùô±Í)±½°ÀÌØí5   =a}%9=lÕt()}5ÍÍ  ½à À°ÅÕ½ÐíQÍÐÅÕ½Ðì°ÅÕ½ÐíQÍÑ5Í  ½àÅÕ½Ðì°À°ÄÀ°ÄÀ¤((((ìôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôô)Õ¹}5ÍÍ ½à ÀÌØí±°ÀÌØíѥѱ°ÀÌØíµÍ°ÀÌØíÑ¥µÈôÀ°ÀÌØíàô´Ä°ÀÌØíäô´Ä¤)U%I¥ÍÑÉ5Í ÀÌØí]5}Q%5H°ÅÕ½ÐíQ¥µÉ
±±    ¬ÅÕ½Ðì¤)1½°ÀÌØíµ½àôU%
ÉÑ ÅÕ½Ðí}5ÍÍ   ½àÅÕ½Ðì°Ä°Ä¤)1½°ÀÌØíÙ}ÉÐôÀ(ÀÌØí5 =a}%9=lÁtôÀÌØíѥѱ(ÀÌØí5  =a}%9=lÅtôÀÌØíµÍ(ÀÌØí5  =a}%9=lÉtôÀÌØíà(ÀÌØí5    =a}%9=lÍtôÀÌØíä(ÀÌØí5    =a}%9=lÑtôÀÌØíµ½à)}MÑÉÑQ¥µÈ¡]¥¹Ñ!¹± ÀÌØíµ½à¤°ÀÌØíAA}Q%5I}%¤(ÀÌØíÙ}ÉÐô5Í ½à ÀÌØí±°ÀÌØíѥѱ°ÀÌØíµÍ°ÀÌØíÑ¥µÈ¤)}MѽÁQ¥µÈ¡]¥¹Ñ!¹± ÀÌØíµ½à¤°ÀÌØíAA}Q%5I}%¤)U%I¥ÍÑÉ5Í ÀÌØí]5}Q%5H°ÅÕ½ÐìÅÕ½Ðì¤)IÑÕɸÀÌØíÙ}ÉÐ)¹Õ¹((ìôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôô)Õ¹}5½Ù5Í  ½à ¤(%]¥¹á¥ÍÑÌ ÀÌØí5  =a}%9=lÁt°ÀÌØí5   =a}%9=lÅt¤Q¡¸(%ÀÌØí5    =a}%9=lÉtÐì´Ä¹ÀÌØí5   =a}%9=lÍtÐì´ÄQ¡¸(]¥¹5½Ù ÀÌØí5    =a}%9=lÁt°ÀÌØí5   =a}%9=lÅt°ÀÌØí5   =a}%9=lÉt°ÀÌØí5   =a}%9=lÍt¤(¹%(}MѽÁQ¥µÈ¡]¥¹Ñ!¹± ÀÌØí5    =a}%9=lÑt¤°ÀÌØíAA}Q%5I}%¤(ÀÌØí5½ÙôQÉÕ(¹%)¹Õ¹(ìôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôô)Õ¹}MÑÉÑQ¥µÈ ÀÌØí¡]¹U$°ÀÌØí¥Q¥µÉ%°ÀÌØí¥%¹ÑÉÙ°ôĤ(¥9½Ð%Í!]¹ ÀÌØí¡]¹U$¤Ñ¡¸ÀÌØí¡]¹U$ô!]¹ ÀÌØí¡]¹U$¤(%ÀÌØíQ%5I9    1ôQÉÕQ¡¸}MѽÁQ¥µÈ ÀÌØí¡]¹U$°ÀÌØí¥Q¥µÉ%¤(1½°ÀÌØíÉÑÙ°õ±±
±° ÅÕ½ÐíUÍÈÌȹ±°ÅÕ½Ðì°ÅÕ½Ðí¥¹ÐÅÕ½Ðì°ÅÕ½ÐíMÑQ¥µÈÅÕ½Ðì°ÅÕ½Ðí¡Ý¹ÅÕ½Ðì°ÀÌØí¡]¹U$°ÅÕ½Ðí¥¹ÐÅÕ½Ðì°ÀÌØí¥Q¥µÉ%°ÅÕ½Ðí¥¹ÐÅÕ½Ðì°ÀÌØí¥%¹ÑÉÙ°°ÅÕ½Ðí¥¹ÐÅÕ½Ðì°À¤(IÑÕɸÀÌØíÉÑÙ±lÁt)¹Õ¹ìôôÐíMÑÉÑQ¥µÈ()Õ¹}MѽÁQ¥µÈ ÀÌØí¡]¹U$°ÀÌØí¥Q¥µÉ%¤(1½°ÀÌØíÉÑÙ°ô±±
±° ÅÕ½ÐíUÍÈÌȹ±°ÅÕ½Ðì°ÅÕ½Ðí¥¹ÐÅÕ½Ðì°ÅÕ½Ðí-¥±±Q¥µÈÅÕ½Ðì°ÅÕ½Ðí¡Ý¹ÅÕ½Ðì°ÀÌØí¡]¹U$°ÅÕ½Ðí¥¹ÐÅÕ½Ðì°ÀÌØí¥Q¥µÉ%¤(ÀÌØíQ%5I9   1ô±Í(IÑÕɸÀÌØíÉÑÙ±lÁt)¹Õ¹ìôôÐíMѽÁQ¥µÈ()Õ¹Q¥µÉ
±±    ¬ ÀÌØí¡]¹U$°ÀÌØí5Í%°ÀÌØí]AÉ´°ÀÌØí1AÉ´¤(½ÉÉÀÌØí¡]¹U$°ÀÌØí5Í%°ÀÌØí]AÉ´°ÀÌØí1AÉ´(1½°ÀÌØíQ¥µÉ%ô  ¥Ñ9 ÀÌØí]AÉ´°Áá¤(MÝ¥Ñ ÀÌØíQ¥µÉ%(
ÍÀÌØíAA}Q%5I}%(¥9½ÐÀÌØí5½ÙQ¡¸}5½Ù5Í  ½à ¤(
½¹Í½±]É¥Ñ ÅÕ½Ðì¸ÅÕ½Ðì¤(¹MÝ¥Ñ (IÑÕɸÅÕ½ÐíU%}IU95MÅÕ½Ðì)¹Õ¹ìôôÐíQ¥µÉ
±±    ¬(
Link to comment
Share on other sites

Nice indeed. How do you make it look more like a native MsgBox with the close button (cross in the upper right corner) disabled? Second, how could I make it the permanently top window. And third, what do all these Global variables mean? Won't they interfere with the code of the main script if I just paste your code into my script?

Thanks in advance for your coments.

Warmly,Narciso

Link to comment
Share on other sites

Local $retval =DllCall("User32.dll", "int", "SetTimer", "hwnd", $hWndGUI, "int", $iTimerId, "int", $iInterval, "int", 0)
I am not exactly expert with dll calls but shouldn't the $iTimerID be an integer pointer? Or have I have not understood the SetTimer finction?

SetTimer function

But I like the way you did the move.

Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
Link to comment
Share on other sites

Nice indeed. How do you make it look more like a native MsgBox with the close button (cross in the upper right corner) disabled? Second, how could I make it the permanently top window. And third, what do all these Global variables mean? Won't they interfere with the code of the main script if I just paste your code into my script?

Thanks in advance for your coments.

The script wraps the builtin MsgBox Func therefore it is the native MsgBox. Pass in the same flags as you would a regular MsgBox to make it top most (262144+4096+...).

There is code in the forum that use Get/SetWindowLong to change the style of a window thus removing the close button.

These variables need to have global scope and shouldn't interfere with your script unless your using variables with the same name.

Global Const $APP_TIMER_ID = 9999 ;There can be multiple timers per application. This is the only one used here.
Global Const $WM_TIMER = 0x0113 ; the WndProc message that this udf will process.
Global $TIMERENABLED = False ; just a bool flag.
Global $bMoved = False              ; same here.  This is set to true after the MsgBox is moved.  It is used to "switch off" the message notification. 
Global $MBOX_INFO[5]   ;This contains information about the MsgBox, like title
;    $MBOX_INFO[0]  ; holds the title
;    $MBOX_INFO[1]  ; holds the message to display
;    $MBOX_INFO[2]  ; holds the x (horizontal) pos
;    $MBOX_INFO[3]  ; holds the y (vertical) pos
;    $MBOX_INFO[4]  ; holds the hwnd to the parent window.

There needs to be a window to receive WM_TIMER notifications. This script creates a little 1x1 window and the window handle is passed to Start/StopTimer (Set/KillTimer API's).

To (very) basically describe how this script works:

The _MessageBox() func is called

a small 1x1 window is created ( not shown though)

The func _MoveMsgBox() is called with the params to receive WM_TIMER notifications

The start timer func is called, this begins a timer loop sending notifications to the TimerCallBack func

If the timer id passed to TimerCallBack matches ours then _MoveMsgBox() is called.

The standard AutoIt MsgBox is called and displayed

The script normally pauses here, but the timer loop is still functioning.

The stop timer func is called as added insurance on the chance that the MsgBox failed.

the return value from MsgBox is passed back.

The WM_TIMER notification is not stalled when the MsgBox is displayed as the AdLib function is. So when our timer id is matched in TimerCallback it calls _MoveMsgBox(). the WinExists() built-in is called to search for the title and message. When a matching window is found, it is _MsgBox is moved and the timer is stopped.

I hope this provides the clarification you request.

Link to comment
Share on other sites

I am not exactly expert with dll calls but shouldn't the $iTimerID be an integer pointer? Or have I have not understood the SetTimer finction?

SetTimer function

But I like the way you did the move.

nIDEvent [in] Specifies a nonzero timer identifier. If the hWnd parameter is NULL, and the nIDEvent does not match an existing timer then it is ignored and a new timer ID is generated. If the hWnd parameter is not NULL and the window specified by hWnd already has a timer with the value nIDEvent, then the existing timer is replaced by the new timer. When SetTimer replaces a timer, the timer is reset. Therefore, a message will be sent after the current time-out value elapses, but the previously set time-out value is ignored. If the call is not intended to replace an existing timer, nIDEvent should be 0 if the hWnd is NULL.

Does this help?

Edit: Pasted incorrect description.

Edited by eltorro
Link to comment
Share on other sites

Does this help?

I did read that. But I was thrown by the function definition

UINT_PTR SetTimer(

HWND hWnd,

UINT_PTR nIDEvent,

UINT uElapse,

TIMERPROC lpTimerFunc

);

But I read that on WIN32 UINT_PTR is UINT, so now I see that I only thought I was confused when in fact I really was.

Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
Link to comment
Share on other sites

Passing in a ptr to a DllStruct filled the the timer id didn't work. Passing as it is seems to work just fine. That's why there is the deviation in this call. This method also works in VB.

Edit: typo

Edited by eltorro
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...