Codejock Forums Homepage
Forum Home Forum Home > Codejock Products > ActiveX COM > Command Bars
  New Posts New Posts RSS Feed - Loading Icons From a Resource File
  FAQ FAQ  Forum Search   Events   Register Register  Login Login

Loading Icons From a Resource File

 Post Reply Post Reply
Author
Message
mzwandile View Drop Down
Newbie
Newbie
Avatar

Joined: 16 August 2012
Location: South Africa
Status: Offline
Points: 6
Post Options Post Options   Thanks (0) Thanks(0)   Quote mzwandile Quote  Post ReplyReply Direct Link To This Post Topic: Loading Icons From a Resource File
    Posted: 28 September 2012 at 10:12am
Hi
 
I am using Xtreme Command Bars ActiveX v15.2.1 and need assistance with loading icons from a resource file (VB6 .RES file). I've got a PNG image with ID: "Exit16_PNG" in the resource file (filename.RES) and I'm doing the following in my VB6 Code to load the image:
 
CommandBars.Icons.LoadBitmapFromResource App.hInstance, "Exit16_PNG", ID_FILE_EXIT, xtpImageNormal
 
This does not load the icon though! Confused Am I missing something?
 
Any assistance will be much appreciated.
Mzwandile Jojisa
Software developer
Sage Alchemex
Back to Top
SuperMario View Drop Down
Admin Group
Admin Group
Avatar

Joined: 14 February 2004
Status: Offline
Points: 18057
Post Options Post Options   Thanks (0) Thanks(0)   Quote SuperMario Quote  Post ReplyReply Direct Link To This Post Posted: 03 October 2012 at 9:47am
Could be a number of things without seeing your complete code or how you made the RES.

First in the VB IDE (see add-in manager if not visible) open VB Resource Editor, verify your PNG images have the "PNG" type.  If you were to add a new PNG you would click Add Custom Resource and in Resource type write "PNG" after you have selected the image.

Second, app.hinstance just returns a handle to the instance of the application.  You need to use LoadLibraryEx.

Here is a working sample assuming your RES file is set up correctly like I mentioned above.

Option Explicit

Private Declare Function LoadLibraryEx _
                Lib "kernel32" _
                Alias "LoadLibraryExA" (ByVal lpLibFileName As String, _
                                        ByVal hFile As Long, _
                                        ByVal dwFlags As Long) As Long
                                        
Private Declare Function FreeLibrary _
                Lib "kernel32" (ByVal hLibModule As Long) As Long
                                        
Private m_hMod As Long

Const ID_TEST_NEW = 111
Const ID_TEST_ECLUB = 112
                                        
Private Sub LoadResources()
    Dim IDS() As Long
    
    ReDim IDS(1)
    IDS(0) = ID_TEST_NEW
    IDS(1) = ID_TEST_ECLUB
    
    If (m_hMod <> 0) Then
        FreeLibrary m_hMod
    End If

    m_hMod = 0
    
    m_hMod = LoadLibraryEx(App.Path + "\Project1.exe", 0, 0)
    
    ImageManager.Icons.LoadBitmapFromResource LoadLibraryEx(App.Path + "\Project1.exe", 0, 0), ID_TEST_NEW, IDS(0), xtpImageNormal
    ImageManager.Icons.LoadBitmapFromResource LoadLibraryEx(App.Path + "\Project1.exe", 0, 0), ID_TEST_ECLUB, IDS(1), xtpImageNormal
    
    If (m_hMod <> 0) Then
        FreeLibrary m_hMod
    End If
    
End Sub


Private Sub Form_Load()

    CommandBarsGlobalSettings.App = App
    
    CommandBars.DeleteAll
    
    Dim Toolbar As CommandBar
     
    Set Toolbar = CommandBars.Add("mainapp", xtpBarTop)
    With Toolbar.Controls
        .Add xtpControlButton, ID_TEST_NEW, "&Test"
    End With
       
    LoadResources
    
    Set CommandBars.Icons = ImageManager.Icons
    
End Sub

Back to Top
iamgtd View Drop Down
Senior Member
Senior Member
Avatar

Joined: 25 February 2009
Status: Offline
Points: 131
Post Options Post Options   Thanks (0) Thanks(0)   Quote iamgtd Quote  Post ReplyReply Direct Link To This Post Posted: 22 February 2013 at 2:38am
How does it work in C#.NET?

Public Sub LoadIconFromResource( _
   ByVal Module As Long, _
   ByVal Resource As Long, _
   ByVal Command As Long, _
   ByVal imageState As XTPImageState _
) 
Is there another way to get the value for Module as the API-Function  LoadLibraryEx?
In C# the images in the resources have names (string) and not  long-values, how do I convert this values?

thanks in advance
---------

OS: Win 10 64 bit

Codejock Version 22.1 ActiveX

MS Visual Studio 2022 - C#

---------
Back to Top
 Post Reply Post Reply
  Share Topic   

Forum Jump Forum Permissions View Drop Down

Forum Software by Web Wiz Forums® version 12.04
Copyright ©2001-2021 Web Wiz Ltd.

This page was generated in 0.156 seconds.