Home
Search
 
What's New
Index
Books
Links
Q & A
Newsletter
Banners
 
Feedback
Tip Jar
 
C# Helper...
 
XML RSS Feed
Follow VBHelper on Twitter
 
 
 
MSDN Visual Basic Community
 
 
 
 
 
TitleShow memory usage while creating and removing windowed and windowless ActiveX controls
DescriptionThis example shows how to show memory usage while creating and removing windowed and windowless ActiveX controls in Visual Basic 6.
Keywordsmemory usage, memory, GlobalMemoryStatus, windowless, ActiveX, ActiveX control
CategoriesActiveX Controls, ActiveX, Controls
 
The cmdMakeWindowed button makes or removes a windowed ActiveX control. It then calls subroutine ShowStatistics to show the memory usage. The cmdMakeWindowless is similar except it makes a windowless control.
 
Private Sub cmdMakeWindowed_Click()
Dim ctl As Control

    If cmdMakeWindowed.Caption = "Remove Windowed" Then
        Me.Controls.Remove "windowed_control"
        cmdMakeWindowed.Caption = "Make Windowed"
    Else
        Set ctl = _
            Me.Controls.Add("Project1.WindowedControl", _
            "windowed_control")
        With ctl
            .Move Label2.Left + Label2.Width, Label2.Top
            .Visible = True
        End With
        cmdMakeWindowed.Caption = "Remove Windowed"
    End If

    DoEvents
    ShowStatistics
End Sub
 
Subroutine ShowStatistics uses the GlobalMemoryStatus API function to get information about the system's global memory. It displays the information and the difference between the current usage and the that of the last time the routine ran.
 
Private Sub ShowStatistics()
Static old_mem As MEMORYSTATUS
Dim mem As MEMORYSTATUS
Dim txt As String

    GlobalMemoryStatus mem

    With mem
        txt = txt & "% used:                " & _
            Format$(.dwMemoryLoad, "@@@@@@@@@@@") & vbCrLf
        txt = txt & "Total physical memory: " & _
            Format$(.dwTotalPhys, "@@@@@@@@@@@") & vbCrLf
        txt = txt & "Physical memory free:  " & _
            Format$(.dwAvailPhys, "@@@@@@@@@@@") & vbCrLf
        txt = txt & "Total page file size:  " & _
            Format$(.dwTotalPageFile, "@@@@@@@@@@@") & _
            vbCrLf
        txt = txt & "Free page file size:   " & _
            Format$(.dwAvailPageFile, "@@@@@@@@@@@") & _
            vbCrLf
        txt = txt & "Total virtual memory:  " & _
            Format$(.dwTotalVirtual, "@@@@@@@@@@@") & vbCrLf
        txt = txt & "Free virtual memory:   " & _
            Format$(.dwAvailVirtual, "@@@@@@@@@@@") & vbCrLf
    End With
    Label1.Caption = txt

    If old_mem.dwMemoryLoad > 0 Then
        txt = ""
        txt = txt & Format$(mem.dwMemoryLoad - _
            old_mem.dwMemoryLoad, "@@@@@@@@@@@") & vbCrLf
        txt = txt & Format$(mem.dwTotalPhys - _
            old_mem.dwTotalPhys, "@@@@@@@@@@@") & vbCrLf
        txt = txt & Format$(mem.dwAvailPhys - _
            old_mem.dwAvailPhys, "@@@@@@@@@@@") & vbCrLf
        txt = txt & Format$(mem.dwTotalPageFile - _
            old_mem.dwTotalPageFile, "@@@@@@@@@@@") & vbCrLf
        txt = txt & Format$(mem.dwAvailPageFile - _
            old_mem.dwAvailPageFile, "@@@@@@@@@@@") & vbCrLf
        txt = txt & Format$(mem.dwTotalVirtual - _
            old_mem.dwTotalVirtual, "@@@@@@@@@@@") & vbCrLf
        txt = txt & Format$(mem.dwAvailVirtual - _
            old_mem.dwAvailVirtual, "@@@@@@@@@@@") & vbCrLf
        Label2.Caption = txt
    End If
    old_mem = mem
End Sub
 
 
Copyright © 1997-2010 Rocky Mountain Computer Consulting, Inc.   All rights reserved.
  Updated