Hallo,
Im Anhang eine MsgBox() Alternative. (Ich weiß, die gibts wie Sand am Meer)
Da ich oft nur MsgBox(0,"","") verwende, brauchte ich ein eigenes MsgBox (schreibfaul... 20x '0,"",' können schon nervig sein. Als kleinen "Bonus" kann man sich aussuchen, ob die MsgBox das script pausieren soll oder nicht.
Habe versucht so nah wie möglich an der "echten" MsgBox dran zu bleiben. Deshalb keine Color-Spielerie.
Hab zwar getsetet, aber wenn sich doch noch bugs einschleichen, wär ich froh wenn man mir die melden könnte.
Spoiler anzeigen
#include <GDIPlus.au3>
$DUMMY = GUICreate("")
Func _MsgBox($sText, $sTitle = "", $iWait=1, $x = -1, $y = -1)
;=================================================================================================
; Function: _MsgBox($sText[,$sTitle[,$iWait[,$x[,$y]]]])
; Description: Create your very own MsgBox, which does not pause your script (if you dont want it)
; Beschreibung: Erstelle deine eigene MsgBox, die dein Script nicht pausiert, wenn du es nicht willst
;
; Parameter(s): $sText - Your Msgbox' text. | Dein MsgBox-Text
; $sTitle - (optional) Sekect an title for you MsgBox | Weise deiner MsgBox einen Titel zu.
; $iWait - (optional) Determines, weither the MsgBox shall pause (1 ; [default]) or continue your script (0)
; Gibt an, ob die MsgBox die Ausfürhung des Scriptes pausieren (1 ; [Standard])
; oder weiterlaufen lassen soll (0)
; $x - (optional) Your MsgBox's $x position. -1 = centered (default)
; $x-Koordinaten deiner MsgBox. -1 = Zentriert (standard)
; $y - (optional) Your MsgBox's $y position. -1 = centered (default)
; $y-Koordinaten deiner MsgBox. -1 = Zentriert (standard)
;
; Requirement(s): Valid parameters
; _GetTextSize() -> _GDIPlus.au3
;
;
; Return Value(s): $iWait = 1 - True after MsgBox was closed.
; $iWait = 1 - True, nachdem die MsgBox geschlossen wurde
;
; $iWait = 0 - Returns 1D-Array Containing MsgBox' GUI Handle and "OK" Button ID
; $iWait = 0 - Gibt 1D-Array zurück, der das GUI Handle sowie "OK" Button ID der _MsgBox enthält
;
;
;
; Author(s): SEuBo (http://www.autoit.de)
; Note(s):
;=================================================================================================
IF $iWait > 1 Or $iWait < 0 Or $x < -1 Or $y < -1 Then Return
Local $iTrim = 70, $sNewText, $iStart = 0, $oldhWnd = GUISwitch($DUMMY), $Ltop = 26
While StringLen($sText) > $iStart + $iTrim
Do
$iTrim -= 1
$sNewTextTmp = StringStripWS(StringMid($sText, $iStart+1,$iTrim), 1)
Until StringRight($sNewTextTmp,1) = " " OR StringRight($sNewTextTmp,1) = "," OR StringRight($sNewTextTmp,1) = "." OR StringRight($sNewTextTmp,1) = "!"
$iStart += $iTrim
$sNewText &= $sNewTextTmp & "|"
WEnd
$sNewText &= StringStripWS(StringTrimLeft($sText, $iStart), 1)
$aNewText = StringSplit($sNewText, "|")
Local $LWidth=0,$LHeight=0
If $aNewText[0] > 0 Then
$aSize = _GetTextSize($aNewText[1],9.6)
If $aSize[0] < 125 Then $aSize[0] = 125
Local $LWidth=$aSize[0],$LHeight=$aSize[1]
EndIf
$hGUI = GUICreate($sTitle, $LWidth+15, 127 + (15 * $aNewText[0]), $x, $y, BitOR(0x00000080, 0x00080000, 0x00400000))
GUISetFont(9.6)
For $i = 1 To $aNewText[0]
GUICtrlCreateLabel($aNewText[$i], 12, $Ltop, 435 - 24, 15)
$Ltop += 15
Next
GUICtrlCreateLabel(" ", 0, $Ltop + 30, $LWidth+15, (127 + (15 * $aNewText[0])) - ($Ltop + 30))
GUICtrlSetState(-1, 128)
GUICtrlSetBkColor(-1, 0x00F0F0F0)
GUISetBkColor(0xFFFFFF)
$btn_Ok = GUICtrlCreateButton("OK", $LWidth-100, $Ltop + 43, 100, 25)
GUISetState()
DllCall("user32.dll", "int", "MessageBeep", "int", 0x0)
Switch $iWait
Case 0
Local $_iMsgBox_aRet[2] = [$hGUI,$btn_Ok]
GUISwitch($oldhWnd)
Return $_iMsgBox_aRet
Case 1
$iGetMsg = Opt("GUIOnEventMode",0)
Do
$nMsg = GUIGetMsg()
Sleep(10)
Until $nMsg = -3 Or $nMsg = $btn_Ok
GUIDelete($hGUI)
GUISwitch($oldhWnd)
Opt("GUIOnEventMode",$iGetMsg)
Return True
EndSwitch
EndFunc
Func _GetTextSize($nText, $iFontSize = 8.5, $sFont = 'Microsoft Sans Serif', $iFontAttributes = 0)
;Author: Bugfix
;Modified: funkey
If $nText = '' Then Return
Local $hGUI = GUICreate("Textmeter by Bugfix")
_GDIPlus_Startup()
Local $hFormat = _GDIPlus_StringFormatCreate(0)
Local $hFamily = _GDIPlus_FontFamilyCreate($sFont)
Local $hFont = _GDIPlus_FontCreate($hFamily, $iFontSize, $iFontAttributes, 3)
Local $tLayout = _GDIPlus_RectFCreate(15, 171, 0, 0)
Local $hGraphic = _GDIPlus_GraphicsCreateFromHWND($hGUI)
Local $aInfo = _GDIPlus_GraphicsMeasureString($hGraphic, $nText, $hFont, $tLayout, $hFormat)
Local $iWidth = Ceiling(DllStructGetData($aInfo[0], "Width"))
Local $iHeight = Ceiling(DllStructGetData($aInfo[0], "Height"))
_GDIPlus_StringFormatDispose($hFormat)
_GDIPlus_FontDispose($hFont)
_GDIPlus_FontFamilyDispose($hFamily)
_GDIPlus_GraphicsDispose($hGraphic)
_GDIPlus_Shutdown()
GUIDelete($hGUI)
Local $aSize[2] = [$iWidth, $iHeight]
Return $aSize
EndFunc ;==>_GetTextSize
Besten Dank an BugFix und Funkey ; _GetTextSize ist eine der geilsten Funktionen die ich je hatte