Twml

Opening MsgBox with a button

7 posts in this topic

Im wondering how to open a MsgBox i have with a button that i have

Here is the button displaying line:
$idToS = GUICtrlCreateButton("Click Me", 180, 10, 280, 20)

and my MsgBox line:

$iMessage = MsgBox(1,"title","line 1" & @CRLF & "" & @CRLF & "line 2" & @CRLF &  "line 3")

 

right now the main box just opens and the msgbox gets opened with it, how can i make the msgbox stay closed until the button is clicked?
        

 

 

Share this post


Link to post
Share on other sites



Welcome to AutoIt and the forum!

Could you please post the whole script? Helps us to help you :)


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

Here is my full Au3 file

right now both boxes open when the script is run, i want the msgbox to only open when button is clicked that is at top of the main window.

 

Im new to AutoIT, this is a example script that comes with autoit that i changed a bit to add more info but now i cant get this button to work

file.au3

Share this post


Link to post
Share on other sites
#include <GUIConstantsEx.au3>
#include <MsgBoxConstants.au3>

Example()

Func Example()
    Opt("GUICoordMode", 2)
    Opt("GUIResizeMode", 1)
    Opt("GUIOnEventMode", 1)

    GUICreate("Parent1")
    GUISetOnEvent($GUI_EVENT_CLOSE, "SpecialEvents")
    GUISetOnEvent($GUI_EVENT_MINIMIZE, "SpecialEvents")
    GUISetOnEvent($GUI_EVENT_RESTORE, "SpecialEvents")

    GUICtrlCreateButton("OK", 10, 30, 50)
    GUICtrlSetOnEvent(-1, "OKPressed")

    GUICtrlCreateButton("Cancel", 0, -1)
    GUICtrlSetOnEvent(-1, "CancelPressed")

    GUISetState(@SW_SHOW)

    ; Just idle around
    While 1
        Sleep(10)
    WEnd
EndFunc   ;==>Example

Func OKPressed()
    MsgBox($MB_SYSTEMMODAL, "OK Pressed", "ID=" & @GUI_CtrlId & " WinHandle=" & @GUI_WinHandle & " CtrlHandle=" & @GUI_CtrlHandle)
EndFunc   ;==>OKPressed

Func CancelPressed()
    MsgBox($MB_SYSTEMMODAL, "Cancel Pressed", "ID=" & @GUI_CtrlId & " WinHandle=" & @GUI_WinHandle & " CtrlHandle=" & @GUI_CtrlHandle)
EndFunc   ;==>CancelPressed

Func SpecialEvents()
    Select
        Case @GUI_CtrlId = $GUI_EVENT_CLOSE
            MsgBox($MB_SYSTEMMODAL, "Close Pressed", "ID=" & @GUI_CtrlId & " WinHandle=" & @GUI_WinHandle)
            Exit

        Case @GUI_CtrlId = $GUI_EVENT_MINIMIZE
            MsgBox($MB_SYSTEMMODAL, "Window Minimized", "ID=" & @GUI_CtrlId & " WinHandle=" & @GUI_WinHandle)

        Case @GUI_CtrlId = $GUI_EVENT_RESTORE
            MsgBox($MB_SYSTEMMODAL, "Window Restored", "ID=" & @GUI_CtrlId & " WinHandle=" & @GUI_WinHandle)

    EndSelect
EndFunc   ;==>SpecialEvents

From help file example

 


Spoiler

Paster - Main function is to paste text, but has more functions.

OpenW - Open With... alternative, Open any file with any application, set it's icon, set application as default.

Renamer - Rename files and folders, remove portions of text from the filename etc.

BeatsPlayer - Music player.

Params Tool - Right click an exe to see it's parameters or execute them.

Regedit Control - Registry browsing history, quickly jump into any saved key.

Time4Shutdown - Write the time for shutdown in minutes.

Power Profiles Tool - Set a profile as active, delete, duplicate, export and import.

Firefox Profile Backup - Backup/restore previously saved profile.

Finished Task Shutdown - Shuts down pc when specified window/Wndl/process closes.

NetworkSpeedShutdown - Shuts down pc if download speed goes under "X" Kb/s.

IUIAutomation - Topic with framework and examples

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

In your While loop, you need to look for that button press, so:

Case $iMsg = $idToS

$iMessage = MsgBox(1,"title","line 1" & @CRLF & "" & @CRLF & "line 2" & @CRLF &  "line 3")

 

EDIT I looked at your code, and I think you might want to start with the basics, as you are using DIM for a regular variable, they are reserved for arrays, and that message part of the code can go in the main while loop so, that if you click the click me button, then the msgbox will appear, waiting for your answer.

Edited by nitekram

All by me:

"Sometimes you have to go back to where you started, to get to where you want to go." 

"Everybody catches up with everyone, eventually" 

"As you teach others, you are really teaching yourself."

From my dad

"Do not worry about yesterday, as the only thing that you can control is tomorrow."

 

WindowsError.gif

WIKI | Tabs; | Arrays; | Strings | Wiki Arrays | How to ask a Question | Forum Search | FAQ | Tutorials | Original FAQ | ONLINE HELP | UDF's Wiki | AutoIt PDF

AutoIt Snippets | Multple Guis | Interrupting a running function | Another Send

StringRegExp | StringRegExp Help | RegEXTester | REG TUTOR | Reg TUTOT 2

AutoItSetOption | Macros | AutoIt Snippets | Wrapper | Autoit  Docs

SCITE | SciteJump | BB | MyTopics | Programming | UDFs | AutoIt 123 | UDFs Form | UDF

Learning to script | Tutorials | Documentation | IE.AU3 | Games? | FreeSoftware | Path_Online | Core Language

Programming Tips

Excel Changes

ControlHover.UDF

GDI_Plus

Draw_On_Screen

GDI Basics

GDI_More_Basics

GDI Rotate

GDI Graph

GDI  CheckExistingItems

GDI Trajectory

Replace $ghGDIPDll with $__g_hGDIPDll

DLL 101?

Array via Object

GDI Swimlane

GDI Plus French 101 Site

GDI Examples UEZ

GDI Basic Clock

GDI Detection

Ternary operator

Share this post


Link to post
Share on other sites

@nitekram added what you said and it does open when clicking button, but now when clicking ok on the popup closes the whole thing not just the msgbox

this will work but i would like for ok on the msgbox to not close the whole thing if possible here is what i changed on my original with that you 

 

I originally wrote this all to work in mshta and it did but mshta is just buggy when used on different os then wrote on usually, so tried something new, if i keep using autoit i will definitially learn it from ground up, im just trying to Frankenstein this together for now so it does what i want it to.  closer then i once was.

While 1
        $iMsg = GUIGetMsg()
        Select
        Case $iMsg = $idToS
           $iMessage = MsgBox(1,"title","line 1" & @CRLF & "" & @CRLF & "line 2" & @CRLF &  "line 3")
                ExitLoop
            Case Else
                ;;;
             EndSelect
    WEnd

 

Share this post


Link to post
Share on other sites

Cant seem to find edit button for my last reply, but i got it to work now without closing the whole thing.

Thank you all issue solved. 

Share this post


Link to post
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