📄 form1.frm
字号:
VERSION 5.00
Begin VB.Form Form1
Caption = "Form1"
ClientHeight = 750
ClientLeft = 60
ClientTop = 345
ClientWidth = 7860
LinkTopic = "Form1"
ScaleHeight = 750
ScaleWidth = 7860
StartUpPosition = 3 '窗口缺省
Begin VB.CommandButton Command1
Caption = "设置收藏夹路径"
Height = 375
Left = 5520
TabIndex = 2
Top = 240
Width = 1575
End
Begin VB.TextBox Text1
Height = 375
Left = 1680
TabIndex = 0
Top = 240
Width = 3015
End
Begin VB.Label Label1
Caption = "收藏夹路径"
Height = 375
Left = 240
TabIndex = 1
Top = 240
Width = 1575
End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit
Public Enum REG_TOPLEVEL_KEYS
HKEY_CLASSES_ROOT = &H80000000
HKEY_CURRENT_CONFIG = &H80000005
HKEY_CURRENT_USER = &H80000001
HKEY_DYN_DATA = &H80000006
HKEY_LOCAL_MACHINE = &H80000002
HKEY_PERFORMANCE_DATA = &H80000004
HKEY_USERS = &H80000003
End Enum
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 RegCloseKey Lib _
"advapi32.dll" (ByVal Hkey 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 Const REG_SZ = 1
Private Function WriteStringToRegistry(Hkey As _
REG_TOPLEVEL_KEYS, strPath As String, strValue As String, _
strdata As String) As Boolean
Dim bAns As Boolean
On Error GoTo ErrorHandler
Dim keyhand As Long
Dim r As Long
r = RegCreateKey(Hkey, strPath, keyhand)
If r = 0 Then
r = RegSetValueEx(keyhand, strValue, 0, _
REG_SZ, ByVal strdata, Len(strdata))
r = RegCloseKey(keyhand)
End If
WriteStringToRegistry = (r = 0)
Exit Function
ErrorHandler:
WriteStringToRegistry = False
Exit Function
End Function
Private Sub Command1_Click()
If Text1.Text <> "" Then
If WriteStringToRegistry(HKEY_CURRENT_USER, _
"Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders", _
"Favorites", Text1.Text) Then
MsgBox "设置收藏夹成功"
Else
MsgBox "设置收藏夹失败"
End If
Else
MsgBox "收藏夹路径不能为空,请输入收藏夹路径!", vbOKOnly + vbInformation, "提示"
End If
End Sub
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -