VERSION 5.00
Begin VB.Form frmMsg 
   BorderStyle     =   3  'Fixed Dialog
   Caption         =   "MsgBox"
   ClientHeight    =   1155
   ClientLeft      =   45
   ClientTop       =   330
   ClientWidth     =   1815
   LinkTopic       =   "Form1"
   MaxButton       =   0   'False
   MinButton       =   0   'False
   ScaleHeight     =   1155
   ScaleWidth      =   1815
   ShowInTaskbar   =   0   'False
   StartUpPosition =   2  'CenterScreen
   Begin VB.CommandButton cmdButton 
      Caption         =   "OK"
      Height          =   345
      Left            =   120
      TabIndex        =   1
      Top             =   720
      Width           =   1185
   End
   Begin VB.Label labMsg 
      AutoSize        =   -1  'True
      BackStyle       =   0  'Transparent
      Caption         =   "MsgBox"
      Height          =   195
      Left            =   720
      TabIndex        =   0
      Top             =   90
      Width           =   570
   End
   Begin VB.Image imgICO 
      Height          =   480
      Index           =   3
      Left            =   120
      Picture         =   "frmMsg.frx":0000
      Top             =   90
      Visible         =   0   'False
      Width           =   480
   End
   Begin VB.Image imgICO 
      Height          =   480
      Index           =   2
      Left            =   120
      Picture         =   "frmMsg.frx":030A
      Top             =   90
      Visible         =   0   'False
      Width           =   480
   End
   Begin VB.Image imgICO 
      Height          =   480
      Index           =   1
      Left            =   120
      Picture         =   "frmMsg.frx":0614
      Top             =   90
      Visible         =   0   'False
      Width           =   480
   End
   Begin VB.Image imgICO 
      Height          =   480
      Index           =   0
      Left            =   120
      Picture         =   "frmMsg.frx":091E
      Top             =   90
      Visible         =   0   'False
      Width           =   480
   End
End
Attribute VB_Name = "frmMsg"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit

Private Const DEFAULT_CHARSET = 1
Private nOldWidth As Long, nOldHeith As Long, OwnerForm As Form

Public Function ShowMsg(Prompt As String, Optional Buttons As VbMsgBoxStyle = vbExclamation, Optional Title As String = vbNullString) As Boolean
    Dim nICOInx As Integer, nHigh As Long, nWidth As Long, nFitWidth As Long
    Me.Font.Name = LoadResStringX(20)
    Me.Font.size = Val(LoadResStringX(21))
    Me.Font.Charset = DEFAULT_CHARSET
    With labMsg.Font
        .Name = Me.Font.Name
        .size = Me.Font.size
        .Charset = DEFAULT_CHARSET
    End With
    With cmdButton.Font
        .Name = Me.Font.Name
        .size = Me.Font.size
        .Charset = DEFAULT_CHARSET
    End With
    If Not Me.Visible Then
        nOldWidth = Me.Width
        nOldHeith = Me.Height
        If Not TypeName(Screen.ActiveForm) = "Nothing" Then
            Set OwnerForm = Screen.ActiveForm
        End If
    Else
        Me.Width = nOldWidth
        Me.Height = nOldHeith
    End If
    
    cmdButton.Left = imgICO(0).Left
    nWidth = CLng(Screen.Width * 2 / 3)
    With labMsg
        .AutoSize = True
        .WordWrap = False
        .Caption = AdjustWidth(Replace$(Prompt, "\n", Chr$(13), , , vbTextCompare), nWidth - .Left - 350)
        nFitWidth = .Left + .Width + 200
        If nFitWidth > nWidth Then nFitWidth = nWidth
    End With
    Me.Width = nFitWidth
    
    If Title = vbNullString Then Title = App.Title
    Me.Caption = Title
    nFitWidth = Me.TextWidth(Title) + 1000
    If (nFitWidth > Me.Width) And (nFitWidth < nWidth) Then
        Me.Width = nFitWidth
    End If
    
    With cmdButton
        nFitWidth = .Left * 2 + .Width + 200
    End With
    If (nFitWidth > Me.Width) And (nFitWidth < nWidth) Then Me.Width = nFitWidth
    
    nICOInx = 2
    Select Case Buttons And &H70
    Case vbCritical
        nICOInx = 0
    Case vbQuestion
        nICOInx = 1
    Case vbExclamation
        nICOInx = 2
    Case vbInformation
        nICOInx = 3
    End Select
    imgICO(nICOInx).Visible = True
    
    nHigh = Me.TextHeight(labMsg.Caption)
    If nHigh < imgICO(0).Height Then
        nHigh = imgICO(0).Height
        labMsg.Top = imgICO(0).Top + (nHigh - labMsg.Height) / 2
    Else
        cmdButton.Top = labMsg.Top + nHigh + 200
        Me.Height = 0
        Me.Height = Me.Height + cmdButton.Top + cmdButton.Height + 150
    End If
    cmdButton.Left = (Me.Width - cmdButton.Width - 75) / 2
    
    If Not TypeName(OwnerForm) = "Nothing" Then
        Me.Show vbModeless, OwnerForm
    Else
        Me.Show vbModeless
    End If
End Function

Private Sub cmdButton_Click()
    Unload Me
End Sub


Private Sub labMsg_Change()
    'Debug.Assert False
End Sub

Public Function AdjustWidth(ByVal strDataR As String, ByVal nWidth) As String
    Dim strDataL As String, nLen As Long
    Dim L As Long, R As Long, nPos As Long, strData As String, J As Long
    strDataL = vbNullString
    strData = vbNullString
    nWidth = nWidth - 50
    If strDataR <> vbNullString Then
        For J = 1 To Len(strDataR)
            strDataL = strDataL & Mid(strDataR, J, 1)
            If Me.TextWidth(strDataL) > nWidth Then
                If strData = vbNullString Then
                    strData = strDataL
                Else
                    strData = strData & Chr$(13) & strDataL
                End If
                strDataL = vbNullString
            End If
        Next J
    End If
    If strDataL <> vbNullString Then
        If strData = vbNullString Then
            strData = strDataL
        Else
            strData = strData & Chr$(13) & strDataL
        End If
    End If
    AdjustWidth = strData
End Function

