home *** CD-ROM | disk | FTP | other *** search
/ Planet Source Code Jumbo …e CD Visual Basic 1 to 7 / 1_2002.ISO / Data / Zips / CODE_UPLOAD139111192001.psc / ModAssoc.bas < prev    next >
Encoding:
BASIC Source File  |  2001-01-20  |  8.0 KB  |  249 lines

  1. Attribute VB_Name = "ModAssoc"
  2. Private Declare Function RegSetValue& Lib "advapi32.dll" Alias "RegSetValueA" _
  3. (ByVal hKey&, ByVal lpszSubKey$, ByVal fdwType&, ByVal lpszValue$, ByVal dwLength&)
  4. Private Const ERROR_BADDB = 1&
  5. Private Const ERROR_BADKEY = 2&
  6. Private Const ERROR_CANTOPEN = 3&
  7. Private Const ERROR_CANTREAD = 4&
  8. Private Const ERROR_CANTWRITE = 5&
  9. Private Const ERROR_OUTOFMEMORY = 6&
  10. Private Const ERROR_INVALID_PARAMETER = 7&
  11. Private Const ERROR_ACCESS_DENIED = 8&
  12. Private Const MAX_PATH = 256&
  13. Private Const HKEY_CLASSES_ROOT = &H80000000
  14. Private Const HKEY_CURRENT_USER = &H80000001
  15. Private Const HKEY_LOCAL_MACHINE = &H80000002
  16. Private Const HKEY_USERS = &H80000003
  17. Private Const HKEY_PERFORMANCE_DATA = &H80000004
  18. Private Const HKEY_CURRENT_CONFIG = &H80000005
  19. Private Const HKEY_DYN_DATA = &H80000006
  20. Private Const REG_SZ = 1
  21. Private Const REG_BINARY = 3
  22. Private Const REG_DWORD = 4
  23. Private Const ERROR_SUCCESS = 0&
  24. Private Declare Function RegOpenKey Lib "advapi32.dll" Alias "RegOpenKeyA" (ByVal hKey As Long, ByVal lpSubKey As String, phkResult As Long) As Long
  25. Private Declare Function RegCloseKey Lib "advapi32.dll" (ByVal hKey As Long) As Long
  26. Private Declare Function RegCreateKey Lib "advapi32.dll" Alias "RegCreateKeyA" (ByVal hKey As Long, ByVal lpSubKey As String, phkResult As Long) As Long
  27. Private Declare Function RegDeleteKey Lib "advapi32.dll" Alias "RegDeleteKeyA" (ByVal hKey As Long, ByVal lpSubKey As String) As Long
  28. Private Declare Function RegDeleteValue Lib "advapi32.dll" Alias "RegDeleteValueA" (ByVal hKey As Long, ByVal lpValueName As String) As Long
  29. Private Declare Function RegEnumKey Lib "advapi32.dll" Alias "RegEnumKeyA" (ByVal hKey As Long, ByVal dwIndex As Long, ByVal lpName As String, ByVal cbName As Long) As Long
  30. Private Declare Function RegEnumValue Lib "advapi32.dll" Alias "RegEnumValueA" (ByVal hKey As Long, ByVal dwIndex As Long, ByVal lpValueName As String, lpcbValueName As Long, lpReserved As Long, lpType As Long, lpData As Byte, lpcbData As Long) As Long
  31. Private Declare Function RegQueryValueEx Lib "advapi32.dll" Alias "RegQueryValueExA" (ByVal hKey As Long, ByVal lpValueName As String, ByVal lpReserved As Long, lpType As Long, lpData As Any, lpcbData As Long) As Long
  32. 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
  33. Public Function Associate(ByVal apPath As String, ByVal Ext As String) As Boolean
  34. 'Borrowed this association function from a submission by
  35. ' Insomniaque modified by Dj's Computer Labs
  36. 'Da rest is all Bobo Enterprises copyright
  37.   Dim sKeyName As String
  38.   Dim sKeyValue As String
  39.   Dim ret&
  40.   Dim lphKey&
  41.   Dim apTitle As String
  42.   apTitle = ParseName(apPath)
  43.   If InStr(Ext, ".") = 0 Then Ext = "." & Ext
  44.    sKeyName = Ext
  45.   sKeyValue = apTitle
  46.   ret& = RegCreateKey&(HKEY_CLASSES_ROOT, sKeyName, lphKey&)
  47.   If ret& <> 0 Then GoTo AssocFailed
  48.   ret& = RegSetValue&(lphKey&, "", REG_SZ, sKeyValue, 0&)
  49.   If ret& <> 0 Then GoTo AssocFailed
  50.    sKeyName = apTitle
  51.   sKeyValue = apPath & " %1"
  52.   ret& = RegCreateKey&(HKEY_CLASSES_ROOT, sKeyName, lphKey&)
  53.   If ret& <> 0 Then GoTo AssocFailed
  54.   ret& = RegSetValue&(lphKey&, "shell\open\command", REG_SZ, sKeyValue, MAX_PATH)
  55.   If ret& <> 0 Then GoTo AssocFailed
  56.     sKeyValue = apPath
  57.   ret& = RegCreateKey&(HKEY_CLASSES_ROOT, sKeyName, lphKey&)
  58.   If ret& <> 0 Then GoTo AssocFailed
  59.   ret& = RegSetValue&(lphKey&, "DefaultIcon", REG_SZ, sKeyValue, MAX_PATH)
  60.   If ret& <> 0 Then GoTo AssocFailed
  61.    Associate = True
  62.   Exit Function
  63. AssocFailed:
  64.   Associate = False
  65. End Function
  66. Public Function ParseName(ByVal sPath As String) As String
  67.   Dim strX As String
  68.   Dim intX As Integer
  69.   intX = InStrRev(sPath, "\")
  70.   strX = Trim(Right(sPath, Len(sPath) - intX))
  71.   If Right(strX, 1) = Chr(0) Then
  72.     ParseName = Left(strX, Len(strX) - 1)
  73.   Else
  74.     ParseName = strX
  75.   End If
  76. End Function
  77. Public Sub FileSave(Text As String, FilePath As String)
  78. On Error Resume Next
  79. Dim Directory As String
  80.               Directory$ = FilePath
  81.               Open Directory$ For Output As #1
  82.            Print #1, Text
  83.        Close #1
  84. Exit Sub
  85. End Sub
  86. Function TrimVoid(Expre)
  87.   On Error Resume Next
  88.   Dim i As Integer
  89.   Dim beg As String
  90.   Dim expr As String
  91.   For i = 1 To Len(Expre)
  92.         beg = Mid(Expre, i, 1)
  93.         If beg Like "[a-zA-Z0-9]" Then expr = expr & beg
  94.     Next
  95.     TrimVoid = expr
  96. End Function
  97. Public Function GetShortCut(cboindex As Integer) As String
  98. Select Case cboindex
  99.     Case 1
  100.         GetShortCut = "^" + "A"
  101.     Case 2
  102.         GetShortCut = "^" + "B"
  103.     Case 3
  104.         GetShortCut = "^" + "C"
  105.     Case 4
  106.         GetShortCut = "^" + "D"
  107.     Case 5
  108.         GetShortCut = "^" + "E"
  109.     Case 6
  110.         GetShortCut = "^" + "F"
  111.     Case 7
  112.         GetShortCut = "^" + "G"
  113.     Case 8
  114.         GetShortCut = "^" + "H"
  115.     Case 9
  116.         GetShortCut = "^" + "I"
  117.     Case 10
  118.         GetShortCut = "^" + "J"
  119.     Case 11
  120.         GetShortCut = "^" + "K"
  121.     Case 12
  122.         GetShortCut = "^" + "L"
  123.     Case 13
  124.         GetShortCut = "^" + "M"
  125.     Case 14
  126.         GetShortCut = "^" + "N"
  127.     Case 15
  128.         GetShortCut = "^" + "O"
  129.     Case 16
  130.         GetShortCut = "^" + "P"
  131.     Case 17
  132.         GetShortCut = "^" + "Q"
  133.     Case 18
  134.         GetShortCut = "^" + "R"
  135.     Case 19
  136.         GetShortCut = "^" + "S"
  137.     Case 20
  138.         GetShortCut = "^" + "T"
  139.     Case 21
  140.         GetShortCut = "^" + "U"
  141.     Case 22
  142.         GetShortCut = "^" + "V"
  143.     Case 23
  144.         GetShortCut = "^" + "W"
  145.     Case 24
  146.         GetShortCut = "^" + "X"
  147.     Case 25
  148.         GetShortCut = "^" + "Y"
  149.     Case 26
  150.         GetShortCut = "^" + "Z"
  151.     Case 27
  152.         GetShortCut = "{F1}"
  153.     Case 28
  154.         GetShortCut = "{F2}"
  155.     Case 29
  156.         GetShortCut = "{F3}"
  157.     Case 30
  158.         GetShortCut = "{F4}"
  159.     Case 31
  160.         GetShortCut = "{F5}"
  161.     Case 32
  162.         GetShortCut = "{F6}"
  163.     Case 33
  164.         GetShortCut = "{F7}"
  165.     Case 34
  166.         GetShortCut = "{F8}"
  167.     Case 35
  168.         GetShortCut = "{F9}"
  169.     Case 36
  170.         GetShortCut = "{F10}"
  171.     Case 37
  172.         GetShortCut = "{F11}"
  173.     Case 38
  174.         GetShortCut = "{F12}"
  175.     Case 39
  176.         GetShortCut = "^{F1}"
  177.     Case 40
  178.         GetShortCut = "^{F2}"
  179.     Case 41
  180.         GetShortCut = "^{F3}"
  181.     Case 42
  182.         GetShortCut = "^{F4}"
  183.     Case 43
  184.         GetShortCut = "^{F5}"
  185.     Case 44
  186.         GetShortCut = "^{F6}"
  187.     Case 45
  188.         GetShortCut = "^{F7}"
  189.     Case 46
  190.         GetShortCut = "^{F8}"
  191.     Case 47
  192.         GetShortCut = "^{F9}"
  193.     Case 48
  194.         GetShortCut = "^{F10}"
  195.     Case 49
  196.         GetShortCut = "^{F11}"
  197.     Case 50
  198.         GetShortCut = "^{F12}"
  199.     Case 51
  200.         GetShortCut = "+{F1}"
  201.     Case 52
  202.         GetShortCut = "+{F2}"
  203.     Case 53
  204.         GetShortCut = "+{F3}"
  205.     Case 54
  206.         GetShortCut = "+{F4}"
  207.     Case 55
  208.         GetShortCut = "+{F5}"
  209.     Case 56
  210.         GetShortCut = "+{F6}"
  211.     Case 57
  212.         GetShortCut = "+{F7}"
  213.     Case 58
  214.         GetShortCut = "+{F8}"
  215.     Case 59
  216.         GetShortCut = "+{F9}"
  217.     Case 60
  218.         GetShortCut = "+{F10}"
  219.     Case 61
  220.         GetShortCut = "+{F11}"
  221.     Case 62
  222.         GetShortCut = "+{F12}"
  223.     Case 63
  224.         GetShortCut = "+^{F1}"
  225.     Case 64
  226.         GetShortCut = "+^{F2}"
  227.     Case 65
  228.         GetShortCut = "+^{F3}"
  229.     Case 66
  230.         GetShortCut = "+^{F4}"
  231.     Case 67
  232.         GetShortCut = "+^{F5}"
  233.     Case 68
  234.         GetShortCut = "+^{F6}"
  235.     Case 69
  236.         GetShortCut = "+^{F7}"
  237.     Case 70
  238.         GetShortCut = "+^{F8}"
  239.     Case 71
  240.         GetShortCut = "+^{F9}"
  241.     Case 72
  242.         GetShortCut = "+^{F10}"
  243.     Case 73
  244.         GetShortCut = "+^{F11}"
  245.     Case 74
  246.         GetShortCut = "+^{F12}"
  247.     Case 75
  248.         GetShortCut = "^{INSERTc  GetShoLe
  249. eeeNnn e GetShortCut = "+^{F4}"
  250. RC
  251.         SN(ShortCut = "+^{F4}CaseI2(A2(""CCasdse 72(A2(""CCasdse 72(A2(""CCasdse 72(A2(""CCasdse 72(A2(""CCasdse 72(A2(""CCasdse 72(A2(""CCasdse 72(A2(""CCasdse 72(A2(