Skip to content

Technical Details ​

Internal implementation principles and technical details of cToast.

Table of Contents ​

Internal Architecture ​

Class Structure ​

cToast (Main class)
├── Private members
│   ├── m_ePos          ' Current position
│   ├── m_eState        ' Current state
│   ├── m_eTheme        ' Current theme
│   ├── m_lIndex        ' Stack index
│   ├── m_sTagName      ' Unique identifier
│   └── m_colToasts     ' Collection of all popups
│
├── Public methods (chain call)
│   ├── Pos()
│   ├── State()
│   ├── Theme()
│   ├── InstIndex()
│   ├── Tag()
│   └── Show()
│
├── Management methods
│   ├── CloseMe()
│   ├── CloseAll()
│   └── Exists()
│
└── Properties
    ├── Count
    ├── ActiveKeys
    └── Events
        ├── OnToastCountChange
        └── OnCloseAll

Data Flow ​

User Call → Set Properties → Check Tag → Calculate Index → Create Form → Display → Timer Countdown → Close → Remove from Collection

Form Implementation ​

FToastCenter - Center Form ​

Used Positions: Center, CenterTop, CenterBottom

Key Features:

  • Center display mode
  • Bottom color bar indicating state
  • Simple and clean design
  • Suitable for important notifications

Technical Implementation:

vb
' Form properties
.BorderStyle = 0      ' No border
.Caption = ""         ' No title
.ControlBox = False   ' No control box
.Moveable = False     ' Non-movable
.ShowInTaskbar = False ' Not shown in taskbar
.StartUpPosition = 0  ' Manual positioning

' Shadow effect (using cShadow component)
Set Shadow = New cShadow
Shadow.Add Me

Display Algorithm:

  1. Calculate screen center position
  2. Apply vertical offset based on stack index
  3. CenterTop: Positive offset (stack down)
  4. CenterBottom: Negative offset (stack up)
  5. Center: No offset (overlay mode)

FToastDrawer - Side Form ​

Used Positions: LeftTop, LeftBottom, LeftCenter, RightTop, RightBottom, RightCenter

Key Features:

  • Side drawer style
  • Side color bar indicating state
  • Contains title and content two lines
  • Suitable for stacking multiple messages

Technical Implementation:

vb
' Form properties
.BorderStyle = 0      ' No border
.Caption = ""         ' No title
.ControlBox = False   ' No control box
.Moveable = False     ' Non-movable
.ShowInTaskbar = False ' Not shown in taskbar
.StartUpPosition = 0  ' Manual positioning

' Layout
' Left side: Color bar (based on state)
' Right side: Title and content

Display Algorithm:

  1. Calculate screen edge position
  2. Apply horizontal/vertical offset based on stack index
  3. Top positions: Positive vertical offset (stack down)
  4. Bottom positions: Negative vertical offset (stack up)
  5. Center positions: No vertical offset (overlay mode)

Stacking Algorithm ​

Auto Stack Index Calculation ​

vb
Private Function GetNextIndex() As Long
    ' Get all popups with current position
    Dim colPos As Collection
    Set colPos = GetToastsByPosition(m_ePos)
    
    ' Return current count as new index
    GetNextIndex = colPos.Count
End Function

Stack Order Rules ​

Top Positions (CenterTop, LeftTop, RightTop):

  • Index 0: Topmost
  • Index increases downward
  • New popups appear at the bottom
Index 0 ━━━━━━━━━━━
Index 1 ━━━━━━━━━━━
Index 2 ━━━━━━━━━━━ (Newest)

Bottom Positions (CenterBottom, LeftBottom, RightBottom):

  • Index 0: Bottommost
  • Index increases upward
  • New popups appear at the top
Index 2 ━━━━━━━━━━━ (Newest)
Index 1 ━━━━━━━━━━━
Index 0 ━━━━━━━━━━━

Center Positions (Center, LeftCenter, RightCenter):

  • Overlay mode, only one popup visible
  • New popups overlay old ones
  • Index calculation exists but does not affect display

Offset Calculation ​

vb
Private Sub CalculatePosition()
    Dim x As Long, y As Long
    Dim offset As Long
    
    ' Base position based on position type
    Select Case m_ePos
        Case CenterTop
            x = Screen.Width / 2 - Me.Width / 2
            offset = m_lIndex * (Me.Height + 10)
            y = 10 + offset
            
        Case CenterBottom
            x = Screen.Width / 2 - Me.Width / 2
            offset = m_lIndex * (Me.Height + 10)
            y = Screen.Height - Me.Height - 10 - offset
            
        Case LeftTop
            x = 10
            offset = m_lIndex * (Me.Height + 10)
            y = 10 + offset
            
        Case LeftBottom
            x = 10
            offset = m_lIndex * (Me.Height + 10)
            y = Screen.Height - Me.Height - 10 - offset
            
        Case RightTop
            x = Screen.Width - Me.Width - 10
            offset = m_lIndex * (Me.Height + 10)
            y = 10 + offset
            
        Case RightBottom
            x = Screen.Width - Me.Width - 10
            offset = m_lIndex * (Me.Height + 10)
            y = Screen.Height - Me.Height - 10 - offset
            
        ' Center positions - no offset
        Case Center
            x = Screen.Width / 2 - Me.Width / 2
            y = Screen.Height / 2 - Me.Height / 2
            
        Case LeftCenter
            x = 10
            y = Screen.Height / 2 - Me.Height / 2
            
        Case RightCenter
            x = Screen.Width - Me.Width - 10
            y = Screen.Height / 2 - Me.Height / 2
    End Select
    
    Me.Move x, y
End Sub

Event Mechanism ​

Event Declaration ​

vb
Public Event OnToastCountChange(ByVal TagName As String, _
                                ByVal IsDelete As Boolean, _
                                ByVal CurrentCount As Long)

Public Event OnCloseAll(ByVal ClosedCount As Long)

Event Trigger Timing ​

OnToastCountChange:

  1. Triggered when a new popup is created
  2. Triggered when a popup is closed
  3. Provides change details (add/delete, current count)

OnCloseAll:

  1. Triggered after all popups are closed by CloseAll
  2. Only triggered once for batch operations
  3. Provides total number of popups closed

Event Implementation in Form ​

vb
' In FToastCenter and FToastDrawer forms
Private Sub Form_Unload(Cancel As Integer)
    ' Notify parent class when form closes
    On Error Resume Next
    RaiseEvent OnClose
    On Error GoTo 0
End Sub

' cToast handles event
Private Sub HandlePopupClose()
    m_colToasts.Remove m_sTagName
    RaiseEvent OnToastCountChange(m_sTagName, True, m_colToasts.Count)
End Sub

Event Best Practices ​

vb
' In user code
Private WithEvents Toast As cToast

Private Sub Toast_OnToastCountChange(ByVal TagName As String, _
                                     ByVal IsDelete As Boolean, _
                                     ByVal CurrentCount As Long)
    ' Update UI
    UpdateCountLabel CurrentCount
    
    ' Log
    If IsDelete Then
        Log "Popup " & TagName & " closed"
    End If
End Sub

Lifecycle Management ​

Creation Lifecycle ​

1. User calls .Show()
   ↓
2. Check if Tag exists
   ↓
3. If exists, return (no duplicate creation)
   ↓
4. If not exists, calculate position and index
   ↓
5. Create form (FToastCenter or FToastDrawer)
   ↓
6. Set form properties and content
   ↓
7. Add to collection
   ↓
8. Trigger OnToastCountChange event
   ↓
9. Start timer countdown
   ↓
10. Display form

Display Lifecycle ​

1. Form displayed
   ↓
2. Timer starts countdown
   ↓
3. User can hover to pause countdown
   ↓
4. Countdown completes or user manually closes
   ↓
5. Form starts unload
   ↓
6. Remove from collection
   ↓
7. Trigger OnToastCountChange event
   ↓
8. Form completely unloaded

Resource Cleanup ​

vb
' cToast cleanup
Public Sub CloseAll()
    Dim i As Long
    Dim count As Long
    
    count = m_colToasts.Count
    
    ' Close all popups
    For i = count To 1 Step -1
        On Error Resume Next
        Dim frm As Object
        Set frm = m_colToasts(i)
        Unload frm
        On Error GoTo 0
    Next i
    
    ' Clear collection
    Set m_colToasts = New Collection
    
    ' Trigger event
    RaiseEvent OnCloseAll(count)
End Sub

' Form cleanup
Private Sub Form_Unload(Cancel As Integer)
    ' Release shadow object
    If Not Shadow Is Nothing Then
        Set Shadow = Nothing
    End If
    
    ' Release other resources
    ' ...
End Sub

Performance Optimization ​

Memory Management ​

  1. Prompt Resource Release
vb
' User code should release object references promptly
Set Toast = Nothing
  1. Avoid Memory Leaks
vb
' Check if exists before creating
If Not Toast.Exists("msg1") Then
    Toast.Tag("msg1").Show "Message", 0
End If
  1. Collection Management
vb
' Forms are automatically removed from collection on unload
' No manual intervention needed

Display Performance ​

  1. Delay Loading
vb
' Forms are only created when needed
' Not pre-loaded at program start
  1. Optimized Drawing
vb
' Use simple controls
' Avoid complex graphics operations
' Ensure smooth animations
  1. Timer Optimization
vb
' Each form has its own timer
' No shared timer conflicts

Event Optimization ​

  1. Avoid Frequent Triggers
vb
' OnCloseAll only triggers once for batch operations
' Avoids excessive event triggers
  1. Event Debouncing
vb
' User can implement their own debouncing logic
Private Sub Toast_OnToastCountChange(...)
    Static lastTime As Long
    Dim currentTime As Long
    
    currentTime = GetTickCount()
    If currentTime - lastTime < 100 Then Exit Sub
    lastTime = currentTime
    
    ' Process event
End Sub

Extension Suggestions ​

Custom Theme Extension ​

vb
' Add custom theme enumeration
Public Enum EnumCustomTheme
    CustomLight = 0
    CustomDark = 1
    CustomBlue = 2
    CustomGreen = 3
End Enum

' Extend Theme method to support custom themes
Public Function ThemeCustom(ByVal eTheme As EnumCustomTheme) As cToast
    ' Set custom theme
    ' ...
    Set ThemeCustom = Me
End Function

Custom Icon Extension ​

vb
' Add custom icon support
Public Function Icon(ByVal IconPath As String) As cToast
    ' Set custom icon
    m_sIconPath = IconPath
    Set Icon = Me
End Function

Animation Extension ​

vb
' Add animation effect
Public Enum EnumAnimation
    None = 0
    FadeIn = 1
    SlideIn = 2
    ScaleIn = 3
End Enum

Public Function Animation(ByVal eAnim As EnumAnimation) As cToast
    ' Set animation type
    m_eAnimation = eAnim
    Set Animation = Me
End Function

Sound Extension ​

vb
' Add sound notification
Public Function Sound(ByVal SoundFile As String) As cToast
    ' Play sound on show
    PlaySound SoundFile
    Set Sound = Me
End Function

Click Action Extension ​

vb
' Add click action
Public Sub OnClick(ByVal Action As String)
    m_sClickAction = Action
End Sub

' Handle form click event
Private Sub Form_Click()
    ' Execute action
    ExecuteAction m_sClickAction
End Sub

Progress Bar Extension ​

vb
' Add progress bar support
Public Function Progress(ByVal Value As Long, ByVal Max As Long) As cToast
    ' Show progress bar
    m_lProgress = Value
    m_lProgressMax = Max
    UpdateProgressBar
    Set Progress = Me
End Function

Multi-Line Content Extension ​

vb
' Support for richer text formatting
Public Function RichText(ByVal HTML As String) As cToast
    ' Support HTML or RTF format
    m_sRichContent = HTML
    Set RichText = Me
End Function

Auto Dismiss on Click Extension ​

vb
' Click to close
Public Function DismissOnClick() As cToast
    m_bDismissOnClick = True
    Set DismissOnClick = Me
End Function

' Handle form click
Private Sub Form_Click()
    If m_bDismissOnClick Then
        Unload Me
    End If
End Sub

Security Considerations ​

Content Injection Prevention ​

vb
' Validate user input before displaying
Private Function ValidateContent(ByVal Content As String) As String
    ' Remove dangerous characters
    ' Prevent XSS injection
    ' ...
    ValidateContent = Sanitize(Content)
End Function

Tag Name Security ​

vb
' Prevent malicious Tag names
Private Function ValidateTagName(ByVal TagName As String) As Boolean
    ' Check length
    If Len(TagName) > 100 Then Exit Function
    
    ' Check for illegal characters
    If InStr(TagName, "|") > 0 Then Exit Function
    If InStr(TagName, ";") > 0 Then Exit Function
    
    ValidateTagName = True
End Function

Compatibility Notes ​

VB6 Version Compatibility ​

  • Minimum required: VB6 SP6
  • Recommended: VB6 SP6 with latest updates

Windows Version Compatibility ​

  • Windows XP and later
  • Best performance on Windows 7 and later

Dependency Components ​

  • cShadow (for shadow effects)
  • Standard VB6 runtime libraries

Debugging Tips ​

Enable Debug Output ​

vb
' Add debug logging
Private Sub DebugLog(ByVal msg As String)
    Debug.Print "[cToast] " & msg
End Sub

' Log at key points
DebugLog "Creating popup: " & TagName
DebugLog "Closing popup: " & TagName

Check Popup Status ​

vb
' List all active popups
Sub ListActiveToasts()
    Dim Toast As New cToast
    Dim Keys As Collection
    Dim Key As Variant
    
    Set Keys = Toast.ActiveKeys
    
    Debug.Print "Active popups: " & Toast.Count
    For Each Key In Keys
        Debug.Print "  - " & CStr(Key)
    Next Key
End Sub

Monitor Event Triggers ​

vb
Private WithEvents Toast As cToast

Private Sub Toast_OnToastCountChange(ByVal TagName As String, _
                                     ByVal IsDelete As Boolean, _
                                     ByVal CurrentCount As Long)
    Debug.Print "Event: " & TagName & " " & _
                IIf(IsDelete, "Deleted", "Added") & _
                ", Count: " & CurrentCount
End Sub

Known Limitations ​

  1. Maximum Number of Popups: Limited by system resources, recommended not to exceed 50
  2. Display Position: 9 preset positions only, does not support arbitrary positioning
  3. Content Length: Extremely long text may affect display效果
  4. Multi-Monitor Support: Default is primary monitor, multi-monitor support requires modification
  5. Form Style: Cannot modify basic form properties (borderless, no control box)

VB6 and LOGO copyright of Microsoft Corporation