Retrieving the resource


ResProcName finally uses the Form variable, which has been passed down from UpdateResources to EnumResourceTypes to ResTypeProc to EnumResource­Names to ResNameProc. First it looks at the check box and, if appropriate, vali­dates the resource by giving it a trial run. I’m not going to show you the trial run because we’re almost ready for the real thing, which is a lot more interesting.


If the resource passes the test, ResNameProc stores it in the list box. Numbered resources come out like this:

00002   String

Named resources come out like this:

CLOCK   Menu

When the user clicks an item in the Resources list box, you have to parse the item text for the resource name and type, and then pass them to a procedure that can display the resource as shown on the next page.

Private Sub lstResource_Click()
Dim sType As String, sName As String, i As Integer

sType = lstResource.Text
BugAssert sType <> sEmpty
‘ Extract resource ID and type
If Left$(sType, 1) = “0” Then
‘ Append # so Windows will recognize numbers as strings
sName = “#” & Left$(sType, 5)
sType = Trim$(Mid$(sType, 7))
Else
i = InStr(sType, “ “)
sName = Trim$(Left$(sType, i - 1))
sType = Trim$(Mid$(sType, i + 1))
End If

‘ Clear last resource and handle new one
ClearResource
pbResource.AutoRedraw = False
If UCase$(sType) <> “BITMAP” Then
BmpTile pbResource, imgCloud.Picture
End If

Select Case UCase$(sType)
Case “CURSOR”
ShowCursor hModCur, sName
Case “GROUP_CURSOR”, “GROUP CURSOR”
ShowCursors hModCur, sName
Case “BITMAP”
ShowBitmap hModCur, sName
Case “ICON”
ShowIcon hModCur, sName
Case “GROUP_ICON”, “GROUP ICON”
ShowIcons hModCur, sName
Case “MENU”
ShowMenu hModCur, sName
Case “STRING”, “STRINGTABLE”
ShowString hModCur, sName
Case “WAVE”
PlayWave hModCur, sName
Case “AVI”
PlayAvi hModCur, sName
Case “FONTDIR”, “FONT”, “DIALOG”, “ACCELERATOR”
pbResource.Print sType & “ selected”
Case “VERSION”
pbResource.Print GetVersionData(sModCur, 26)
Case Else
ShowData hModCur, sName, sType
End Select
pbResource.AutoRedraw = True
End Sub

The first part of this code strips out the type and name, taking advantage of a Windows shortcut that lets you pass numeric ID numbers as strings by pre­pending the “#” character. This is easier than passing numbers in some cases and strings in others, and the performance cost in WinWatch is negligible.


The second part of the procedure brings us, at last, to the main point of this chapter: what you can do with those resources once you find them.