添加菜单项到“开始”按钮的右键快捷菜单 刘红军 2000年 第28期   有些软件实现了把菜单项添加到Windows“开始”按钮的右键快捷菜单中,你想不想让自己的程序也通过这种方式运行呢?这是很诱人的,也不难实现,直接修改系统注册表就能做到。把下面的代码放在你自己的程序中,即可由软件实现用户自己选择菜单项的添加或撤消。下面用VB6.0调用API函数实现:   首先,在Form1中添加Command1和Check1,主要属性设置:   Command1的Caption=″确定″;   Check1的Caption=″将本程序添加到′开始′按钮的右击快捷菜单″,Value=1-Checked。   代码如下:   ′通用声明   Private Declare Function RegCreateKey Lib ″advapi32.dll″ Alias ″RegCreateKeyA″ (ByVal hKey As Long, ByVal lpSubKey As String, phkResult As Long) As Long   Private Declare Function RegSetValueEx Lib ″advapi32.dll″ Alias ″RegSetValueExA″ (ByVal hKey As Long, ByVal lpValueName As String, ByVal Reserved As Long, ByVal dwType As Long, lpData As Any, ByVal cbData As Long) As Long   Private Declare Function RegDeleteKey Lib ″advapi32.dll″ Alias ″RegDeleteKeyA″ (ByVal hKey As Long, ByVal lpSubKey As String) As Long   Private Declare Function RegCloseKey Lib ″advapi32.dll″ (ByVal hKey As Long) As Long   Private Const REG_SZ = 1   Private Const HKEY_LOCAL_MACHINE = &H80000002   ′按钮代码   Private Sub Command1_Click()    Dim hKey As Long    Dim lRet As Long    Dim strRunCmd As String    Dim strMenuName As String    ′strRunCmd为本程序的完整路径和文件名    strRunCmd = App.Path & ″\″ & App.EXEName & ″.exe″    strMenuName = ″我的应用程序″    Select Case Check1.Value    Case 1    ′在主键HKEY_LOCAL_MACHINE\Software\CLASSES\Directory\shell下创建主键abcd    lRet = RegCreateKey(HKEY_LOCAL_MACHINE, ″Software\CLASSES\Directory\shell\abcd″, hKey)    ′设置abcd的默认键值为strmenuname的值    lRet = RegSetValueEx(hKey, ″″, 0&, REG_SZ, ByVal strMenuName, Len(strMenuName) + 1)   ′在主键HKEY_LOCAL_MACHINE\Software\CLASSES\Directory\shell\abcd下创建主键command   lRet = RegCreateKey(HKEY_ LOCAL_MACHINE, ″Software\CLASSES\Directory\shell\abcd\command″, hKey)   ′设置command的默认键值为strRunCmd的值   lRet = RegSetValueEx(hKey, ″″, 0&, REG_SZ, ByVal strRunCmd, Len(strRunCmd) + 1)    ′关上主键 lRet = RegCloseKey(hKey)    MsgBox ″菜单项添加成功″, ,″提示″    Case 0    ′删除主键abcd lRet = RegDeleteKey(HKEY_LOCAL_ MACHINE, ″Software\CLASSES\Directory\shell\abcd″)    lRet = RegCloseKey(hKey)    MsgBox ″菜单项被撤消″, , ″提示″    End Select   End Sub    本程序在Win98+VB6.0中文企业版运行通过。