form1.frm

来自「100个vb编程实例,什么都有」· FRM 代码 · 共 57 行

FRM
57
字号
VERSION 5.00
Begin VB.Form Form1 
   Caption         =   "Form1"
   ClientHeight    =   3195
   ClientLeft      =   60
   ClientTop       =   345
   ClientWidth     =   4680
   LinkTopic       =   "Form1"
   ScaleHeight     =   3195
   ScaleWidth      =   4680
   StartUpPosition =   3  '窗口缺省
   Begin VB.CommandButton Command1 
      Caption         =   "设置"
      Height          =   375
      Left            =   1680
      TabIndex        =   0
      Top             =   1680
      Width           =   1335
   End
   Begin VB.Label Label1 
      Caption         =   $"Form1.frx":0000
      Height          =   855
      Left            =   840
      TabIndex        =   1
      Top             =   360
      Width           =   2775
   End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
'---------------处理注册表的函数-----------------------
Const HKEY_CURRENT_USER = &H80000001
Const REG_SZ = 1
Private Declare Function RegSetValue Lib "advapi32.dll" Alias "RegSetValueA" (ByVal hKey As Long, ByVal lpSubKey As String, ByVal dwType As Long, ByVal lpData As String, ByVal cbData As Long) As Long
Private Declare Function RegCreateKey& Lib "advapi32.dll" Alias "RegCreateKeyA" (ByVal hKey&, ByVal lpszSubKey$, lphKey&)

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 Sub Command1_Click()
 Dim hKey As Long, SubKey As String, Exe As String

    SubKey = "Software\Microsoft\Windows\CurrentVersion\Run"
    Exe = "notepad"
    RegCreateKey HKEY_CURRENT_USER, SubKey, hKey
    
    RegSetValueEx hKey, "记事本", 0, REG_SZ, ByVal Exe, _
                  LenB(StrConv(Exe, vbFromUnicode)) + 1
    RegCloseKey hKey
    
    MsgBox "notepad 程序已经被设定成 Windows 启动时自动被执行的程序!"

End Sub

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?