_MsgBox

  • Tach.

    Hab mal ne MsgBox gemacht, bei der man die Position und Hintergrundfarbe wärhlen kann.

    Will sie noch so verändern, dass man auch die Größe ändern kann.
    Das dauert aber etwas.

    Die Rückgabewerte und Flags sind die gleichen wie in einer normalen MsgBox.

    Hier mal das Script: ( Beispiel ist unten im Script )

    Spoiler anzeigen
    [autoit]

    ; ==================================================================================================
    ;
    ; Name: _MsgBox
    ; Funktion: Eine einfach MsgBox, bei der man Position und Farbe ändern kann.
    ;
    ; Parameter: $Flag: Der Flag gibt an, wie die Box aussieht, und welche Buttons angezeigt werden.
    ; $ExFlag: Bestimmt, welches Icon angezeigt werden soll.
    ; $Titel: Titel der MsgBox.
    ; $Text: Text, der in der MsgBox stehen soll.
    ; .....|Optional|.....
    ; $Width: Bestimmt die Breite der msgBox. (Standart = 245)
    ; .....|Optional|.....
    ; $Heigth: Bestimmt die Höhe der MsgBox. (Standart = 200)
    ; .....|Optional|.....
    ; $Left: X-Position der MsgBox. (-1 definiert die Mitte des Bildschirms)
    ; .....|Optional|.....
    ; $Top: Y-Position der MsgBox. (-1 definiert die Mitte des Bildschirms)
    ; .....|Optional|.....
    ; $Color: Hintergrundfarbe der MsgBox (Standart = 0xCCCCCC)
    ; .....|Optional|.....
    ; $OnTop: 1 = Bestimmt, dass die MsgBox immer im Vordergrund steht. (Standart = 0)
    ; .....|Optional|.....
    ; $Sound: 1 = Bestimmt, dass der Sound an ist. (Standart = 1)
    ;
    ; ==================================================================================================
    #include <WindowsConstants.au3>
    Func _MsgBox ($Flag, $ExFlag, $Titel, $Text, $Width = 245, $Height = 200, $Left = -1, $Top = -1, $Color = 0xCCCCCC, $OnTop = 0, $SoundPlay = 1)
    Local $iOnEventMode = Opt("GUIOnEventMode", 0)
    Local $Size = 7, $FontWidth = 700, $return, $Sound = @WindowsDir & "\Media\", $PosX = $Height-25
    $MsgGUI = GUICreate ($Titel, $Width, $Height, $Left, $Top)
    If $OnTop = 1 Then WinSetOnTop ($MsgGUI, "", 1)
    GUISetBkColor ($Color)
    GUISetIcon ("User32.dll", -1)
    GUISetState (@SW_SHOW, $MsgGUI)
    $MsgText = GUICtrlCreateLabel ($Text, 60, 10, $Width-65, $Height-40)
    GUICtrlSetBkColor (-1, $Color)
    ; -------------------------------------
    Switch $Flag
    Case 0
    $Ex1 = Execute (($Width-75)/2)
    Case 1, 4, 5
    $Ex2 = Execute (($Width-150)/3)
    $Ex3 = Execute (($Ex2*2)+75)
    Case 2, 3, 6
    $Ex4 = Execute (($Width-225)/4)
    $Ex5 = Execute (($Ex4*2)+75)
    $Ex6 = Execute (($Ex4*3)+(75*2))
    EndSwitch
    ; -------------------------------------
    Switch $ExFlag
    Case 0
    GUICtrlCreateIcon ("User32.dll", -1, 10, 10, 32, 32)
    If $SoundPlay = 1 Then SoundPlay ($Sound & "Windows XP-Ping.wav")
    Case 16
    GUICtrlCreateIcon ("User32.dll", -4, 10, 10, 32, 32)
    If $SoundPlay = 1 Then SoundPlay ($Sound & "Windows XP-kritischer Fehler.wav")
    Case 32
    GUICtrlCreateIcon ("User32.dll", -3, 10, 10, 32, 32)
    If $SoundPlay = 1 Then SoundPlay ($Sound & "chimes.wav")
    Case 48
    GUICtrlCreateIcon ("User32.dll", -2, 10, 10, 32, 32)
    If $SoundPlay = 1 Then SoundPlay ($Sound & "Windows XP-Hinweis.wav")
    Case 64
    GUICtrlCreateIcon ("User32.dll", -5, 10, 10, 32, 32)
    If $SoundPlay = 1 Then SoundPlay ($Sound & "windows xp-informationsleiste.wav")
    EndSwitch
    ; -------------------------------------
    If $Flag = 0 Then
    $Button1 = GUICtrlCreateButton ("Ok", $Ex1, $PosX, 75, 20)
    GUICtrlSetFont (-1, $Size, $FontWidth)
    While 1
    $Msg1 = GUIGetMsg ()
    Switch $msg1
    Case $Button1
    $return = 1
    ExitLoop
    Case -3
    $return = 2
    ExitLoop
    EndSwitch
    WEnd
    EndIf
    ; -------------------------------------
    If $Flag = 1 Then
    $Button2 = GUICtrlCreateButton ("Ok", $Ex2, $PosX, 75, 20)
    GUICtrlSetFont (-1, $Size, $FontWidth)
    $Button3 = GUICtrlCreateButton ("Abbrechen", $Ex3, $PosX, 75, 20)
    GUICtrlSetFont (-1, $Size, $FontWidth)
    While 1
    $Msg2 = GUIGetMsg ()
    Switch $msg2
    Case $Button2
    $return = 1
    ExitLoop
    Case $Button3
    $return = 2
    ExitLoop
    Case -3
    $return = 2
    ExitLoop
    EndSwitch
    WEnd
    EndIf
    ; -------------------------------------
    If $Flag = 2 Then
    $Button4 = GUICtrlCreateButton ("Abbrechen", $Ex4, $PosX, 75, 20)
    GUICtrlSetFont (-1, $Size, $FontWidth)
    $Button5 = GUICtrlCreateButton ("Wiederhohlen", $Ex5, $PosX, 75, 20)
    GUICtrlSetFont (-1, $Size, $FontWidth)
    $Button6 = GUICtrlCreateButton ("Ignorieren", $Ex6, $PosX, 75, 20)
    GUICtrlSetFont (-1, $Size, $FontWidth)
    While 1
    $Msg3 = GUIGetMsg ()
    Switch $msg3
    Case $Button4
    $return = 2
    ExitLoop
    Case $Button5
    $return = 4
    ExitLoop
    Case $Button6
    $return = 5
    ExitLoop
    Case -3
    $return = 2
    ExitLoop
    EndSwitch
    WEnd
    EndIf
    ; -------------------------------------
    If $Flag = 3 Then
    $Button7 = GUICtrlCreateButton ("Ja", $Ex4, $PosX, 75, 20)
    GUICtrlSetFont (-1, $Size, $FontWidth)
    $Button8 = GUICtrlCreateButton ("Nein", $Ex5, $PosX, 75, 20)
    GUICtrlSetFont (-1, $Size, $FontWidth)
    $Button9 = GUICtrlCreateButton ("Abbrechen", $Ex6, $PosX, 75, 20)
    GUICtrlSetFont (-1, $Size, $FontWidth)
    While 1
    $Msg4 = GUIGetMsg ()
    Switch $msg4
    Case $Button7
    $return = 6
    ExitLoop
    Case $Button8
    $return = 7
    ExitLoop
    Case $Button9
    $return = 2
    ExitLoop
    Case -3
    $return = 2
    ExitLoop
    EndSwitch
    WEnd
    EndIf
    ; -------------------------------------
    If $Flag = 4 Then
    $Button10 = GUICtrlCreateButton ("Ja", $Ex2, $PosX, 75, 20)
    GUICtrlSetFont (-1, $Size, $FontWidth)
    $Button11 = GUICtrlCreateButton ("Nein", $Ex3, $PosX, 75, 20)
    GUICtrlSetFont (-1, $Size, $FontWidth)
    While 1
    $Msg4 = GUIGetMsg ()
    Switch $msg4
    Case $Button10
    $return = 6
    ExitLoop
    Case $Button11
    $return = 7
    ExitLoop
    Case -3
    $return = 2
    ExitLoop
    EndSwitch
    WEnd
    EndIf
    ; -------------------------------------
    If $Flag = 5 Then
    $Button12 = GUICtrlCreateButton ("Wiederhohlen", $Ex2, $PosX, 75, 20)
    GUICtrlSetFont (-1, $Size, $FontWidth)
    $Button13 = GUICtrlCreateButton ("Abbrechen", $Ex3, $PosX, 75, 20)
    GUICtrlSetFont (-1, $Size, $FontWidth)
    While 1
    $Msg4 = GUIGetMsg ()
    Switch $msg4
    Case $Button12
    $return = 4
    ExitLoop
    Case $Button13
    $return = 2
    ExitLoop
    Case -3
    $return = 2
    ExitLoop
    EndSwitch
    WEnd
    EndIf
    ; -------------------------------------
    If $Flag = 6 Then
    $Button14 = GUICtrlCreateButton ("Abbrechen", $Ex4, $PosX, 75, 20)
    GUICtrlSetFont (-1, $Size, $FontWidth)
    $Button15 = GUICtrlCreateButton ("Wiederhohlen", $Ex5, $PosX, 75, 20)
    GUICtrlSetFont (-1, $Size, $FontWidth)
    $Button16 = GUICtrlCreateButton ("Weiter", $Ex6, $PosX, 75, 20)
    GUICtrlSetFont (-1, $Size, $FontWidth)
    While 1
    $Msg4 = GUIGetMsg ()
    Switch $msg4
    Case $Button14
    $return = 2
    ExitLoop
    Case $Button15
    $return = 4
    ExitLoop
    Case $Button16
    $return = 11
    ExitLoop
    Case -3
    $return = 2
    ExitLoop
    EndSwitch
    WEnd
    EndIf ;==> Flags
    ; ---
    GUIDelete($MsgGUI)
    Opt("GUIOnEventMode", $iOnEventMode)
    Return($return)
    EndFunc ;==> _MsgBox
    ; ---
    ; ---
    ; ---
    ; BEISPIEL ( Um die Udf zu benutzen, entweder ab hier löschen, oder auskommentieren!
    _MsgBox (0, 64, "Titel der MsgBox", "Dies ist der Text, der in der MsgBox stehen soll." & @CRLF & @CRLF & "Das steht 2 Zeilen weiter.")

    [/autoit]

    MfG

    EDIT: Neue Version.
    Jetz kann man auch noch bestimmen, ob die MsgBox immer im Vordergund sein soll oder nicht ($OnTop)...

    Edit: Neue version, nun kann man die Sounds noch ausschalten.

    EDIT: Neue Version: Nun lässt sich auch die Größe der MsgBox verändern. Dabei bleiben das Label und die Buttons immder im Verhältniss zur Größe.

    9 Mal editiert, zuletzt von Commander21 (6. Mai 2009 um 17:46)

  • Mich hats einfach gestört, dass man so sachen wie position und farbe net ändern kann.
    Wenn man ne GUI mit roten hintergrund hat und dann so Graue MsgBox kommt, find ich das nich so schön ^^

  • Jo, thx ^^

    Die Icons will ich noch einbauen. Mir war erstmal wichtig, ob es überhaupt so geht, wie ichs mir vorstell, und ob mans gebrauchen könnte.

  • Jo, thx ^^

    Die Icons will ich noch einbauen. Mir war erstmal wichtig, ob es überhaupt so geht, wie ichs mir vorstell, und ob mans gebrauchen könnte.


    Hallo Commander21.

    Klar kann Frau das gebrauchen und Mann sicherlich auch. Ich finde das sehr schön.

    Lieben Gruß,
    Alina

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

    Geheime Information: ;)
    OuBVU5ebLhHu5QvlnAyQB4A7SzBrvWulwL7RLl2BdH5tI6sIYspeMKeXMSXl

    • Offizieller Beitrag

    Nicht schlecht. Wenn du diese Funktion im GuiOnEventMode benutzt hast du aber gelitten.
    Einfach an den Anfang deiner Funktion folgendes setzen :

    [autoit]

    Local $iOnEventMode = Opt("GUIOnEventMode", 0)

    [/autoit]


    Und am Ende :

    [autoit]

    Opt("GUIOnEventMode", $iOnEventMode)

    [/autoit]


    Damit kann man deine MessageBox auch in Scripten verwenden , die im GuiOnEventMode arbeiten ;)

  • Danke für die Info! Habs mit eingebaut ^^

    Hab noch die Icons aus den normalen MsgBoxen mit eingefügt und statt einem Edit, ein Label genommen.
    Sieht einfach besser aus. ( Siehe Post 1 )

    Hoffe dass alles funzt.

    Um sie zu benutzen, muss aber noch das Beispiel untem im Script gelöscht oder auskommentiert werden!

  • Hallo Commander21,

    dass mit dem Icon ist gut gelöst, auch wenn es mit weniger Zeilen ginge. Du solltestet aber die _MsgBox nicht nur verstecken sondern auch löschen,

    mfg (Auto)Bert

  • Hallo Commander21,

    ich habe mal Deine UDF etwas modifiziert,
    damit Opt("GUIOnEventMode", $iOnEventMode)
    überhaupt am Ende ausgeführt wird.

    Spoiler anzeigen
    [autoit]

    ; ======================================================
    ;
    ; Name: _MsgBox
    ; Funktion: Eine einfach MsgBox, bei der man Position und Farbe ändern kann.
    ;
    ; Parameter: $Flag: Das Flag gibt an, wie die Box aussieht, und welche Buttons angezeigt werden.
    ; $ExFlag: Bestimmt, welches Icon angezeigt werden soll.
    ; $Titel: Titel der MsgBox.
    ; $Text: Text, der in der MsgBox stehen soll.
    ; $Left: X-Position der MsgBox.
    ; $Top: Y-Position der MsgBox.
    ; $Color: Hintergrundfarbe der MsgBox
    ;
    ; ======================================================
    Func _MsgBox ($Flag, $ExFlag, $Titel, $Text, $Left, $Top, $Color)
    Local $iOnEventMode = Opt("GUIOnEventMode", 0)
    Local $Size = 7
    Local $FontWidth = 50
    Local $return
    $MsgGUI = GUICreate ($Titel, 245, 200, $Left, $Top)
    GUISetBkColor ($Color)
    GUISetIcon ("User32.dll", -1)
    GUISetState (@SW_SHOW, $MsgGUI)
    $MsgText = GUICtrlCreateLabel ($Text, 60, 10, 180, 160, 0x0800)
    GUICtrlSetBkColor (-1, $Color)
    ; -------------------------------------
    Switch $ExFlag
    Case 0
    GUICtrlCreateIcon ("User32.dll", -1, 10, 10, 32, 32)
    Case 16
    GUICtrlCreateIcon ("User32.dll", -4, 10, 10, 32, 32)
    Case 32
    GUICtrlCreateIcon ("User32.dll", -3, 10, 10, 32, 32)
    Case 48
    GUICtrlCreateIcon ("User32.dll", -2, 10, 10, 32, 32)
    Case 64
    GUICtrlCreateIcon ("User32.dll", -5, 10, 10, 32, 32)
    EndSwitch
    ; -------------------------------------
    If $Flag = 0 Then
    $Button1 = GUICtrlCreateButton ("Ok", 75, 175, 75, 20)
    GUICtrlSetFont (-1, $Size, $FontWidth)
    While 1
    $Msg1 = GUIGetMsg ()
    Switch $msg1
    Case $Button1
    $return = 1
    ExitLoop
    Case -3
    $return = 2
    ExitLoop
    EndSwitch
    WEnd
    EndIf
    ; -------------------------------------
    If $Flag = 1 Then
    $Button2 = GUICtrlCreateButton ("Ok", 25, 175, 75, 20)
    GUICtrlSetFont (-1, $Size, $FontWidth)
    $Button3 = GUICtrlCreateButton ("Abbrechen", 125, 175, 75, 20)
    GUICtrlSetFont (-1, $Size, $FontWidth)
    While 1
    $Msg2 = GUIGetMsg ()
    Switch $msg2
    Case $Button2
    $return = 1
    ExitLoop
    Case $Button3
    $return = 2
    ExitLoop
    Case -3
    $return = 2
    ExitLoop
    EndSwitch
    WEnd
    EndIf
    ; -------------------------------------
    If $Flag = 2 Then
    $Button4 = GUICtrlCreateButton ("Abbrechen", 5, 175, 75, 20)
    GUICtrlSetFont (-1, $Size, $FontWidth)
    $Button5 = GUICtrlCreateButton ("Wiederhohlen", 85, 175, 75, 20)
    GUICtrlSetFont (-1, $Size, $FontWidth)
    $Button6 = GUICtrlCreateButton ("Ignorieren", 165, 175, 75, 20)
    GUICtrlSetFont (-1, $Size, $FontWidth)
    While 1
    $Msg3 = GUIGetMsg ()
    Switch $msg3
    Case $Button4
    $return = 2
    ExitLoop
    Case $Button5
    $return = 4
    ExitLoop
    Case $Button6
    $return = 5
    ExitLoop
    Case -3
    $return = 2
    ExitLoop
    EndSwitch
    WEnd
    EndIf
    ; -------------------------------------
    If $Flag = 3 Then
    $Button7 = GUICtrlCreateButton ("Ja", 5, 175, 75, 20)
    GUICtrlSetFont (-1, $Size, $FontWidth)
    $Button8 = GUICtrlCreateButton ("Nein", 85, 175, 75, 20)
    GUICtrlSetFont (-1, $Size, $FontWidth)
    $Button9 = GUICtrlCreateButton ("Abbrechen", 165, 175, 75, 20)
    GUICtrlSetFont (-1, $Size, $FontWidth)
    While 1
    $Msg4 = GUIGetMsg ()
    Switch $msg4
    Case $Button7
    $return = 6
    ExitLoop
    Case $Button8
    $return = 7
    ExitLoop
    Case $Button9
    $return = 2
    ExitLoop
    Case -3
    $return = 2
    ExitLoop
    EndSwitch
    WEnd
    EndIf
    ; -------------------------------------
    If $Flag = 4 Then
    $Button10 = GUICtrlCreateButton ("Ja", 25, 175, 75, 20)
    GUICtrlSetFont (-1, $Size, $FontWidth)
    $Button11 = GUICtrlCreateButton ("Nein", 125, 175, 75, 20)
    GUICtrlSetFont (-1, $Size, $FontWidth)
    While 1
    $Msg4 = GUIGetMsg ()
    Switch $msg4
    Case $Button10
    $return = 6
    ExitLoop
    Case $Button11
    $return = 7
    ExitLoop
    Case -3
    $return = 2
    ExitLoop
    EndSwitch
    WEnd
    EndIf
    ; -------------------------------------
    If $Flag = 5 Then
    $Button12 = GUICtrlCreateButton ("Wiederhohlen", 25, 175, 75, 20)
    GUICtrlSetFont (-1, $Size, $FontWidth)
    $Button13 = GUICtrlCreateButton ("Abbrechen", 125, 175, 75, 20)
    GUICtrlSetFont (-1, $Size, $FontWidth)
    While 1
    $Msg4 = GUIGetMsg ()
    Switch $msg4
    Case $Button12
    $return = 4
    ExitLoop
    Case $Button13
    $return = 2
    ExitLoop
    Case -3
    $return = 2
    ExitLoop
    EndSwitch
    WEnd
    EndIf
    ; -------------------------------------
    If $Flag = 6 Then
    $Button14 = GUICtrlCreateButton ("Abbrechen", 5, 175, 75, 20)
    GUICtrlSetFont (-1, $Size, $FontWidth)
    $Button15 = GUICtrlCreateButton ("Wiederhohlen", 85, 175, 75, 20)
    GUICtrlSetFont (-1, $Size, $FontWidth)
    $Button16 = GUICtrlCreateButton ("Weiter", 165, 175, 75, 20)
    GUICtrlSetFont (-1, $Size, $FontWidth)
    While 1
    $Msg4 = GUIGetMsg ()
    Switch $msg4
    Case $Button14
    $return = 2
    ExitLoop
    Case $Button15
    $return = 4
    ExitLoop
    Case $Button16
    $return = 11
    ExitLoop
    Case -3
    $return = 2
    ExitLoop
    EndSwitch
    WEnd
    EndIf ;==> Flags
    ; ---
    GUIDelete($MsgGUI)
    Opt("GUIOnEventMode", $iOnEventMode)
    Return($return)
    EndFunc ;==> _MsgBox
    ; ---
    ; ---
    ; ---
    ; BEISPIEL ( Um die Udf zu benutzen, entweder ab hier löschen, oder auskommentieren!
    _MsgBox (2, 32, "Titel der MsgBox", "Dies ist der Text, der in der MsgBox stehen soll." & @CRLF & @CRLF & "Das steht 2 Zeilen weiter.", 500, 500, 0x00FF00)

    [/autoit]

    MfG Schnuffel

    "Sarkasmus ist die niedrigste Form des Witzes, aber die höchste Form der Intelligenz."
    Val McDermid

    ein paar Infos ...

    Wer mehr als "nur" Hilfe benötigt, kann sich gern im Forum "Programmieranfragen" an uns wenden. Wir helfen in allen Fällen, die die Forenregeln zulassen.

    Für schnelle Hilfe benötigen wir ein ! lauffähiges ! Script, dass wir als Demonstration des Problems testen können. Wer von uns erwartet ein Teilscript erstmal lauffähig zu bekommen, der hat
    1. keine wirkliche Not
    2. keinen Respekt vor Menschen die ihm in ihrer Freizeit Ihre Hilfe anbieten
    3. oder ist einfach nur faul und meint wir coden das für ihn

    In solchen Fällen erlaube ich mir, die Anfrage einfach zu ignorieren. ;)

  • Ich würde ein zum Schluss einen Parameter einbauen, der, wenn er auf 1 gesetzt ist, nur den Handle der GUI zurückgibt und später eine Funktion aufrufen, die die Abfrage der Buttons macht, so kann man, ohne die Funktion zu verändern, die GUI manipulieren...

    Zu wenig Punkte, zu viele Kommas....... ;)

  • ich vermisse den ton, der bei den verschiedenen msgbox arten kommt. :)
    wäre sicher auch gut einzubauen.
    mfg

  • Thx ^^

    Ich bau grad noch die Sounds der einzelnen Arten ein.


    EDIT: So, die Sounds sind nun drin.
    Für das Fragezeichen gibts anscheinend keinen, deswegen hab ich einfach nen anderen genomm ^^

    PS: Das sind nur die Sound von Windows XP Home!

    Ich weis nicht, ob sie bei anderen Version auch abgespielt werden.
    Bei Windows Vista wird das wohl leider nicht der Fall sein...

    Einmal editiert, zuletzt von Commander21 (1. Mai 2009 um 17:05)

  • Warum nimmst du nicht die System-Töne, die sind doch überall eindeutig, irgendwo in der Registry müssen die liegen...

  • Systemtöne? Welche?

    Ich hab die aus dem ordner C:\Windows\Media genommen. da sind ( Bei mir jedenfalls ) die ganzen Sounds für die msgBoxen, Anmeldesound, abmeldesound, fehlertöne u.s.w...

    Wo sind die denn in der Reg?

  • find ich schon jetzt sehr super, aber was ich noch bemerkt hab, wenn die ExFlag auf 0 gestellt ist wird ein Icon erstellt ohne zeichen :(
    Ich finde, es wäre besser, wenn gar kein icon erstellt wird :)

    [autoit]

    ;....
    Switch $ExFlag
    Case 0
    GUICtrlCreateIcon ("User32.dll", -1, 10, 10, 32, 32) ;diese Zeile sollte weggelassen werden!
    SoundPlay ($Sound & "Windows XP-Ping.wav")
    ;....

    [/autoit]
  • So, neue Version, nun kann man die Sounds auch ausschalten.

    Siehe ganz oben...