BenEskew.com Just another web developer's personal weblog.

11Sep/090

Visual Basic Code Snippets #6

In this next update I'll continue to re-post my Visual Basic code snippets (which are older than five years by the way) that pertain to System Functions.

Hide/Show Your Application from Task Manager

Compatibility: Win. 98-ME

Add the following code into a module within your project...

Public Declare Function GetCurrentProcessId Lib "kernel32" () As Long
Public Declare Function GetCurrentProcess Lib "kernel32" () As Long
Public Declare Function RegisterServiceProcess Lib "kernel32" (ByVal dwProcessID As Long, ByVal dwType As Long) As Long
Public Const RSP_SIMPLE_SERVICE = 1
Public Const RSP_UNREGISTER_SERVICE = 0

Public Sub removeCtrlAltDel()
'only works on win98/ME
Dim pid As Long
Dim lngRet As Long
pid = GetCurrentProcessId()
lngRet = RegisterServiceProcess(pid, RSP_SIMPLE_SERVICE)
End Sub

Public Sub showCtrlAltDel()
'only works on win98/ME
Dim pid As Long
Dim lngRet As Long
pid = GetCurrentProcessId()
lngRet = RegisterServiceProcess(pid, RSP_UNREGISTER_SERVICE)
End Sub

Add the following code wherever you want the Hide code to execute...

Call removeCtrlAltDel()

Add the following code wherever you want the Show code to execute...

Call showCtrlAltDel()

Get and Show Windows Runtime

Compatibility: Win. 98-XP

Add the following code into a module within your project...

Public Declare Function GetTickCount& Lib "kernel32" ()

Public Function windowsRuntime(lbl As Label)
Dim lngReturn As Long
lngReturn = GetTickCount()
lbl.Caption = "Windows has been running for " & (lngReturn / 1000) & " seconds."
End Function

Add a label named Label1 to a form and add the following code...

Call windowsRuntime(Label1) 'Label1 being the display label.

Add All Available System Fonts to List

Compatibility: Win. 98-XP

Add the following code into a module within your project...

Public Function AddFontsList(Lis As ListBox)
For X = 0 To Screen.FontCount - 1
Lis.AddItem Screen.Fonts(X)
Next X
End Function

Add a ListBox named List1 and add the following code wherever you want the code to execute...

Call AddFontsList(List1)

Visual Basic Code Snippets #7