|
-
Jan 26th, 2018, 03:24 PM
#1
[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.
-
Jan 26th, 2018, 03:28 PM
#2
Re: How to set icon from bitmap
P.S. I saw this code, but it looks dirty and returns strange result for me.
-
Jan 27th, 2018, 11:43 AM
#3
Re: How to set icon from bitmap
-
Jan 27th, 2018, 12:10 PM
#4
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.
-
Jan 27th, 2018, 12:54 PM
#5
Re: How to set icon from bitmap
-
Jan 27th, 2018, 01:21 PM
#6
Re: How to set icon from bitmap
 Originally Posted by Dragokas
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
-
Jan 27th, 2018, 01:27 PM
#7
Re: How to set icon from bitmap
dreammanor, Schmidt, thanks.
Nice options.
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|