VB 6.0 System Related...

Change the Screen Resolution
Change the screen resolution from VB using the EnumDisplaySettings and ChangeDisplaySettings APIs.

Code Based Timers
Create a code based timer that's more accurate with better resolution than VB's Timer control. The timer resides in an ActiveX DLL and doesn't need to be sited on a form. You can use it in applications that run unattended and that have no visual interface. Also make counting timers and timers that callback your app when they trigger.

Create Your Own Screen Saver or Start an Existing Screen Saver
Develop fancy screen savers with VB. Mine shows a number of animated images, called sprites, moving around the screen glancing off its edges and ricocheting off each other. The screen saver is fully customizable, allows password protection, and runs in the screen saver preview window.

Determining Memory Statistics and System Resources
Retrieve the current state of the system's memory using the GlobalMemoryStatus function. On Windows 9x machines you can determine the system resource values displayed in Explorer's Help About dialog by using the Resource Meter's Rsrc32.dll. Use this info to determine to if there are enough reources to safely start your application.

Disable Ctrl-Alt-Delete, Alt-Tab and Ctrl-Esc Key Sequences
Prevent users from rebooting a PC by telling Windows the screen saver is running. Stop Ctrl-Esc and the Windows key from displaying the Start Menu.

Shut Down/Restart Windows
Shut down and Restart Windows via the ExitWindowsEx API. On WinNT and Win2K you can shut down windows after giving your application sufficient privilege to do so.

System Metrics Information
The GetSystemMetrics function returns a wealth of information including the width and height of the screen, window, icon, border, caption, scroll bar elements and more.

System Parameters Information
The SystemParametersInfo function queries systemwide parameters and provides information about the mouse, keyboard, desktop, icons size, screen saver,... This example also demonstrates how to get the Window's version using GetVersionEx.

Add Your Application's Icon to the System Tray
Add your application's icon to the System Tray and respond to mouse events occurring on your system tray icon. Work with ActiveX components from the system tray. Normally this is not possible due to the way Windows handles Remote Procedure Calls.

Locale Aware Date Format
Get the Locale specific Date and Number formats. If your regional settings are set to German, the standard date looks like "dd.mm.yy". Convert to the proper date format based on the locale.

List and Change Window's Date Formats
Enumerate all Long and Short Date formats currently defined on your system. Create new ones and change them on the fly!

Synchronize Your System's Time With an NTP Server
Retrieve the time from a public Network Time Protocol (NTP) server via the Winsock control then use it set your PC's time.

Create a System DSN
Programmatically create a system Data Source Name.

VB 6.0 Window Related ...

Create Multi-Line ToolTips
Create ToolTtip windows with text that spans multiple lines and contains text formatting characters such as vbCrLf and vbTab.

Enumerate all Windows in the System
List all top-level windows currently in existence, extract each window's handle, class name, title, process and thread IDs. See how to relate window and process information, use callback functions and Set Tab Stops in a ListBoxes.

Restore or Minimize One or All Windows
Query a window's current state (minimized, restored or maximized) and return it to its normal state. You can also minimize or restore ALL open windows.

Bring a Window to the Foreground
Making a form the foreground window requires determining the foreground thread and attaching it to your window, using AttachThreadInput, then calling SetForegroundWindow.

Spy on the Window Under the Cursor
Move the cursor over any window and get its caption, text, style, extended style, size, thread ID, process ID and its parent window's handle and text.

NOTE: you can also display the actual text of encoded password fields. However, by subclassing you can properly protect your passwords.

Capture and Print a Form, the Screen or Any Portion of Any Window
Capture any part of any window, including the desktop window, and created a bitmap out of it. Then send this image to your printer.

VB 6.0 Window Process Related...

Enumerate All Processes Currently Running
On Win9x and Win2K machines it is a snap to enumerate all the processes running. Use CreateToolHelpSnapshot to create a snapshot of the processes then loop through the snapshot with the Process32First and Process32Next functions. On NT you need to use the functions available in PSAPI.dll.

Simulate Window's Alt-Tab List
List the applications running like Windows does when you press the ALT-TAB keys. Applications listed are those that appear on the taskbar.

Also see how to switch between applications and correctly bring an application to the foreground.

Determine if an Application has Stopped Responding
See if an application is hung or has stopped responding then kill it if is has.

Safely Stop a Running Process
The correct way to close another application from your program is to close all of the application's parent windows. Here's how.

Wait for a Process to Terminate
Start another program from your app and wait for it to end before processing your next instruction. The WaitForSingleObject API allows you to do this. You can even wait for DOS applications to finish.

Wait for a Process to Terminate with Windows Scripting Host
The Windows Scripting Host (WSH) lets you start an application and run it either asynchronously or modally. Call its Run method and tell it whether to wait for the application to terminate or not.

Start Control Panel Applets or Dial Up Networking,
Format Floppies, De-Brand Internet Explorer

Rundll32.exe lets you open Control Panel applets, launch Dial Up Networking and format floppy disks. You can also do this with Explorer.

Open/Print Files, View Web Sites, Connect to the Internet
Determine the application associated with a given file type then open or print the file with the associated application. Start your default browser and view a particular web site or pre-fill E-Mail fields such as To:, CC:, Subject:,...

See how to automatically dial the Internet and disconnect when you are done using the InternetAutodial and InternetAutodialHangup functions of Wininet.dll. Use the Microsoft Internet Control to web enable your apps.

Enumerate DUN connections and connect to the Internet
List your Dial-Up Networking (DUN) connections. Use the the Internetdial and InternetHangup functions of Wininet.dll to establish a DUN connection to the internet.

Pass Strings and Data Between VB Applications
Pass data from one VB app to another, without COM, even though the apps run in separate process spaces. The receiving app automatically detects and processes the data.

Perform Interprocess Commumication With DDEML
Transfer data between applications and send commands to another application using the Dynamic Data Exchange Management Library.

VB 6.0 File System and Windows Registry Related...

Register and Unregister ActiveX Components
Register and unregister ActiveX DLLs and OCXs from VB without running Regsvr32.exe.

Touch Files
Set file creation, modified and last accessed dates.

Windows-Like File Operations
Copy, move, rename and delete files and folders or send them to the Recycle Bin displaying the same dialog boxes, status and confirmation messages, and progress indicators as Windows.

Using the Scripting Runtime Engine's FileSystemObject
The Scripting Runtime Engine (Scrrun.dll) FileSystemObject simplifies file operations like copying, moving and deleting files and folders, querying drive, folder or file information and reading and writing text files.

Get the Paths of the Windows and System Folders
Find the Location of your Executable and
Convert Long Path Names to Short (8 Character) Names

Determine where the Windows and System folders reside. Dynamically find out where your executable lives. App.Path isn't reliable when your .Exe lives on a server.

Convert long path names to their equivalent short path names. Example: C:\Program Files\My becomes C:\Progra~1\Mybrie~.

Get Windows Special Folders Paths
Use the SHGetFolderPath API to get the path to folders such as: Windows, System, My Documents, My Pictures, Application Data,... This is the recommended way to find these folders under Windows XP.

Automatically Detect When the Contents of a Folder Change
Have Windows alert your application whenever a folder or any of its sub-folders change. Changes detected include copying, deleting, renaming files as well as changing the size or attributes of any files in the folder.

Browse for Files, Folders, Computer and Printers
The SHBrowseForFolder API lets you invoke a system dialog used to browse for files and folders on your hard drive as well as network computers and printers.

Registry/Ini File Function Library
This ready to use .Bas module is full of functions to perform common Registry and/or .Ini file operations such as reading, setting, deleting and enumerating values and keys. It is self contained and can be included in your application. Or, use it as a starting point to write your own functions. It illustrates all the common registry and .Ini API functions.

Registry Operations Simplified w/ Windows Scripting Host
The Windows Scripting Host (WSH) trivializes registry tasks normally requiring much more code. Wshom.ocx lets you perform basic reading, writing and deleting of registry values and keys. You can use the common registry data types and access any part of the registry.

You can also create .VBS files to contain and execute your VB script code allowing you to create powerful batch files.

Create Desktop Shortcuts, Get Special Folder Locations,
and Refresh the Desktop (Part I)

Create Desktop shortcuts using standard API calls by creating a .Lnk file in the Recent Files folder then moving it to the Desktop. This method does not let you set all shortcut properties. Also, see my next two samples.

Also see how to refresh the desktop and get the location of the Desktop, Recycle Bin, Control Panel Recent Files and other special folders.

Create Shortcuts (Shell Links) (Part II)
Create shortcuts (shell links - .lnk files) with the iShellLnk interface and set ALL shortcut properties. Determine the location of special folders such as the desktop, start menu, recent files,...

Create Desktop & Internet Shortcuts (Part III)
Here's the easiest way yet to create shortcuts (shell links - .lnk files) and internet shortcuts. Use the Windows Scripting Host (WSH).

Extract Icons From EXEs and DLLs
View the icons in an .Exe or .Dll and extract them to a PictureBox or other control with a device context handle (.hdc). You can also draw them to controls without .hdc's such as an ImageList. This is useful when creating toolbars where you need to dynamically add icons at run time.

Change the Text and Background Color of Desktop Icons
Learn about the desktop and how to programmatically customize it. Change the color of the text and the text's background on your desktop icons.

Replace Files that are Currently In Use
Delete, rename, or move files that are currently being used by the system.

View and Extract the Contents of CAB Files
Programmatically view and extract the contents of cabinet (.CAB) files with the SetupIterateCabinet API.

Digitally Sign and Verify Files
Protect files from tampering by digitally signing them. Digitally sign files with private keys then electronically transmit them along with the public keys to an associate. Using the public key your associate can verify the files insuring they were not tampered with or corrupted during transmission.

Use the Internet Transfer Control to FTP files
The Internet Transfer Control allows you to FTP files to and from a remote computer. My class module provides methods to transfer one or more files.

Retrieve File Version Information
Read national language, code page, target OS, version, ... info as well as the developer's comment, description, copyright and trademark info from EXEs, OCXs, DLLs, device drivers, and font files.

VB 6.0 WinForm and Control Related...

Tile and Center Images on the Background of MDI Forms.
Learn how to tile an image across the background of an MDI form or how to center an image on the background or even tile one image then center another image over it.

Irregularly Shaped Forms
Develop elliptically shaped forms and controls, forms with rounded corners, forms with see through holes in them or forms that spell out words such as "THE SCARMS". Use flashing title bars and gradient background colors that change.

Create an Active Skin (Irregular Shaped Form Based on Any Image)
Create an active skin resembling any image that you can change by dragging a new image onto it. Likewise, add and remove skin shaped buttons with a simple drag operation.

Forms with Transparent or Gradient Backgrounds
Add Bitmaps to Your Menus
Remove/Disable the Close ("X") Button

Make a form's background fade from light to dark or make it completely transparent.

Also, see how add bitmap images to your menus and how to disable the Close ("X"), Minimize and Maximize buttons in the title bar.

Toggle and Change the TitleBar and Border Style at Run Time
Toggle the TitleBar on and off and change the border style of your form at run time. Add and remove the Minimize, Maximize and WhatsThisHelp buttons and System Menu at runtime.

Animate How Forms are Displayed and Hidden,
Make Translucent Forms or Tile an Image Across your Form

Windows 98 and later provides the ability to slide your form in or out of view. See how to tile an image across the entire background of your form.

Windows 2000 introduced layered windows which let you make windows with varying degrees of translucency from invisible windows to fully opaque using the SetLayeredWindowAttributes function.

Prevent the Cursor From Moving Off Your Form
The ClipCursor API lets you define a region of the screen and restrict the cursor to within that region.

Copy the Desktop Wallpaper to a Form's Background
Set your form's background to the desktop wallpaper.

Create a Scrollable Form
Add more controls than can fit on the visible portion of a form and scroll though the form moving the controls into and out of view.

Dynamically Add Controls and Create a Scrollable Form
Dynamically add and remove controls at runtime using the controls collection, add controls to any container control and not the form itself, detect events from the new controls and create a scrollable form.

Move A Form Without A Title Bar/Resize Controls
Method one retrieves the X and Y coordinates of the cursor and then moves the form to that locatoin. Method two calls ReleaseCapture and SendMessage to move the form.

Let users resize a form's controls at runtime.

Change a Control's Style / Owner Drawn Controls
See how to change the font of individual ListBox items by changing the Style of the control. Creating Owner Drawn controls lets you customize VB's intrinsic controls to look the way you want.

Read a discussion of hooks and how to use them in Visual Basic.

ListBox Functions Galore
Customize ListBoxes and ComboBoxes to add Tab Stops and align data in columns. Right Justify columns, automatically locate items as you type, and speed up operations such as adding, deleting, selecting and locating items.

Create a Dockable, AutoHide AppBar
The Window's taskbar and IE4+ toolbars are called Appbars. Create an Appbar which can float or be docked to a screen edge and can be set to AutoHide.

Dock Your Forms
Create child forms that you can dock to the edges of your main form. Child forms used are Toolbar type windows. See how to create toolbar and ToolTip windows.

Edit Data in a Read Only Grid
Use a floating textbox to edit data in the read only Microsoft FlexGrid control.

Create 3 Dimensional Text
Create 3 Dimensional text effects.

Use Manifests for Windows XP Look and Feel

Use a Manifest file to tell Windows XP's theme manager to use version 6 of comctl32.dll to give your application's controls the look and feel of XP.

Create Multi-Line ToolTip Windows
Create popup ToolTip windows containing more than one line and control characters such as TABs.

VB 6.0 Sub Classing Related...

Sub-Class Your Form to Intercept Window's Messages
Hook into the Window's message stream. Trap messages and react to or ignore events not normally available in Visual Basic. Learn the difference between subclassing and setting hooks.

Sub-Classing TextBox Controls
Stop adding the same code over again to all your textboxes. Subclass the textbox and use Multicasting to create a textbox object that consolidates your code into one location. Then create as many instances of the textbox object as needed. All will inherit the same behavior.

Sub-Class Textbox & Combobox Controls
Learn how to replace the context menu that is displayed when you right click on a textbox with your own popup menu.

Numeric/Uppercase TextBox with Undo Capabilities
Subclass TextBoxes so they only accept characters 0 through 9 or Uppercase letters. Add Undo capabilities to textboxes relieving you of the need to detect and track changes.

VB6.0 Multi-Media Samples...

Play Wave Files and Adjust Their Volume
Open and Close the CD Tray

Play Wave (.wav) files and adjust the waveout volume. Open and close the CD tray programmatically.

Create and Play Wave Files
Create your own Wave (.wav) files. Save them to disk or retain them in memory and play them back.

A Skinnable MP3 Player
Play MP3 files using Windows Media Player and a skinnable form.

Create Transparent Bitmaps
Create a bitmap with a transparent background using memory Device Contexts and various GDI functions.

Animated Sprites
Animated Sprites are continually changing pictures, possibly with irregular shapes, that can be moved in all directions on the desktop allowing the desktop to show through their background.

Create and Edit Images With This Full Featured Paint Application
This application lets you create or enhance images much as you would in Microsoft's Paint program. It has a wealth of drawing and color editing tools, screen capture capabilities, twain support, and wide variety of color filters and special effects.

Connect 4 Game
This is the classic Connect 4 game with ten levels of play.

Excel and Word Samples...

Using the Excel Object Library
Manipulate Excel spreadsheets from within VB. Add, change, copy, retrieve, delete data. Change fonts, cell color and format. Add formulas, view or print the results.

Load Excel Data into the DataGrid
Establish an ADO connection to your Excel worksheet and open a recordset against it. Then bind the recordset to the grid. All the recordset object's methods and features are available.

Add Microsoft Word's Spell Checker to your Apps
Invoke the Microsoft Word Object Library to add spell checking and thesaurus capabilities to your applications.

Miscellaneous VB 6.0 Samples...

E-Mail Enable Apps With MAPI
Using MAPI (Messaging API) you can send e-mail that includes file attachments from your application.

Create a Macro Processor to Interpret Source Code
Expose Your App's Object Model with the Script Control

Create and execute VB statements at run time. Read a complete procedure from a database and have your program run it. Let users call the methods of the objects used in your application. The Microsoft Script Control behaves as a macro engine allowing you to add and execute VBScript or JavaScript commands at run time and make your application scriptable.

String Functions, Assign Arrays, Dynamic Control Addition,
Validate/CausesValidation, Call by Name

Learn about the Join, Split, StrReverse, InStrRev, Replace, Filter functions, Array Assignment, Call by Name and the Validate event and CausesValidation property.

Encrypt and Decrypt Strings
Encrypt strings and prevent others from determining their contents. Usefull when storing passwords, PINs and other sensitive information.

OLE Automation Error Messages
Retrieve the error text associated with OLE Automation errors such as error -214741809. A must when developing ActiveX components.

Calculate Month End and Quarter End Dates
This class module lets you to calculate the current or next month end and quarter end dates taking into account leap years.

Perform Binary Searches on Arrays and Files
Learn how to perform the faster of all searches - the binary search.

Create a Web Report From Your Data.
My ready to use class module allows you to display the data in your recordset in a web browser by wrapping it with the appropriate HTML tags.

Perform Serial Port I/O
Here is a module containing a collection of routines to perform serial port I/O without using the Microsoft Comm Control component.

Get your PC's Network Interface Card's MAC Address.
A MAC Address is a unique 48 bit number assigned to each Network Interface Card (NIC) by its manufacturer. This sample shows how to get your computer's MAC Address in VB6 with the help of a number of Windows APIs.

About TheScarms
About TheScarms

Sample code
version info

If you use this code, please mention "www.TheScarms.com"

Email this page

© Copyright 2024 TheScarms
Goto top of page