#AutoIt3Wrapper_Res_Icon_Add=Icon.ico, 243
#include <MsgBoxConstants.au3>
#include <WindowsConstants.au3>
#include <GUIConstantsEx.au3>
#include <Timers.au3>
Global Const $MB_ICONAPP = 112
Opt("GUIOnEventMode", 1)
Global $TextToTest
$TextToTest = "Text Text Text Text Text Text Text Text Text Text ABCDEFGH" & @CRLF & "Text Text Text Text Text Text Text Text Text Text ABCDEFGH" & @CRLF & "Text Text Text Text Text Text Text Text Text Text ABCDEFGH"
_MsgBoxMy($MB_ICONAPP, "MyMsgBox", $TextToTest, 5)
_MsgBoxMy($MB_ICONERROR, "MyMsgBox", $TextToTest, 4)
_MsgBoxMy($MB_ICONQUESTION, "MyMsgBox", $TextToTest, 3)
_MsgBoxMy($MB_ICONWARNING, "MyMsgBox", $TextToTest, 2)
_MsgBoxMy($MB_ICONINFORMATION, "MyMsgBox", $TextToTest, 1)
While 1
Sleep(10)
WEnd
Exit
Func _MsgBoxMy(Const $flag, Const $title, Const $text, $timeout = 0, $hwind = 0)
Local $Ret
Local $Icon
Local $SpaceTextLeft
Local $SpaceTextRight
Local $SpaceTextTop
Local $SpaceTextDown
Local $TitleSize = 30
If BitAnd(7, $flag) Then
If $hwind Then
$Ret = MsgBox($flag, $title, $text, $timeout, $hwind)
Else
$Ret = MsgBox($flag, $title, $text, $timeout)
EndIf
Return $Ret
EndIf
Local $MsgBox = GUICreate($title, 1, 1, -1, -1, $WS_DLGFRAME)
GUISetBkColor(0xFFFFFF, $MsgBox)
Local $Label = GUICtrlCreateLabel($text, 0, 0, -1, -1)
Local $aPos = ControlGetPos($MsgBox, "", $Label)
Select
Case BitAND(112, $flag) = $MB_ICONAPP
$Icon = -1
Case BitAND(112, $flag) = $MB_ICONERROR
$Icon = 98
Case BitAND(112, $flag) = $MB_ICONQUESTION
$Icon = 99
Case BitAND(112, $flag) = $MB_ICONWARNING
$Icon = 84
Case BitAND(112, $flag) = $MB_ICONINFORMATION
$Icon = 81
Case Else
$Icon = 0
EndSelect
If $Icon Then
If $Icon = -1 Then
GUICtrlCreateIcon(@ScriptFullPath, 243, 25, 26, 32, 32)
Else
GUICtrlCreateIcon("imageres.dll", $Icon, 25, 26, 32, 32)
EndIf
$SpaceTextLeft = 65
$SpaceTextRight = 36
If $aPos[3] > 25 Then
$SpaceTextTop = 26
Else
$SpaceTextTop = 34
EndIf
$SpaceTextDown = 18
GUICtrlSetPos($Label, $SpaceTextLeft, $SpaceTextTop, -1, -1)
Else
$SpaceTextLeft = 12
$SpaceTextRight = 12
$SpaceTextTop = 26
$SpaceTextDown = 18
GUICtrlSetPos($Label, $SpaceTextLeft, $SpaceTextTop, -1, -1)
EndIf
Local $WinW = $SpaceTextLeft + $aPos[2] + $SpaceTextRight
If $WinW < 144 Then $WinW = 144
Local $WinH = $SpaceTextTop + $aPos[3] + $SpaceTextDown + $TitleSize + 30
If $WinH < 144 Then $WinH = 144
WinMove($MsgBox, "", @DesktopWidth/2-$WinW/2, @DesktopHeight/2-$WinH/2, $WinW, $WinH)
Local $ButOK = GUICtrlCreateButton("OK", ($WinW-88)/2, $WinH-35-$TitleSize, 88, 25)
GUICtrlSetState($ButOK, $GUI_FOCUS)
GUICtrlSetOnEvent($ButOK, "_EventMsgBox")
If $timeout Then
_Timer_SetTimer($MsgBox, $timeout*1000, "_TimerMsgBox")
EndIf
GUISetState(@SW_SHOW, $MsgBox)
EndFunc
Func _TimerMsgBox($hWnd, $iMsg, $iIDTimer, $iTime)
If WinExists($hWnd) Then
GUIDelete($hWnd)
EndIf
_Timer_KillTimer($hWnd, $iIDTimer)
EndFunc
Func _EventMsgBox()
If WinExists(@GUI_WinHandle) Then
GUIDelete(@GUI_WinHandle)
EndIf
EndFunc