Get a LIFETIME subscription to Code of the Week for only $49.95 (regularly $59.95). Just jump to our SECRET order page at http://www.codeoftheweek.com/orderforms/lifetime4995.html and see everything you get with this outstanding offer!
Download a free copy of NetMon - Your Internet Performance Monitor at http://www.codeoftheweek.com/netmon/index.html
In this issue we show how to launch control panel applets.
This source code is designed for VB 5.0 32-bit and up. Questions? Email us at questions@codeoftheweek.com.
The cControlPanel class module contains several routines to start some common control panel applets. It is very easy to customize for any additional applets you want to start.
If you have any questions about using this class, let us know at questions@codeoftheweek.com
Public Function LaunchControlPanelApplet(sAppletName As String, _ Optional AppWinStyle As VbAppWinStyle = vbNormalFocus, _ Optional lTab As Long = -1, _ Optional lAppletNumber As Long = 0)
This function provides the ability to launch any control panel applet with the information provided. The sAppletName is the CPL file to launch. See the Other Information section below for some examples. The AppWinStyle is what the window style will be when launched. For example, you might not want the window to get focus right away so you can set it to vbNormalNoFocus. This parameter is optional.
The lTab and lAppletNumber are also optional. The lTab parameter allows you to select which tab is shown when the applet is started. The lAppletNumber parameter allows you to start a particular applet within the sAppletName applet. Sometimes there are more than one applet in a single CPL file.
Public Function AddRemovePrograms() As Boolean
Launches the Add/Remove control panel applet.
Public Function Joystick() As Boolean
Launches the Joystick control panel applet.
Public Function Display() As Boolean
Launches the display properties control panel applet.
Public Function ScreenSaver() As Boolean
Launches the display properties control panel applet and then jumps to the screen saver tab.
Public Function System() As Boolean
Launches the system properties control panel applet.
Public Function SystemDevices() As Boolean
Launches the system properties control panel applet and then jumps to the device manager tab.
Currently these routines will always return True.
Most CPL files are stored in the Windows System directory. You can use the Find Files feature to locate all the ones installed on your system. Some other common control panel applets that you might want to use are:
The below sample describes how to use the cControlPanel class. It assumes you have created a form and added the following code to it. Make sure the form has a list box called lstApps and a command button called cmdActions.
Option Explicit Private Sub cmdAction_Click() Dim ControlPanel As New cControlPanel With ControlPanel Select Case lstApps.ListIndex Case 0 .AddRemovePrograms Case 1 .Joystick Case 2 .Display Case 3 .ScreenSaver Case 4 .System Case 5 .SystemDevices End Select End With End Sub Private Sub Form_Load() lstApps.AddItem "Add/Remove Programs" lstApps.AddItem "Joystick" lstApps.AddItem "Display" lstApps.AddItem "Screen Saver" lstApps.AddItem "System Properties" lstApps.AddItem "System Devices" cmdActions.Caption = "Execute" End Sub
To see the source code for this issue you must be a subscriber to Code of the Week. If you are a subscriber the source code is available at the following address: http://www.codeoftheweek.com/membersonly/bi/0077.html