⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 regdemo.frm

📁 一款漂亮的控件。 快
💻 FRM
字号:
VERSION 5.00
Begin VB.Form frmMain 
   Caption         =   "建立关联文件"
   ClientHeight    =   1380
   ClientLeft      =   60
   ClientTop       =   345
   ClientWidth     =   4365
   LinkTopic       =   "Form1"
   LockControls    =   -1  'True
   ScaleHeight     =   1380
   ScaleWidth      =   4365
   StartUpPosition =   2  '屏幕中心
   Begin VB.CommandButton Command1 
      Caption         =   "添加关联"
      Height          =   495
      Left            =   1260
      TabIndex        =   0
      Top             =   680
      Width           =   1995
   End
   Begin VB.Label Label1 
      Caption         =   "将扩展名为.lzd的文件与记事本程序关联"
      Height          =   375
      Left            =   800
      TabIndex        =   1
      Top             =   120
      Width           =   2600
   End
End
Attribute VB_Name = "frmMain"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
'推荐使用第三种方法!
'
'文件关连应在安装程序中完成!

Option Explicit

Const HKEY_CLASSES_ROOT = &H80000000
Private Declare Function OSRegCreateKey Lib "Advapi32" Alias "RegCreateKeyA" (ByVal hKey As Long, ByVal lpszSubKey As String, phkResult As Long) As Long
Const ERROR_SUCCESS = 0&
Const REG_SZ = 1
Private Declare Function OSRegSetValueEx Lib "Advapi32" Alias "RegSetValueExA" (ByVal hKey As Long, ByVal lpszValueName As String, ByVal dwReserved As Long, ByVal fdwType As Long, lpbData As Any, ByVal cbData As Long) As Long

Const SW_SHOW = 5
Private Declare Function ShellExecute Lib "Shell32.dll" Alias "ShellExecuteA" (ByVal hwnd As Long, ByVal lpOperation As String, ByVal lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long
          
Private Sub Command1_Click()
'第一种方法。

' Dim ret As Long
 'ret = ShellExecute(Me.hwnd, "open", "c:\wsv.reg", "", "", SW_SHOW)
 
'第二种方法。
 'Shell "RegEdit c:\wsv.reg"
 
'第三种方法。
    Dim ret1 As Long, hKey As Long, hkey1 As Long, strdata As String
    strdata = "WinLZDFile"
    ret1 = OSRegCreateKey(HKEY_CLASSES_ROOT, ".lzd", hKey)
    ret1 = OSRegSetValueEx(hKey, "", 0&, REG_SZ, ByVal strdata, LenB(StrConv(strdata, vbFromUnicode)) + 1)
    
    ret1 = OSRegCreateKey(HKEY_CLASSES_ROOT, "WinLZDFile", hKey)
    strdata = "WinLZD 文件"
    ret1 = OSRegSetValueEx(hKey, "", 0&, REG_SZ, ByVal strdata, LenB(StrConv(strdata, vbFromUnicode)) + 1)
    ret1 = OSRegCreateKey(hKey, "DefaultIcon", hkey1)
    strdata = "Notepad.exe, 0" '应根据具体情况更改路径
    ret1 = OSRegSetValueEx(hkey1, "", 0&, REG_SZ, ByVal strdata, LenB(StrConv(strdata, vbFromUnicode)) + 1)
    ret1 = OSRegCreateKey(hKey, "shell", hKey)
    ret1 = OSRegCreateKey(hKey, "open", hKey)
    ret1 = OSRegCreateKey(hKey, "command", hkey1)
    strdata = "Notepad.exe " & Chr(34) & "%1" & Chr(34)
    ret1 = OSRegSetValueEx(hkey1, "", 0&, REG_SZ, ByVal strdata, LenB(StrConv(strdata, vbFromUnicode)) + 1)
    Debug.Print hKey
End Sub

⌨️ 快捷键说明

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