Results 1 to 10 of 10

Thread: obtain a 32-bit icon from the resource in IDE

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Dec 2008
    Location
    Argentina
    Posts
    441

    obtain a 32-bit icon from the resource in IDE

    It is possible to obtain a 32-bit icon from the resource file of my project in the IDE in the section ICON

    LoadImage does not work
    Code:
    hIcon = LoadImage(App.hInstance, lpSection, IMAGE_ICON, lWidth, lHeight, LR_SHARED Or LR_LOADMAP3DCOLORS)
    LoadResPicture still less because it is an icon of 32 Bits

    I do not want to use LoadResData

    There any trick?
    Attached Images Attached Images  
    leandroascierto.com Visual Basic 6 projects

  2. #2
    Fanatic Member
    Join Date
    Mar 2009
    Posts
    804

    Re: obtain a 32-bit icon from the resource in IDE

    The code below (from LaVolpe) will load a 32bit icon FILE to your form. How did
    you get the 32bit icon into the Resource file? I tried with VB's Resource Editor
    but it failed with "Invalid icon". Assuming you built the .res file
    some other way you might try the LoadResource API:
    Private Declare Function LoadResource Lib "kernel32.dll" ( _
    ByVal hInstance As Long, _
    ByVal hResInfo As Long) As Long

    Code:
    Option Explicit
    Private Declare Function LoadImage Lib "user32.dll" Alias "LoadImageA" (ByVal hInst As Long, ByVal lpsz As String, ByVal un1 As Long, ByVal n1 As Long, ByVal n2 As Long, ByVal un2 As Long) As Long
    Private Declare Function SendMessage Lib "user32.dll" Alias "SendMessageA" (ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByRef lParam As Any) As Long
    Private Const WM_SETICON As Long = &H80
    Private Const ICON_SMALL As Long = 0
    Private Const IMAGE_ICON As Long = 1
    Private Const LR_DEFAULTSIZE As Long = &H40
    Private Const LR_LOADFROMFILE As Long = &H10
    
    Private Sub Form_Load()
        Dim hIcon As Long
        ' replace FileName below with a valid icon path/filename
        hIcon = LoadImage(0&, FileName, IMAGE_ICON, 0&, 0&, LR_DEFAULTSIZE Or LR_LOADFROMFILE)
        If hIcon Then
            SendMessage Me.hWnd, WM_SETICON, ICON_SMALL, ByVal hIcon
        End If
    End Sub

  3. #3
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    Re: obtain a 32-bit icon from the resource in IDE

    VB won't even let you load a 32bpp icon in the icon section of the resource file, will it?

    LoadResData is the answer, and use of the CreateIconFromResourceEx API can create a hIcon that can be used with WM_SETICON (shown above in post #2). See this thread, post #2 for an example of the API usage.

    Edited: that last link should read Post #1, "Bonus #2"
    Last edited by LaVolpe; Jun 16th, 2010 at 10:45 AM.
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  4. #4

    Thread Starter
    Hyperactive Member
    Join Date
    Dec 2008
    Location
    Argentina
    Posts
    441

    Re: obtain a 32-bit icon from the resource in IDE

    Quote Originally Posted by LaVolpe View Post
    VB won't even let you load a 32bpp icon in the icon section of the resource file, will it?

    LoadResData is the answer, and use of the CreateIconFromResourceEx API can create a hIcon that can be used with WM_SETICON (shown above in post #2). See this thread, post #2 for an example of the API usage.

    Edited: that last link should read Post #1, "Bonus #2"
    Hello I had read your article using LoadResData from (Section / type) "CUSTOM", my intrigue was whether it could do the same but from the (Section / type) "ICON"

    just wondering out of curiosity.

    Greetings.
    leandroascierto.com Visual Basic 6 projects

  5. #5
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    Re: obtain a 32-bit icon from the resource in IDE

    LeandroA. As mentioned in previous replies, I don't even think you can put a 32bpp icon in the icon section. And even if you could, you'd get an error using LoadResPicture because VB cannot load a 32bpp icon into a stdPicture object - error is invalid picture type (or something like that). LoadResPicture creates a stdPicture/IPictureDisp object. VBClassicRocks mentioned using resource APIs and that should also work, but I think it only works for compiled apps, not while in IDE (not positive about that).

    Edited: I think LoadResData only works with Custom resource section(s), not the icon, cursor & bitmap sections
    Last edited by LaVolpe; Jun 16th, 2010 at 02:04 PM.
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  6. #6
    New Member
    Join Date
    Sep 2009
    Posts
    4

    insert 32bit icon into a X.res file

    pre:
    create new project.
    if you haven't done this untill now- follow usual way to enable resource-manager in vb6.

    create a new <any name>.res file and save it in project's folder.

    you've got a blank res file, save your project and close down vb6.

    lets say you've saved the res file in the name project1.res.

    download reshacker, run, open project1.res.
    click action-add new resource

    browse and open the 32bit icon, give it a numeric name for example: 1001
    and write in the language the number 1033 (means english. 1037 is hebrew, it does not really matter. you can also leave it blank).

    'icon" and "icongroup" nodes will be added to the resource file. click file-save and you can quit reshacker. notice that if you open the res file in vb6 again using the resource manager it will get corrupted and the 32bit icon will be erased. so manage your other resources using vb first, like editing text bmp and other stuff, and finish up with reshacker, you can also use the reshacker as your default resources manager, and you don't have to quit and re-open vb6 and reshacker again and again, just keep saving your opened resource file in reshacker to see changes will running your project.

    working with 32bit icons example:
    http://www.vbaccelerator.com/home/vb...ly/article.asp

    Elad Karako
    http://iCompile.0fees.net
    Last edited by eladkarako; Oct 1st, 2010 at 03:49 PM.

  7. #7
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    Re: obtain a 32-bit icon from the resource in IDE

    I'd imagine the only way is to build the res file yourself, with/without resHacker (I've experimented with such things in my Manifest Creator project).

    However, VB corrupting the icon is troublesome -- what a hassle. Not sure it is worth it. May be much simpler to load your icon in the Custom section, use LoadResData to extract bytes & send bytes to API for an icon handle. I assume VB still can't load a 32bpp icon even if it does exist in the Icon section of the res file?

    Regardless, resHacker is an option.
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  8. #8
    New Member
    Join Date
    Sep 2009
    Posts
    4

    Re: obtain a 32-bit icon from the resource in IDE

    Quote Originally Posted by LaVolpe View Post
    I'd imagine the only way is to build the res file yourself, with/without resHacker...
    nope. thats the preferred way unless you use some of the VC executable (rc for example) to create a valid win32 binary file. it is longer and not necessary for most programmers.

    Quote Originally Posted by LaVolpe View Post
    However, VB corrupting the icon is troublesome -- what a hassle.
    thats that...
    vb6 does not support directly 32bit (alpha transparency) images, thats why
    you are using a 3'rd party application that does.


    Quote Originally Posted by LaVolpe View Post
    ...Not sure it is worth it. May be much simpler to load your icon in the Custom section, use LoadResData to extract bytes & send bytes to API for an icon handle.
    yes vb6 should work fine with some bitwise operation.

    although I recommended using GDI+ API Library,
    use can use GDIPlus Wrapper project to load and manipulate images, loading from resources or files.

    I've attached 2 zip files for you to download.
    you can find out more about this project searching in PlanetSourceCode.

    Elad Karako
    http://iCompile.0fees.net
    Attached Files Attached Files
    Last edited by eladkarako; Oct 2nd, 2010 at 05:38 AM.

  9. #9
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    Re: obtain a 32-bit icon from the resource in IDE

    Quote Originally Posted by eladkarako View Post
    ...use can use GDIPlus Wrapper project to load and manipulate images, loading from resources or files.

    I've attached 2 zip files for you to download.
    you can find out more about this project searching in
    I know more about GDI+ than you may think...
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  10. #10

    Thread Starter
    Hyperactive Member
    Join Date
    Dec 2008
    Location
    Argentina
    Posts
    441

    Re: obtain a 32-bit icon from the resource in IDE

    [QUOTE=eladkarako;3891729]
    you can find out more about this project searching in PlanetSourceCode.

    haha LaVolpe is the largest developer of GDI + to vb6 check

    thanked for your intention to help. I intended to read a 32bit alpha icon of the form above, I know the other optional methods

    thanks anyway
    leandroascierto.com Visual Basic 6 projects

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width