<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content="VB6Parse Library Reference - loadrespicture - Resources">
<title>loadrespicture - Resources - VB6Parse Library Reference</title>
<link rel="stylesheet" href="../../../assets/css/style.css">
<link rel="stylesheet" href="../../../assets/css/docs-style.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.9.0/styles/github-dark.min.css">
<script src="../../../assets/js/theme-switcher.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.9.0/highlight.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.9.0/languages/vbnet.min.js"></script>
<script>hljs.highlightAll();</script>
</head>
<body>
<header class="docs-header">
<div class="container">
<h1><a href="../../../index.html">VB6Parse</a> / <a href="../../../library/index.html">Library</a> / <a href="../../../library/functions/resources/index.html">Resources</a> / loadrespicture</h1>
<p class="tagline">VB6 Library Reference</p>
</div>
</header>
<nav class="docs-nav">
<div class="container">
<a href="../../../index.html">Home</a>
<a href="../../../library/index.html">Library Reference</a>
<a href="../../../documentation.html">Documentation</a>
<a href="https://docs.rs/vb6parse" target="_blank">API Docs</a>
<a href="https://github.com/scriptandcompile/vb6parse" target="_blank">GitHub</a>
<button id="theme-toggle" class="theme-toggle" aria-label="Toggle theme">
<span class="theme-icon">🌙</span>
</button>
</div>
</nav>
<main class="container">
<article class="library-item">
<h1 id="loadrespicture-function">LoadResPicture Function</h1>
<p>Returns a picture object (<code>StdPicture</code>) containing an image from a resource (.res) file.</p>
<h2 id="syntax">Syntax</h2>
<pre><code class="language-vbnet">LoadResPicture(index, format)</code></pre>
<h2 id="parameters">Parameters</h2>
<ul>
<li><code>index</code> (Required): Integer or String identifying the picture resource</li>
<li>Can be a numeric ID or string name</li>
<li>Must match the ID/name used when the resource was compiled</li>
<li><code>format</code> (Required): Integer specifying the format of the picture</li>
<li><code>vbResBitmap</code> (0): Bitmap (.bmp)</li>
<li><code>vbResIcon</code> (1): Icon (.ico)</li>
<li><code>vbResCursor</code> (2): Cursor (.cur)</li>
</ul>
<h2 id="return-value">Return Value</h2>
<p>Returns a <code>StdPicture</code> object:
- Picture object containing the loaded image from resources
- Object can be assigned to Picture properties of controls
- Object implements <code>IPicture</code> interface
- Returns Nothing if resource not found (some VB versions)
- May raise error 32813 if resource not found</p>
<h2 id="remarks">Remarks</h2>
<p>The <code>LoadResPicture</code> function loads images from embedded resources:
- Loads images from compiled resource (.res) files
- Resource file must be linked to project at compile time
- Supports BMP, ICO, and CUR formats only
- Does NOT support JPG, GIF, or PNG
- Returns <code>StdPicture</code> object implementing <code>IPicture</code>
- Alternative to <code>LoadPicture</code> for embedded images
- No external files needed at runtime
- Faster than loading from disk
- More secure (can't be modified by users)
- Resources embedded in compiled EXE/DLL
- Only one resource file per project
- Resource file added via Project > Add File
- Resource files created with Resource Editor or RC.EXE
- Index can be numeric ID or string name
- Format constants: vbResBitmap, vbResIcon, vbResCursor
- Error 32813: "Resource not found" if ID/format don't match
- Error 48: "Error loading from file" if resource file corrupt
- Pictures are not cached (loaded each time)
- Set object = Nothing to release memory
- Common in <code>Form_Load</code> for initial graphics
- Used with Image, <code>PictureBox</code>, and Form.Picture
- Preferred for distribution (no external image files)</p>
<h2 id="typical-uses">Typical Uses</h2>
<ol>
<li><strong>Load Bitmap to <code>PictureBox</code></strong></li>
</ol>
<pre><code class="language-vbnet"> Picture1.Picture = LoadResPicture(101, vbResBitmap)
```
2. **Load Icon to Image Control**
```vb
Image1.Picture = LoadResPicture(102, vbResIcon)
```
3. **Load Form Background**
```vb
Me.Picture = LoadResPicture("BACKGROUND", vbResBitmap)
```
4. **Load Cursor**
```vb
Me.MousePointer = vbCustom
Me.MouseIcon = LoadResPicture(103, vbResCursor)
```
5. **Load Named Resource**
```vb
imgLogo.Picture = LoadResPicture("LOGO", vbResBitmap)
```
6. **Conditional Image Loading**
```vb
If mode = "dark" Then
Picture1.Picture = LoadResPicture(201, vbResBitmap)
Else
Picture1.Picture = LoadResPicture(101, vbResBitmap)
End If
```
7. **Button Icons**
```vb
cmdSave.Picture = LoadResPicture(104, vbResIcon)
```
8. **Multiple Images in Loop**
```vb
For i = 1 To 5
imgArray(i).Picture = LoadResPicture(100 + i, vbResBitmap)
Next i
```
## Basic Examples
### Example 1: Basic Picture Loading</code></pre>
<p>vb
' Load bitmap from resources
Picture1.Picture = LoadResPicture(101, vbResBitmap)
' Load icon
Image1.Picture = LoadResPicture(102, vbResIcon)
' Load using string name
Picture2.Picture = LoadResPicture("SPLASH", vbResBitmap)</p>
<pre><code>### Example 2: Form Initialization</code></pre>
<p>vb
Private Sub Form_Load()
' Load form background
Me.Picture = LoadResPicture(101, vbResBitmap)
' Load toolbar icons
cmdNew.Picture = LoadResPicture(201, vbResIcon)
cmdOpen.Picture = LoadResPicture(202, vbResIcon)
cmdSave.Picture = LoadResPicture(203, vbResIcon)
End Sub</p>
<pre><code>### Example 3: Error Handling</code></pre>
<p>vb
On Error Resume Next
Picture1.Picture = LoadResPicture(999, vbResBitmap)
If Err.Number = 32813 Then
MsgBox "Resource not found!", vbCritical
Err.Clear
ElseIf Err.Number <> 0 Then
MsgBox "Error loading resource: " & Err.Description, vbCritical
Err.Clear
End If</p>
<pre><code>### Example 4: Dynamic Loading</code></pre>
<p>vb
Dim imageID As Integer
imageID = 101 + selectedIndex
Picture1.Picture = LoadResPicture(imageID, vbResBitmap)</p>
<pre><code>## Common Patterns
### Pattern 1: `SafeLoadResPicture`</code></pre>
<p>vb
Function SafeLoadResPicture(ByVal resID As Variant, _
ByVal resFormat As Integer, _
ByVal ctrl As Object) As Boolean
On Error Resume Next
Set ctrl.Picture = LoadResPicture(resID, resFormat)
SafeLoadResPicture = (Err.Number = 0)
Err.Clear
End Function</p>
<pre><code>### Pattern 2: `PreloadResourcePictures`</code></pre>
<p>vb
Dim preloadedPics() As StdPicture
Sub PreloadResourcePictures()
Dim i As Long
ReDim preloadedPics(1 To 5)
For i = 1 To 5
Set preloadedPics(i) = LoadResPicture(100 + i, vbResBitmap)
Next i
End Sub
Sub ShowPreloadedImage(ByVal index As Long)
If index >= 1 And index <= UBound(preloadedPics) Then
Set Picture1.Picture = preloadedPics(index)
End If
End Sub</p>
<pre><code>### Pattern 3: `LoadResPictureWithDefault`</code></pre>
<p>vb
Function LoadResPictureWithDefault(ByVal resID As Variant, _
ByVal resFormat As Integer, _
ByVal defaultID As Variant) As StdPicture
On Error Resume Next
Set LoadResPictureWithDefault = LoadResPicture(resID, resFormat)
If Err.Number <> 0 Then
Err.Clear
Set LoadResPictureWithDefault = LoadResPicture(defaultID, resFormat)
End If
End Function</p>
<pre><code>### Pattern 4: `LoadResByName`</code></pre>
<p>vb
Function LoadResByName(ByVal resName As String, _
ByVal resFormat As Integer) As StdPicture
On Error Resume Next
Set LoadResByName = LoadResPicture(resName, resFormat)
If Err.Number <> 0 Then
Debug.Print "Failed to load resource: " & resName
Set LoadResByName = Nothing
Err.Clear
End If
End Function</p>
<pre><code>### Pattern 5: `ToggleResPicture`</code></pre>
<p>vb
Dim currentState As Boolean
Sub ToggleResPicture()
If currentState Then
Picture1.Picture = LoadResPicture(101, vbResBitmap)
Else
Picture1.Picture = LoadResPicture(102, vbResBitmap)
End If
currentState = Not currentState
End Sub</p>
<pre><code>### Pattern 6: `LoadThemeResources`</code></pre>
<p>vb
Enum ThemeType
tmLight = 0
tmDark = 1
End Enum
Sub LoadThemeResources(theme As ThemeType)
Dim baseID As Integer
baseID = IIf(theme = tmDark, 200, 100)
Me.Picture = LoadResPicture(baseID + 1, vbResBitmap)
Picture1.Picture = LoadResPicture(baseID + 2, vbResBitmap)
Picture2.Picture = LoadResPicture(baseID + 3, vbResBitmap)
End Sub</p>
<pre><code>### Pattern 7: `ResExists`</code></pre>
<p>vb
Function ResExists(ByVal resID As Variant, _
ByVal resFormat As Integer) As Boolean
On Error Resume Next
Dim pic As StdPicture
Set pic = LoadResPicture(resID, resFormat)
ResExists = (Err.Number = 0)
Set pic = Nothing
Err.Clear
End Function</p>
<pre><code>### Pattern 8: `LoadAllResourceIcons`</code></pre>
<p>vb
Function LoadAllResourceIcons(startID As Integer, _
endID As Integer) As Collection
Dim col As New Collection
Dim i As Integer
Dim pic As StdPicture
On Error Resume Next
For i = startID To endID
Set pic = LoadResPicture(i, vbResIcon)
If Err.Number = 0 Then
col.Add pic
End If
Err.Clear
Next i
Set LoadAllResourceIcons = col
End Function</p>
<pre><code>### Pattern 9: `SetButtonIcon`</code></pre>
<p>vb
Sub SetButtonIcon(btn As CommandButton, _
ByVal iconID As Integer, _
ByVal enabled As Boolean)
On Error Resume Next
If enabled Then
Set btn.Picture = LoadResPicture(iconID, vbResIcon)
Else
Set btn.Picture = LoadResPicture(iconID + 100, vbResIcon)
End If
btn.enabled = enabled
End Sub</p>
<pre><code>### Pattern 10: `LoadResourceArray`</code></pre>
<p>vb
Sub LoadResourceArray(ByRef picArray() As StdPicture, _
ByVal startID As Integer, _
ByVal count As Integer, _
ByVal resFormat As Integer)
Dim i As Integer
ReDim picArray(1 To count)
On Error Resume Next
For i = 1 To count
Set picArray(i) = LoadResPicture(startID + i - 1, resFormat)
If Err.Number <> 0 Then
Debug.Print "Failed to load resource: " & (startID + i - 1)
Err.Clear
End If
Next i
End Sub</p>
<pre><code>## Advanced Examples
### Example 1: Resource Picture Manager</code></pre>
<p>vb
' Class: ResPictureManager
Private m_cache As Collection
Private Sub Class_Initialize()
Set m_cache = New Collection
End Sub
Public Function LoadPicture(ByVal resID As Variant, _
ByVal resFormat As Integer) As StdPicture
Dim key As String
On Error Resume Next
key = CStr(resID) & "_" & CStr(resFormat)
Set LoadPicture = m_cache(key)
If Err.Number <> 0 Then
Err.Clear
Set LoadPicture = LoadResPicture(resID, resFormat)
If Err.Number = 0 Then
m_cache.Add LoadPicture, key
Else
Err.Raise vbObjectError + 1000, "ResPictureManager", _
"Failed to load resource"
End If
End If
End Function
Public Sub AssignToControl(ByVal ctrl As Object, _
ByVal resID As Variant, _
ByVal resFormat As Integer)
Set ctrl.Picture = LoadPicture(resID, resFormat)
End Sub
Public Sub ClearCache()
Dim i As Long
For i = m_cache.Count To 1 Step -1
m_cache.Remove i
Next i
End Sub
Public Property Get CacheSize() As Long
CacheSize = m_cache.Count
End Property
Private Sub Class_Terminate()
ClearCache
Set m_cache = Nothing
End Sub</p>
<pre><code>### Example 2: Image Gallery from Resources</code></pre>
<p>vb
' Form with Picture1, Timer1, cmdNext, cmdPrev, lblInfo
Private Const BASE_IMAGE_ID = 1001
Private Const IMAGE_COUNT = 10
Private currentIndex As Long
Private Sub Form_Load()
currentIndex = 0
ShowCurrentImage
Timer1.Interval = 5000 ' 5 seconds
Timer1.Enabled = True
End Sub
Private Sub ShowCurrentImage()
Dim imageID As Integer
On Error Resume Next
imageID = BASE_IMAGE_ID + currentIndex
Set Picture1.Picture = LoadResPicture(imageID, vbResBitmap)
If Err.Number <> 0 Then
Picture1.Cls
Picture1.Print "Image not found"
Else
lblInfo.Caption = "Image " & (currentIndex + 1) & " of " & IMAGE_COUNT
End If
Err.Clear
End Sub
Private Sub Timer1_Timer()
NextImage
End Sub
Private Sub cmdNext_Click()
NextImage
End Sub
Private Sub cmdPrev_Click()
PrevImage
End Sub
Private Sub NextImage()
currentIndex = (currentIndex + 1) Mod IMAGE_COUNT
ShowCurrentImage
End Sub
Private Sub PrevImage()
currentIndex = (currentIndex - 1 + IMAGE_COUNT) Mod IMAGE_COUNT
ShowCurrentImage
End Sub</p>
<pre><code>### Example 3: Toolbar with Resource Icons</code></pre>
<p>vb
' Form with toolbar buttons array: cmdTool(0 to 9)
Private Type ToolButton
caption As String
iconID As Integer
enabled As Boolean
tooltip As String
End Type
Private toolConfig() As ToolButton
Private Sub Form_Load()
InitializeToolbar
ApplyToolbarConfig
End Sub
Private Sub InitializeToolbar()
ReDim toolConfig(0 To 9)
With toolConfig(0)
.caption = "New"
.iconID = 201
.enabled = True
.tooltip = "Create new document"
End With
With toolConfig(1)
.caption = "Open"
.iconID = 202
.enabled = True
.tooltip = "Open existing document"
End With
With toolConfig(2)
.caption = "Save"
.iconID = 203
.enabled = False
.tooltip = "Save current document"
End With
' ... more buttons
End Sub
Private Sub ApplyToolbarConfig()
Dim i As Long
On Error Resume Next
For i = 0 To UBound(toolConfig)
With cmdTool(i)
.caption = toolConfig(i).caption
.enabled = toolConfig(i).enabled
.ToolTipText = toolConfig(i).tooltip
Set .Picture = LoadResPicture(toolConfig(i).iconID, vbResIcon)
If Err.Number <> 0 Then
Debug.Print "Failed to load icon: " & toolConfig(i).iconID
Err.Clear
End If
End With
Next i
End Sub
Public Sub EnableTool(ByVal index As Long)
If index >= 0 And index <= UBound(toolConfig) Then
toolConfig(index).enabled = True
cmdTool(index).enabled = True
End If
End Sub
Public Sub DisableTool(ByVal index As Long)
If index >= 0 And index <= UBound(toolConfig) Then
toolConfig(index).enabled = False
cmdTool(index).enabled = False
End If
End Sub</p>
<pre><code>### Example 4: Multi-State Indicator</code></pre>
<p>vb
' Form with imgStatus (Image control)
Public Enum StatusState
stIdle = 0
stProcessing = 1
stSuccess = 2
stWarning = 3
stError = 4
End Enum
Private Const RES_STATUS_IDLE = 301
Private Const RES_STATUS_PROCESSING = 302
Private Const RES_STATUS_SUCCESS = 303
Private Const RES_STATUS_WARNING = 304
Private Const RES_STATUS_ERROR = 305
Private statusIcons() As StdPicture
Private currentStatus As StatusState
Private Sub Form_Load()
LoadStatusIcons
SetStatus stIdle
End Sub
Private Sub LoadStatusIcons()
ReDim statusIcons(0 To 4)
On Error Resume Next
Set statusIcons(stIdle) = LoadResPicture(RES_STATUS_IDLE, vbResIcon)
Set statusIcons(stProcessing) = LoadResPicture(RES_STATUS_PROCESSING, vbResIcon)
Set statusIcons(stSuccess) = LoadResPicture(RES_STATUS_SUCCESS, vbResIcon)
Set statusIcons(stWarning) = LoadResPicture(RES_STATUS_WARNING, vbResIcon)
Set statusIcons(stError) = LoadResPicture(RES_STATUS_ERROR, vbResIcon)
If Err.Number <> 0 Then
MsgBox "Warning: Some status icons could not be loaded", vbExclamation
Err.Clear
End If
End Sub
Public Sub SetStatus(ByVal newStatus As StatusState)
currentStatus = newStatus
If newStatus >= 0 And newStatus <= UBound(statusIcons) Then
If Not statusIcons(newStatus) Is Nothing Then
Set imgStatus.Picture = statusIcons(newStatus)
End If
End If
End Sub
Public Function GetStatus() As StatusState
GetStatus = currentStatus
End Function
Private Sub Form_Unload(Cancel As Integer)
Dim i As Long
For i = 0 To UBound(statusIcons)
Set statusIcons(i) = Nothing
Next i
End Sub</p>
<pre><code>## Error Handling</code></pre>
<p>vb
' Error 32813: Resource not found
On Error Resume Next
Set pic = LoadResPicture(999, vbResBitmap)
If Err.Number = 32813 Then
MsgBox "Resource not found!"
End If
' Error 48: Error loading from file
Set pic = LoadResPicture(101, vbResBitmap)
If Err.Number = 48 Then
MsgBox "Resource file is corrupt or missing!"
End If
' Safe loading pattern
Function TryLoadResPicture(ByVal resID As Variant, _
ByVal resFormat As Integer, _
ByRef pic As StdPicture) As Boolean
On Error Resume Next
Set pic = LoadResPicture(resID, resFormat)
TryLoadResPicture = (Err.Number = 0)
Err.Clear
End Function</p>
<pre><code>## Performance Considerations
- **Fast Loading**: Resources embedded in EXE (very fast access)
- **No File I/O**: No disk access required
- **Memory Usage**: Pictures consume memory until released
- **No Caching**: Each call loads fresh copy (implement caching if needed)
- **Preloading**: Load frequently used images once at startup
- **EXE Size**: Large images increase executable size
## Best Practices
1. **Always handle errors** - resource might not exist
2. **Use constants** for resource IDs for maintainability
3. **Preload frequently used images** for better performance
4. **Release memory** by setting picture objects to Nothing when done
5. **Use meaningful names** for string-based resource IDs
6. **Test all resources** during development
7. **Document resource IDs** in code or separate file
8. **Use Resource Editor** to manage resources efficiently
9. **Consider image size** - large bitmaps increase EXE size
10. **Cache in Collection** for images used multiple times
## Comparison with Related Functions
| Function | Purpose | Source | External Files |
|----------|---------|--------|----------------|
| **`LoadResPicture`** | Load from resources | Embedded .res | No |
| **`LoadPicture`** | Load from file | External file | Yes |
| **`LoadResData`** | Load binary data | Embedded .res | No |
| **`LoadResString`** | Load string | Embedded .res | No |
## `LoadResPicture` vs `LoadPicture`</code></pre>
<p>vb
' LoadResPicture - from embedded resources
Picture1.Picture = LoadResPicture(101, vbResBitmap)
' LoadPicture - from external file
Picture1.Picture = LoadPicture("C:\Images\logo.bmp")</p>
<pre><code>**When to use each:**
- **`LoadResPicture`**: Distribution (no external files), static images, faster loading
- **`LoadPicture`**: Dynamic images, user-selected files, easier updates
## Resource Format Constants</code></pre>
<p>vb
' Format constants
Const vbResBitmap = 0 ' Bitmap (.bmp)
Const vbResIcon = 1 ' Icon (.ico)
Const vbResCursor = 2 ' Cursor (.cur)
' Usage
Picture1.Picture = LoadResPicture(101, vbResBitmap)
Image1.Picture = LoadResPicture(102, vbResIcon)
Me.MouseIcon = LoadResPicture(103, vbResCursor)
```</p>
<h2 id="platform-notes">Platform Notes</h2>
<ul>
<li>Available in VB6 (not in early VB versions)</li>
<li>Requires resource file (.res) linked to project</li>
<li>Resource file created with Resource Editor or RC.EXE</li>
<li>Only one resource file per project</li>
<li>Resources embedded in compiled EXE/DLL</li>
<li>Returns <code>StdPicture</code> object (OLE automation object)</li>
<li>Supports BMP, ICO, CUR formats only</li>
<li>No native support for JPG, GIF, PNG</li>
<li>Format parameter: 0=Bitmap, 1=Icon, 2=Cursor</li>
<li>Icons can contain multiple sizes</li>
</ul>
<h2 id="limitations">Limitations</h2>
<ul>
<li><strong>Format Support</strong>: Only BMP, ICO, CUR (no JPG/GIF/PNG)</li>
<li><strong>One Resource File</strong>: Only one .res file per project</li>
<li><strong>Compile Time</strong>: Must recompile to update resources</li>
<li><strong>No Modification</strong>: Cannot modify resources at runtime</li>
<li><strong>No Caching</strong>: Each call reloads from resource</li>
<li><strong>EXE Size</strong>: Large images significantly increase EXE size</li>
<li><strong>No Compression</strong>: Images stored uncompressed</li>
<li><strong>Limited Editor</strong>: VB6 Resource Editor is basic</li>
<li><strong>No Metadata</strong>: Cannot read image dimensions before loading</li>
<li><strong>Memory Usage</strong>: Large images consume significant memory</li>
</ul>
<h2 id="related-functions">Related Functions</h2>
<ul>
<li><code>LoadPicture</code>: Load picture from external file</li>
<li><code>LoadResData</code>: Load custom binary data from resources</li>
<li><code>LoadResString</code>: Load string from resources</li>
<li><code>SavePicture</code>: Save picture object to file</li>
<li><code>Set</code>: Assign object references</li>
</ul>
</article>
<div style="margin-top: 3rem; padding-top: 2rem; border-top: 1px solid var(--border-color);">
<p>
<a href="index.html">← Back to Resources</a> |
<a href="../index.html">View all functions</a>
</p>
</div>
</main>
<footer>
<div class="container">
<p>© 2024-2026 VB6Parse Contributors. Licensed under the MIT License.</p>
</div>
</footer>
</body>
</html>