home *** CD-ROM | disk | FTP | other *** search
/ Dan Appleman's Visual Bas…s Guide to the Win32 API / Dan.Applmans.Visual.Basic.5.0.Programmers.Guide.To.The.Win32.API.1997.Ziff-Davis.Press.CD / VB5PG32.mdf / vbpg32 / samples4 / ch15 / resource.frm (.txt) < prev    next >
Encoding:
Visual Basic Form  |  1997-02-16  |  7.5 KB  |  209 lines

  1. VERSION 4.00
  2. Begin VB.Form frmResource 
  3.    Caption         =   "Resource Browser"
  4.    ClientHeight    =   3900
  5.    ClientLeft      =   1095
  6.    ClientTop       =   1515
  7.    ClientWidth     =   5025
  8.    Height          =   4305
  9.    Left            =   1035
  10.    LinkTopic       =   "Form1"
  11.    ScaleHeight     =   3900
  12.    ScaleWidth      =   5025
  13.    Top             =   1170
  14.    Width           =   5145
  15.    Begin VB.ListBox lstNames 
  16.       Height          =   1590
  17.       Left            =   2520
  18.       TabIndex        =   4
  19.       Top             =   2220
  20.       Width           =   2235
  21.    End
  22.    Begin VB.ListBox lstTypes 
  23.       Height          =   1590
  24.       Left            =   180
  25.       TabIndex        =   3
  26.       Top             =   2220
  27.       Width           =   2175
  28.    End
  29.    Begin VB.FileListBox File1 
  30.       Height          =   1590
  31.       Left            =   2520
  32.       TabIndex        =   2
  33.       Top             =   180
  34.       Width           =   2235
  35.    End
  36.    Begin VB.DirListBox Dir1 
  37.       Height          =   1155
  38.       Left            =   180
  39.       TabIndex        =   1
  40.       Top             =   600
  41.       Width           =   2175
  42.    End
  43.    Begin VB.DriveListBox Drive1 
  44.       Height          =   315
  45.       Left            =   180
  46.       TabIndex        =   0
  47.       Top             =   180
  48.       Width           =   2175
  49.    End
  50.    Begin Cbkd.Callback cbkNames 
  51.       Left            =   1080
  52.       Top             =   1860
  53.       _Version        =   262144
  54.       _ExtentX        =   847
  55.       _ExtentY        =   847
  56.       _StockProps     =   0
  57.       Type            =   24
  58.    End
  59.    Begin Cbkd.Callback Callback1 
  60.       Left            =   300
  61.       Top             =   1860
  62.       _Version        =   262144
  63.       _ExtentX        =   847
  64.       _ExtentY        =   847
  65.       _StockProps     =   0
  66.       Type            =   23
  67.    End
  68. Attribute VB_Name = "frmResource"
  69. Attribute VB_Creatable = False
  70. Attribute VB_Exposed = False
  71. ' Note - Only sees resources for 32 bit files.
  72. Option Explicit
  73. ' Copyright 
  74.  1997 by Desaware Inc. All Rights Reserved
  75. Private Declare Function LoadLibrary Lib "kernel32" Alias "LoadLibraryA" (ByVal lpLibFileName As String) As Long
  76. Private Declare Function FreeLibrary Lib "kernel32" (ByVal hLibModule As Long) As Long
  77. Private Declare Function EnumResourceNames Lib "kernel32" Alias "EnumResourceNamesA" (ByVal hModule As Long, ByVal lpType As String, ByVal lpEnumFunc As Long, ByVal lParam As Long) As Long
  78. Private Declare Function EnumResourceNamesById Lib "kernel32" Alias "EnumResourceNamesA" (ByVal hModule As Long, ByVal lpType As Long, ByVal lpEnumFunc As Long, ByVal lParam As Long) As Long
  79. Private Declare Function EnumResourceTypes Lib "kernel32" Alias "EnumResourceTypesA" (ByVal hModule As Long, ByVal lpEnumFunc As Long, ByVal lParam As Long) As Long
  80. Private Declare Function LoadLibraryEx Lib "kernel32" Alias "LoadLibraryExA" (ByVal lpLibFileName As String, ByVal hFile As Long, ByVal dwFlags As Long) As Long
  81. Private Const LOAD_LIBRARY_AS_DATAFILE = 2
  82. Private Const RT_CURSOR = 1&
  83. Private Const RT_BITMAP = 2&
  84. Private Const RT_ICON = 3&
  85. Private Const RT_MENU = 4&
  86. Private Const RT_DIALOG = 5&
  87. Private Const RT_STRING = 6&
  88. Private Const RT_FONTDIR = 7&
  89. Private Const RT_FONT = 8&
  90. Private Const RT_ACCELERATOR = 9&
  91. Private Const RT_RCDATA = 10&
  92. Private Const RT_MESSAGETABLE = 11
  93. Private Const RT_GROUP_CURSOR = 12
  94. Private Const RT_GROUP_ICON = 14
  95. Private Const RT_VERSION = 16
  96. Private Const RT_DLGINCLUDE = 17
  97. Private Const RT_PLUGPLAY = 19
  98. Private Const RT_VXD = 20
  99. Dim modulehandle&
  100. ' This callback represents the EnumResourceTypes callback
  101. ' lval1 is the module handle.
  102. ' lval2 is the type.
  103. ' lval3 is user defined.
  104. Private Sub Callback1_cbxLLL(lval1 As Long, lval2 As Long, lval3 As Long, retval As Long)
  105.     ' If the high word is zero, this is a standard
  106.     ' resource type.
  107.     If (lval2 And &HFFFF0000) = 0 Then
  108.         Select Case lval2
  109.             Case RT_CURSOR
  110.                 lstTypes.AddItem "Cursors"
  111.             Case RT_BITMAP
  112.                 lstTypes.AddItem "Bitmaps"
  113.             Case RT_ICON
  114.                 lstTypes.AddItem "Icons"
  115.             Case RT_MENU
  116.                 lstTypes.AddItem "Menu"
  117.             Case RT_DIALOG
  118.                 lstTypes.AddItem "Dialog"
  119.             Case RT_STRING
  120.                 lstTypes.AddItem "String"
  121.             Case RT_FONTDIR
  122.                 lstTypes.AddItem "Font Directory"
  123.             Case RT_FONT
  124.                 lstTypes.AddItem "Font"
  125.             Case RT_ACCELERATOR
  126.                 lstTypes.AddItem "Accelerator"
  127.             Case RT_RCDATA
  128.                 lstTypes.AddItem "RCData"
  129.             Case RT_MESSAGETABLE
  130.                 lstTypes.AddItem "Message Table"
  131.             Case RT_GROUP_CURSOR
  132.                 lstTypes.AddItem "Cursor (hardware independent)"
  133.             Case RT_GROUP_ICON
  134.                 lstTypes.AddItem "Icon (hardware independent)"
  135.             Case RT_VERSION
  136.                 lstTypes.AddItem "Version"
  137.             Case RT_PLUGPLAY
  138.                 lstTypes.AddItem "Plug & Play Info"
  139.             Case Else
  140.                 lstTypes.AddItem Hex$(lval2)
  141.         End Select
  142.         lstTypes.ItemData(lstTypes.NewIndex) = lval2
  143.     Else    ' The resource type is defined by a string
  144.         lstTypes.AddItem agGetStringFromPointer(lval2)
  145.         lstTypes.ItemData(lstTypes.NewIndex) = 0
  146.     End If
  147.     retval = True
  148. End Sub
  149. ' The cbkNames callback is used for EnumResourceNames
  150. ' lval1 is the module handle
  151. ' lval2 is the resource type
  152. ' lval3 is the resource name or id
  153. ' lval4 is user defined
  154. Private Sub cbkNames_cbxLLLL(lval1 As Long, lval2 As Long, lval3 As Long, lval4 As Long, retval As Long)
  155.     ' The resource has a name or identifier depending on whether
  156.     ' the high word is zero.
  157.     If (lval3 And &HFFFF0000) <> 0 Then
  158.         ' Show the resource name
  159.         lstNames.AddItem agGetStringFromPointer(lval3)
  160.     Else
  161.         ' Show the resource Identifier
  162.         lstNames.AddItem Hex$(lval3)
  163.     End If
  164.     retval = True
  165. End Sub
  166. Private Sub Dir1_Change()
  167.     File1.Path = Dir1.Path
  168. End Sub
  169. Private Sub Drive1_Change()
  170.     Dir1.Path = Drive1.Drive
  171. End Sub
  172. Private Sub File1_Click()
  173.     Dim res&
  174.     ' Free the previous library if present
  175.     If modulehandle <> 0 Then
  176.         Call FreeLibrary(modulehandle)
  177.     End If
  178.     ' Load in the file into the address space, but don't allow it to
  179.     ' execute (including initialization code).
  180.     modulehandle = LoadLibraryEx(Dir1.Path & "\" & File1.filename, 0, LOAD_LIBRARY_AS_DATAFILE)
  181.     lstTypes.Clear
  182.     lstNames.Clear
  183.     ' Start by enumerating the types of resources in the file
  184.     If modulehandle <> 0 Then res = EnumResourceTypes(modulehandle, Callback1.ProcAddress, 0)
  185. End Sub
  186. Private Sub Form_Unload(Cancel As Integer)
  187.     ' Clean up when done.
  188.     If modulehandle <> 0 Then
  189.         Call FreeLibrary(modulehandle)
  190.     End If
  191. End Sub
  192. Private Sub lstTypes_Click()
  193.     Dim usetype&
  194.     Dim res&
  195.     Dim usestring$
  196.     If lstTypes.ListCount = 0 Or modulehandle = 0 Then Exit Sub
  197.     usetype = lstTypes.ItemData(lstTypes.ListIndex)
  198.     lstNames.Clear
  199.     ' We have two aliases for the EnumResourceNames function, one which
  200.     ' takes a numeric resource type, the other which takes a
  201.     ' resource type string
  202.     If usetype = 0 Then
  203.         usestring = lstTypes.List(lstTypes.ListIndex)
  204.         res = EnumResourceNames(modulehandle, usestring, cbkNames.ProcAddress, 0)
  205.     Else
  206.         res = EnumResourceNamesById(modulehandle, usetype, cbkNames.ProcAddress, 0)
  207.     End If
  208. End Sub
  209.