Category Archives: Visual Basic 6 (VB6)

Using WinSock

This module will allow you to create a WinSock connection, as well as resolve computernames to IPs and vice-versa. Module Option Explicit Public Const SOCKET_ERROR = -1Public Const AF_INET = 2Public Const PF_INET = AF_INETPublic Const MAXGETHOSTSTRUCT = 1024Public Const SOCK_STREAM = 1Public Const MSG_PEEK = 2 Private Type SockAddr    sin_family As Integer    sin_port As Integer    sin_addr As String * 4    sin_zero… Read More »

Get Remote Time and Date

Say you to check the time and date of a remote computer, be it a server or workstation. Here is how you do it. Module Option Explicit ‘API StructuresType TIME_OF_DAY_INFO    tod_elapsed As Long    tod_msecs As Long    tod_hours As Long    tod_mins As Long    tod_secs As Long    tod_hunds As Long    tod_timezone As Long    tod_tinterval As Long    tod_day As Long    tod_month As Long    tod_year As Long    tod_weekday As LongEnd Type ‘NetAPI CallsPublic Declare… Read More »

Copy picture to Clipboard

Copy what you see in the Screen or in a Form into the clipboard. Module Option Explicit Private Const CCHDEVICENAME = 32Private Const CCHFORMNAME = 32Private Const SRCCOPY = &HCC0020 ‘ (DWORD) destination = source Private Type DEVMODE    dmDeviceName As String * CCHDEVICENAME    dmSpecVersion As Integer    dmDriverVersion As Integer    dmSize As Integer    dmDriverExtra As Integer    dmFields As Long    dmOrientation As Integer    dmPaperSize As Integer    dmPaperLength As Integer    dmPaperWidth… Read More »

Tunnel graphical effect

Create a Form and place this code inside. Sorry but the comments are in german. Code Option Explicit Dim offx%                 ‘ x-offset zur mitteDim offy%                 ‘ y-offset zur mitteDim anz%                 ‘ anzahl sterneDim bahnx%(100, 180)     ‘ x-tabDim bahny%(100, 180)     ‘ y-tabDim starwi%(500)            ‘ anz%Dim starba%(500)            ‘ anz%Dim cosi(360)             ‘ cos-tabDim sini(360)             ‘ sin-tabDim st%Dim wert                 ‘ rad in degDim x%                    … Read More »

Check and Change Resolution

With a little API magic, you can check the current screen resolution, and change it at runtime if needed. Module Option Explicit ‘Declares: Public Declare Function GetSystemMetrics Lib “user32.dll” (ByVal nIndex As Long) As LongPrivate Declare Function EnumDisplaySettings Lib “user32.dll” Alias “EnumDisplaySettingsA” (ByVal lpszDeviceName As Long, ByVal iModeNum As Long, lpDevMode As Any) As BooleanPublic Declare Function ChangeDisplaySettings… Read More »

Desktop Color Settings

Use this code to read or set the current desktop color settings. Module Option Explicit Private Declare Function GetSysColor Lib “user32.dll” (ByVal nindex As Long) As LongPrivate Declare Function SetSysColors Lib “user32.dll” (ByVal nChanges As Long, lpSysColor As Long, lpColorValues As Long) As Long Public Enum WindowsItem    COLOR_ACTIVEBORDER = 10    COLOR_ACTIVECAPTION = 2    COLOR_APPWORKSPACE = 12    COLOR_BACKGROUND = 1    COLOR_BTNFACE = 15    COLOR_BTNHIGHLIGHT =… Read More »

Print a Text File

Simple method to print a text file to the default printer. Module Option Explicit Public Sub PrintTXTFile(FileName As String)    Dim x As Integer    Dim s As String     x = FreeFile    On Error GoTo HandleError    Open FileName For Input As x    Do While Not EOF(x)        Line Input #x, s        Printer.Print s    Loop    Printer.EndDoc    Close #x    Exit SubHandleError:    MsgBox “Error :” & Err.Description, vbCritical, “Printing File…”End Sub Usage Create a Form with… Read More »

Play an AVI in a Picturebox

Just a little bit of code will allow you to play AVI files within your application. Great for media players, instructional apps, etc. Module Const WS_CHILD = &H40000000 Private Declare Function mciSendString Lib “winmm.dll” Alias _    “mciSendStringA” (ByVal lpstrCommand As String, _    ByVal lpstrReturnString As String, ByVal uReturnLength As Long, _    ByVal hwndCallback As Long) As Long Private Declare Function mciGetErrorString… Read More »

Manage Windows Services

This code should give you everything your need to start, stop, pause, and get the status of services. Module Option Explicit ‘API ConstantsPublic Const SERVICES_ACTIVE_DATABASE = “ServicesActive”‘ Service ControlPublic Const SERVICE_CONTROL_STOP = &H1Public Const SERVICE_CONTROL_PAUSE = &H2’ Service State – for CurrentStatePublic Const SERVICE_STOPPED = &H1Public Const SERVICE_START_PENDING = &H2Public Const SERVICE_STOP_PENDING = &H3Public Const SERVICE_RUNNING = &H4Public… Read More »

Enumerate Domain or Local Users

Just like the title says, this will enumerate a list of users either on the local machine or one a Windows domain. Module Option Explicit ‘API typesPrivate Type USER_INFO    Name As String    Comment As String    UserComment As String    FullName As StringEnd Type Private Type USER_INFO_API    Name As Long    Comment As Long    UserComment As Long    FullName As LongEnd Type Public UserInfo(0 To 1000) As USER_INFO ‘API callsPrivate… Read More »