VERSION 1.0 CLASS
BEGIN
  MultiUse = -1  'True
END
Attribute VB_Name = "CPopupDlg"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = True
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = False
Option Explicit

' Win32 API Functions
Private Declare Function SetWindowPos Lib "user32" _
        (ByVal hWnd As Long, ByVal hWndInsertAfter As Long, _
        ByVal X As Long, ByVal Y As Long, ByVal cx As Long, _
        ByVal cy As Long, ByVal wFlags As Long) _
        As Long
Private Declare Function SetCapture Lib "user32" _
        (ByVal hWnd As Long) As Long
Private Declare Function ReleaseCapture Lib "user32" () _
        As Long
Private Declare Function SetForegroundWindow Lib "user32" _
        (ByVal hWnd As Long) As Long
'Private Declare Function SetActiveWindow Lib "user32" _
        (ByVal hWnd As Long) As Long

' Win32 API Constants
Private Const HWND_TOPMOST = -1
Private Const SWP_NOMOVE = &H2
Private Const SWP_NOSIZE = &H1

' Declare module-level variables
Private lngTimeOut As Long
Private strMsg As String
Private blnSized As Boolean
Private nm As Form


Public Sub HideDlg()

nm.Timer1.Enabled = False
nm.Hide
Call ReleaseCapture

End Sub

Public Property Get Text() As String

Text = strMsg

End Property

Public Property Let Text(ByVal strNewValue As String)

strMsg = strNewValue
nm.strMsg = strMsg
SizeDlg

End Property

Public Property Get Timeout() As Long

Timeout = lngTimeOut

End Property

Public Property Let Timeout(ByVal intTimeout As Long)

lngTimeOut = intTimeout
nm.Timer1.Tag = lngTimeOut

End Property

Public Sub ShowDlg()

If Not blnSized Then
   SizeDlg
   blnSized = True
End If
nm.Cls

nm.CurrentX = (nm.ScaleWidth / 2) - nm.TextWidth(strMsg) / 2
nm.CurrentY = (nm.ScaleHeight / 2) - nm.TextHeight(strMsg) / 2

nm.Show
nm.Timer1.Enabled = True
Call SetForegroundWindow(nm.hWnd)
Call SetCapture(nm.hWnd)

End Sub

Private Sub Class_Initialize()

Set nm = nonModal
Load nm
Call SetWindowPos(nm.hWnd, HWND_TOPMOST, 0, 0, 0, 0, _
             SWP_NOMOVE Or SWP_NOSIZE)
Me.Timeout = 5000

End Sub
Private Sub Class_Terminate()

Unload nm

End Sub



Private Sub SizeDlg()

Dim intMargin As Integer
Dim lngHeight As Long, lngWidth As Long

If nm.ScaleMode = vbTwips Then
   intMargin = 200
Else
   intMargin = 50
End If

nm.Width = nm.TextWidth(strMsg) + intMargin
nm.Height = nm.TextHeight(strMsg) + intMargin
nm.Top = frmMain.Top + 50
nm.Left = frmMain.Left + 50
blnSized = True

End Sub

Private Function Max(lng1 As Long, lng2 As Long) As Long

If lng1 > lng2 Then
   Max = lng1
Else
   Max = lng2
End If

End Function

