Executing Control Panel applets

The following code snippet shows how to execute standard Control Panel applets (Display Properties, Reginal Settings, Mouse Properties, and more) from Visual Basic code.


'Executing Control Panel applets from Visual Basic.
'Copyright (c) 2002 Nir Sofer
'
'Web site: http://nirsoft.mirrorz.com
'
'The following code snippet shows how to run standard Control Panel applets from Visual Basic.
'It is done by calling directly to the CPlApplet function of the appropriate .cpl file.

Private Type CPLINFO
    idIcon          As Long
    idName          As Long
    idInfo          As Long
    lData           As Long
End Type

'Declares for all Control Panel applets:
Private Declare Function CPlApplet_Desk Lib "desk.cpl" Alias "CPlApplet" _
(ByVal hwndCPl As Long, ByVal uMsg As Long, ByVal lParam1 As Long, ByVal lParam2 As Long) As Long
Private Declare Function CPlApplet_Intl Lib "intl.cpl" Alias "CPlApplet" _
(ByVal hwndCPl As Long, ByVal uMsg As Long, ByVal lParam1 As Long, ByVal lParam2 As Long) As Long
Private Declare Function CPlApplet_MMSys Lib "mmsys.cpl" Alias "CPlApplet" _
(ByVal hwndCPl As Long, ByVal uMsg As Long, ByVal lParam1 As Long, ByVal lParam2 As Long) As Long
Private Declare Function CPlApplet_Access Lib "access.cpl" Alias "CPlApplet" _
(ByVal hwndCPl As Long, ByVal uMsg As Long, ByVal lParam1 As Long, ByVal lParam2 As Long) As Long
Private Declare Function CPlApplet_AppWiz Lib "appwiz.cpl" Alias "CPlApplet" _
(ByVal hwndCPl As Long, ByVal uMsg As Long, ByVal lParam1 As Long, ByVal lParam2 As Long) As Long
Private Declare Function CPlApplet_InetCpl Lib "inetcpl.cpl" Alias "CPlApplet" _
(ByVal hwndCPl As Long, ByVal uMsg As Long, ByVal lParam1 As Long, ByVal lParam2 As Long) As Long
Private Declare Function CPlApplet_Telephon Lib "telephon.cpl" Alias "CPlApplet" _
(ByVal hwndCPl As Long, ByVal uMsg As Long, ByVal lParam1 As Long, ByVal lParam2 As Long) As Long
Private Declare Function CPlApplet_TimeDate Lib "timedate.cpl" Alias "CPlApplet" _
(ByVal hwndCPl As Long, ByVal uMsg As Long, ByVal lParam1 As Long, ByVal lParam2 As Long) As Long
Private Declare Function CPlApplet_TweakUI Lib "tweakui.cpl" Alias "CPlApplet" _
(ByVal hwndCPl As Long, ByVal uMsg As Long, ByVal lParam1 As Long, ByVal lParam2 As Long) As Long
Private Declare Function CPlApplet_mlcfg32 Lib "mlcfg32.cpl" Alias "CPlApplet" _
(ByVal hwndCPl As Long, ByVal uMsg As Long, ByVal lParam1 As Long, ByVal lParam2 As Long) As Long
Private Declare Function CPlApplet_Main Lib "main.cpl" Alias "CPlApplet" _
(ByVal hwndCPl As Long, ByVal uMsg As Long, ByVal lParam1 As Long, ByVal lParam2 As Long) As Long

'Control Panel Messages Constants:
Private Const CPL_INIT = 1
Private Const CPL_GETCOUNT = 2
Private Const CPL_INQUIRE = 3
Private Const CPL_SELECT = 4
Private Const CPL_DBLCLK = 5
Private Const CPL_STOP = 6
Private Const CPL_EXIT = 7
Private Const CPL_NEWINQUIRE = 8

Private ci      As CPLINFO

Private Sub MainCplApplet(lParam1 As Long)
    If CPlApplet_Main(hWnd, CPL_INIT, 0, 0) <> 0 Then
        CPlApplet_Main hWnd, CPL_INQUIRE, lParam1, VarPtr(ci)
        CPlApplet_Main hWnd, CPL_DBLCLK, lParam1, ci.lData
        CPlApplet_Main hWnd, CPL_STOP, 0, ci.lData
        CPlApplet_Main hWnd, CPL_EXIT, 0, 0
    End If
End Sub

'Accessibility Properties
Private Sub cmdAccessibility_Click()
    If CPlApplet_Access(hWnd, CPL_INIT, 0, 0) <> 0 Then
        CPlApplet_Access hWnd, CPL_INQUIRE, 0, VarPtr(ci)
        CPlApplet_Access hWnd, CPL_DBLCLK, 0, ci.lData
        CPlApplet_Access hWnd, CPL_STOP, 0, ci.lData
        CPlApplet_Access hWnd, CPL_EXIT, 0, 0
    End If
End Sub

'Add/Remove Programs
Private Sub cmdAddRemoveProg_Click()
    If CPlApplet_AppWiz(hWnd, CPL_INIT, 0, 0) <> 0 Then
        CPlApplet_AppWiz hWnd, CPL_INQUIRE, 0, VarPtr(ci)
        CPlApplet_AppWiz hWnd, CPL_DBLCLK, 0, ci.lData
        CPlApplet_AppWiz hWnd, CPL_STOP, 0, ci.lData
        CPlApplet_AppWiz hWnd, CPL_EXIT, 0, 0
    End If
End Sub

'Date/Time Properties
Private Sub cmdDateTime_Click()
    If CPlApplet_TimeDate(hWnd, CPL_INIT, 0, 0) <> 0 Then
        CPlApplet_TimeDate hWnd, CPL_INQUIRE, 0, VarPtr(ci)
        CPlApplet_TimeDate hWnd, CPL_DBLCLK, 0, ci.lData
        CPlApplet_TimeDate hWnd, CPL_STOP, 0, ci.lData
        CPlApplet_TimeDate hWnd, CPL_EXIT, 0, 0
    End If
End Sub

'Dialing Properties
Private Sub cmdDial_Click()
    If CPlApplet_Telephon(hWnd, CPL_INIT, 0, 0) <> 0 Then
        CPlApplet_Telephon hWnd, CPL_INQUIRE, 0, VarPtr(ci)
        CPlApplet_Telephon hWnd, CPL_DBLCLK, 0, ci.lData
        CPlApplet_Telephon hWnd, CPL_STOP, 0, ci.lData
        CPlApplet_Telephon hWnd, CPL_EXIT, 0, 0
    End If
End Sub

'Display Properties
Private Sub cmdDisplay_Click()
    If CPlApplet_Desk(hWnd, CPL_INIT, 0, 0) <> 0 Then
        CPlApplet_Desk hWnd, CPL_INQUIRE, 0, VarPtr(ci)
        CPlApplet_Desk hWnd, CPL_DBLCLK, 0, ci.lData
        CPlApplet_Desk hWnd, CPL_STOP, 0, ci.lData
        CPlApplet_Desk hWnd, CPL_EXIT, 0, 0
    End If
End Sub

'Internet
Private Sub cmdInternet_Click()
    If CPlApplet_InetCpl(hWnd, CPL_INIT, 0, 0) <> 0 Then
        CPlApplet_InetCpl hWnd, CPL_INQUIRE, 0, VarPtr(ci)
        CPlApplet_InetCpl hWnd, CPL_DBLCLK, 0, ci.lData
        CPlApplet_InetCpl hWnd, CPL_STOP, 0, ci.lData
        CPlApplet_InetCpl hWnd, CPL_EXIT, 0, 0
    End If
End Sub

'Keyboard Properties
Private Sub cmdKeyboard_Click()
    MainCplApplet 1
End Sub

'Mail Properties
Private Sub cmdMail_Click()
    If CPlApplet_mlcfg32(hWnd, CPL_INIT, 0, 0) <> 0 Then
        CPlApplet_mlcfg32 hWnd, CPL_INQUIRE, 0, VarPtr(ci)
        CPlApplet_mlcfg32 hWnd, CPL_DBLCLK, 0, ci.lData
        CPlApplet_mlcfg32 hWnd, CPL_STOP, 0, ci.lData
        CPlApplet_mlcfg32 hWnd, CPL_EXIT, 0, 0
    End If
End Sub
'Mouse Properties
Private Sub cmdMouse_Click()
    MainCplApplet 0
End Sub

'Multimedia Properties
Private Sub cmdMultimedia_Click()
    If CPlApplet_MMSys(hWnd, CPL_INIT, 0, 0) <> 0 Then
        CPlApplet_MMSys hWnd, CPL_INQUIRE, 0, VarPtr(ci)
        CPlApplet_MMSys hWnd, CPL_DBLCLK, 0, ci.lData
        CPlApplet_MMSys hWnd, CPL_STOP, 0, ci.lData
        CPlApplet_MMSys hWnd, CPL_EXIT, 0, 0
    End If
End Sub

'Regional Settings
Private Sub cmdRegional_Click()
    If CPlApplet_Intl(hWnd, CPL_INIT, 0, 0) <> 0 Then
        CPlApplet_Intl hWnd, CPL_INQUIRE, 0, VarPtr(ci)
        CPlApplet_Intl hWnd, CPL_DBLCLK, 0, ci.lData
        CPlApplet_Intl hWnd, CPL_STOP, 0, ci.lData
        CPlApplet_Intl hWnd, CPL_EXIT, 0, 0
    End If
End Sub

'Tweak UI
Private Sub cmdTweakUI_Click()
    If CPlApplet_TweakUI(hWnd, CPL_INIT, 0, 0) <> 0 Then
        CPlApplet_TweakUI hWnd, CPL_INQUIRE, 0, VarPtr(ci)
        CPlApplet_TweakUI hWnd, CPL_DBLCLK, 0, ci.lData
        CPlApplet_TweakUI hWnd, CPL_STOP, 0, ci.lData
        CPlApplet_TweakUI hWnd, CPL_EXIT, 0, 0
    End If
End Sub


Download the entire project