Jump to content

MsgBox/MessageBox - Move and change button text


SmOke_N
 Share

Recommended Posts

  • Moderators

A while back, a few of us came up with a method to move the MsgBox window and to change button text. It was rather clumsy.

I wrote a dll solution for moving the MsgBox to the center of the parent GUI window that owned it for most of my personal work.

I decided to port it over to AutoIt rather continue to port the dll with all my AutoIt work, in addition I added the button text changing to the solution as well.

The examples should be self explanatory on how to use the functions provided.

* Note - I did not take the time to a $MB_OK type of Constant variable, they are there ( eg. $__iMsgBox_IDOK ), but they are designed for internal use only.Example:

#include <MsgBoxUDF.au3>
#region 3 piece function call
; Regardless of Coords, if a handle is passed, it will center messagebox to window of handle
_MsgBox_SetWindowPos(200, 100)

; The same flag passed for buttons 0-6 should be set for both messagebox and setbuttontext
_MsgBox_SetButtonText(4, "Button1", "Button2")

_MsgBox(4 + 262144, "Title", "Hello World One")

Sleep(250)
; See now that it reset back to default
_MsgBox(4 + 262144, "Title", "Hello World Two")
#endregion 3 piece function call

#region stand alone all in one call
Sleep(250)
; Change buton 1 to Button1; Move to top left corner of desktop
_MsgBoxEx(4 + 262144, "Title", "Hello World Three", -1, -1, "Button1", -1, -1, 0, 0)

Sleep(250)
; Center to active window
_MsgBoxEx(4 + 262144, "Title", "Hello World Four", -1, WinGetHandle(""), -1, "Button2", -1, 0, 0)
#endregion stand alone all in one call

MsgBoxUDF.au3

Edited by SmOke_N

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

  • Moderators

I use the method often. Especially for centering to parent GUI.

Always drove me crazy to have my message box outside my GUI if I put it somewhere other than it's default location.

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

  • 1 year later...

hey smoke, thanks for the UDF =)

i have success renaming 2 buttons but not with 3. any ideas?

_MsgBox_SetButtonText(6, "text1", "text2", "text3")

$prompt = _MsgBox(6, "Title", "test?")

thanks again for sharing

Edited by gcue
Link to comment
Share on other sites

  • Moderators

I revised the function, try the new udf download.

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

using this

#include <msgboxudf.au3>

_MsgBox_SetButtonText(6, "text1", "text2", "text3")

_MsgBox(6, "Title", "test?") ;WORKS
_MsgBox(6+262144, "Title", "test?") ;DOES NOT WORK

thanks again for your help and the awesome UDF

Edited by gcue
Link to comment
Share on other sites

  • Moderators

I'm pretty sure I know where the issue is. I did one of those... just fix this fast and don't debug things.

In order to fix the above, I'll have to look more which means I won't have time for a while, maybe the weekend or if I run into it too before then.

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

  • Moderators

Try it now

Edit:

FYI: The setbuttontext option clears once the _MsgBox() has been called and is reset to default.

So, you'd have to do this each time:

#include <msgboxudf.au3>

_MsgBox_SetButtonText(6, "text1", "text2", "text3")

_MsgBox(6, "Title", "test?") ;WORKS

; SetButtonText is reset after last _MsgBox(), so set text again
_MsgBox_SetButtonText(6, "text4", "text5", "text6")
_MsgBox(6+262144, "Title", "test?")
Edited by SmOke_N

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

  • 6 months later...

This UDF is great, but is there any way to create a msgbox centered to parent where the msgbox itself doesn't have to always be active? If I use the regular MsgBox() function I can leave the msgbox open while I continue doing other things manually in the background. However, if I use _MsgBoxEx() to center the msgbox, I cannot do anything until the msgbox goes away. I would really like to have both of these functionalities from one function!

Link to comment
Share on other sites

  • Moderators

horstj,

MsgBox is a blocking function, so it is hardly surprising that you find your script blocked until you acknowledge it. Could I suggest either Yashied's NotifyBox or my Notify UDF (look in my sig for the link). :)

You will probably have to rewrite SmOke_N's MsgBox-based UDF to get the NotifyBox to centre on your GUI (although I have not checked) - and my UDF slides in the notifications from the side of the screen. But if you want to keep the main GUI active you are a bit limited in your options. ;)

M23

Edited by Melba23
Fixed formatting - I hate this editor!

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

This UDF is great, but is there any way to create a msgbox centered to parent where the msgbox itself doesn't have to always be active? If I use the regular MsgBox() function I can leave the msgbox open while I continue doing other things manually in the background. However, if I use _MsgBoxEx() to center the msgbox, I cannot do anything until the msgbox goes away. I would really like to have both of these functionalities from one function!

There are MessageBox flags which make it so the user must respond before you can manually do anything in any application.

Perhaps this is one of those, I cannot remember, but be sure to provide the _MgsBoxEx() function with a hWnd parameter which might solve your problem.

Edited by JohnOne

AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

Link to comment
Share on other sites

MsgBox is a blocking function, so it is hardly surprising that you find your script blocked until you acknowledge it.

This may be so with _MsgBox() from this UDF, but the stock MsgBox() is not blocking. If you use the standard msgbox you can still do anything else while leaving the box open. I didn't look too long, but it seems that this UDF is more or less just modifying a basic msgbox. This leads me to believe that something in Sm0ke_N's code is altering the msgbox to make it a blocking function. Am I completely off base here?

Link to comment
Share on other sites

  • Moderators

horstj,

but the stock MsgBox() is not blocking

Oh no? Run this: :)

#include <GUIConstantsEx.au3>

$hGUI = GUICreate("Test", 500, 500)
GUISetState()

MsgBox(0, "Hi", "Try and close the GUI before you close me!")

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch
WEnd

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

I think the guy means it blocks the ability to work on other applications.

If smokes code calls MessageBox API and a certain flag is used without passing a handle to it (NULL) it blocks everything until it is addressed.

AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

Link to comment
Share on other sites

  • Moderators

horstj, JohnOne,

I know nothing about this UDF, nor the flags needed by the API. So I am out of here. :bye:

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

I think the guy means it blocks the ability to work on other applications.

Right, sorry for the confusion there. I wasn't talking about being able to use the GUI that created the msgbox. Here is an exact example of what I am seeing:

#include <GUIConstantsEx.au3>
#include <MsgBoxUDF.au3>
#include <ButtonConstants.au3>

$hGUI = GUICreate("Test", 190, 90)
GUISetState()

Run("C:\Program Files (x86)\Internet Explorer\iexplore.exe -new https://www.google.com","")
$WinHwnd = WinWaitActive("[CLASS:IEFrame]")
GUICtrlCreateLabel("Click _MsgBoxEx first.", 40, 10)
$_MsgBoxExButton = GUICtrlCreateButton("_MsgBoxEx",20,40,70,30,$BS_DEFPUSHBUTTON)
$MsgBoxButton = GUICtrlCreateButton("MsgBox",100,40,70,30,$BS_DEFPUSHBUTTON)

While 1 ;
      $msg = GUIGetMsg(1)
      Select
            Case $msg[0] = $_MsgBoxExButton
                  _MsgBoxEx(0,"Hi", "Try to do anything in IE",-1,$WinHwnd)
            Case $msg[0] = $MsgBoxButton
                  MsgBox(0,"Hi", "Now try to do anything in IE")
            Case $msg[0] = $GUI_EVENT_CLOSE And $msg[1] = $hGUI
                  ExitLoop
      EndSelect
WEnd

The problem is that I cannot use IE when the _MsgBoxEx() function was used, but I would like the msgbox to be centered on the IE window.

Edited by horstj
Link to comment
Share on other sites

  • 1 year later...
  • Moderators

Sorry to have taken so long to respond.  I'm not on as much as I'd like to be.

Having said that, it's been a long while since I've looked at this code.

If I had to take a "stab" in the dark on why you're experienceing this behavior, the first thing I'd reserarch is the windows api SetWindowsHookEx.

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

  • 1 year later...

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...