Results 1 to 7 of 7

Thread: [RESOLVED] How to set icon from bitmap

  1. #1

    Thread Starter
    Member Dragokas's Avatar
    Join Date
    Aug 2015
    Location
    Ukraine on fire (country of slaves)
    Posts
    750

    Resolved [RESOLVED] How to set icon from bitmap

    Hi

    I have a bitmap in resources (16x16 x24 bit). I'm using it in menu (with SetMenuItemBitmaps).
    I'd like to use it also as a form's icon. How can I do it?
    Code:
    Dim oPict As StdPicture
    
    Set oPict = LoadResPicture("KEY", vbResBitmap)
    
    Me.Icon = ...
    Something like CreateIconIndirect ?

    Thanks.
    Malware analyst, VirusNet developer, HiJackThis+ author || my CodeBank works

  2. #2

    Thread Starter
    Member Dragokas's Avatar
    Join Date
    Aug 2015
    Location
    Ukraine on fire (country of slaves)
    Posts
    750

    Re: How to set icon from bitmap

    P.S. I saw this code, but it looks dirty and returns strange result for me.
    Malware analyst, VirusNet developer, HiJackThis+ author || my CodeBank works

  3. #3
    Frenzied Member
    Join Date
    Dec 2012
    Posts
    1,668

    Re: How to set icon from bitmap


  4. #4

    Thread Starter
    Member Dragokas's Avatar
    Join Date
    Aug 2015
    Location
    Ukraine on fire (country of slaves)
    Posts
    750

    Re: How to set icon from bitmap

    It looks good, thanks. However, I'm not much familiar with graphics API, and don't know from what point of your code I can get StdPicture object to set directly to me.Icon without saving it on the disk.
    Malware analyst, VirusNet developer, HiJackThis+ author || my CodeBank works

  5. #5
    PowerPoster
    Join Date
    Sep 2012
    Posts
    2,083

    Re: How to set icon from bitmap

    Maybe the following links are useful to you:

    http://www.planet-source-code.com/vb...46320&lngWId=1

    http://www.planet-source-code.com/vb...60600&lngWId=1

    http://www.planet-source-code.com/vb...28832&lngWId=1

    http://www.planet-source-code.com/vb...40839&lngWId=1

    http://www.planet-source-code.com/vb...=6630&lngWId=1

    In addition, Lavolpe's AlphaImageControl and Olaf's RC5 (Cairo.Drawing) should also be able to implement the functionality you need.

  6. #6
    PowerPoster
    Join Date
    Jun 2013
    Posts
    7,454

    Re: How to set icon from bitmap

    Quote Originally Posted by Dragokas View Post
    It looks good, thanks. However, I'm not much familiar with graphics API, and don't know from what point of your code I can get StdPicture object to set directly to me.Icon without saving it on the disk.
    24Bit-Bitmaps are old fashioned stuff, why not use real Alpha-Resources (PNG, SVG) for all those little Images which fly around in ones App.

    VBs StdPictures do not support proper rendering from such Alpha-Resources - so you will have to enhance its capabilities first
    (to not risk an error-message, once you try to set a Form.Icon to a StdPicture which contains a "32Bit-Alpha-suporting Icon-Resource".

    So - since you are at it now anyways - why not solve the whole thing more thoroughly...

    You could use the RC5 for such stuff of course - but if (for some unexplainable reason ) you try to avoid using it -
    you can take a look at the project I published in October 2015 here:
    http://www.vbforums.com/showthread.p...BaseInterfaces

    Compile the little Helper-Lib vbInterfaces.dll into its own Binary (or into one of your existing Dll-Projects), to enable safe IDE-usage.

    Then the rest becomes simple, when you look at Tutorial-Folder #9, which demonstrates:
    - centralized Resource-Loading from all kind of Alpha-Resources (in Sub Main - storing "reusable alpha-blobs under unique String-Keys" in a kind of "global ImageList")
    - with the "global Resource-ImageList-Collection" prepared, you can then use LoadPictureEx(StringKey,...) against all Controls/Forms which support VBs StdPicture

    Here is some example calls the above mentioned Demo #9 makes in Form_Load:
    Code:
      Set Me.Icon = LoadPictureEx("Png3_16x16", vbPicTypeIcon) 'just to show, that a Form-Icon can easily be derived from a Png-Resource
      Set Me.MouseIcon = LoadPictureEx("HandCursor,11,5", vbPicTypeIcon) 'load an Alpha-MouseCursor from a PNG (note the HotSpot-Offsets, given behind the ImgKey)
      
      Set Command1.Picture = LoadPictureEx("Ico3") 'CommandButton-Picture, derived from an Alpha-Icon-Resource
      '...
    As said, that would solve the problem (reusage of the same App-Resource in different StdPicture-Props - over the same "StringKey") thoroughly -
    and if I may make a suggestion - don't "rip apart" the stuff which makes this possible (the code which is represented in the vbInterfaces.dll-Project).
    Leave it "in a Dll" (your own, already existing one if you like) - and you can implement other stuff as e.g. "lightweight classes" with ease and quite some IDE-safety.

    Olaf

  7. #7

    Thread Starter
    Member Dragokas's Avatar
    Join Date
    Aug 2015
    Location
    Ukraine on fire (country of slaves)
    Posts
    750

    Re: How to set icon from bitmap

    dreammanor, Schmidt, thanks.
    Nice options.
    Malware analyst, VirusNet developer, HiJackThis+ author || my CodeBank works

Tags for this Thread

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