Print Page | Close Window

Loading Icons From a Resource File

Printed From: Codejock Forums
Category: Codejock Products
Forum Name: Command Bars
Forum Description: Topics Related to Codejock Command Bars
URL: http://forum.codejock.com/forum_posts.asp?TID=20178
Printed Date: 28 September 2024 at 10:19pm
Software Version: Web Wiz Forums 12.04 - http://www.webwizforums.com


Topic: Loading Icons From a Resource File
Posted By: mzwandile
Subject: Loading Icons From a Resource File
Date 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



Replies:
Posted By: SuperMario
Date 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



Posted By: iamgtd
Date 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  XtremeCalendarControl~Enumerations~XTPImageState_EN.html - 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#

---------



Print Page | Close Window

Forum Software by Web Wiz Forums® version 12.04 - http://www.webwizforums.com
Copyright ©2001-2021 Web Wiz Ltd. - https://www.webwiz.net