Create a Icon from pBitmap / hBitmap Topic is solved

Get help with using AutoHotkey and its commands and hotkeys
User avatar
Hellbent
Posts: 1058
Joined: 23 Sep 2017, 13:34

Create a Icon from pBitmap / hBitmap

25 Mar 2020, 07:20

Anyone know how to use a bitmap as a Icon (tray or w/e) without having to use any external resources? Is it even possible?
I have never had any interest in changing a scripts icon before, but I figured it might be time to look into it.

I'm only really interested in self contained code.

For example, if I wanted to take this and use it as a icon.

Code: Select all

HB_BITMAP_MAKER(){
	pBitmap := Gdip_CreateBitmap( 16 , 16 ) 
	G := Gdip_GraphicsFromImage( pBitmap )
	Gdip_SetSmoothingMode( G , 2 )
	Brush := Gdip_BrushCreateSolid( "0xFF3399FF" )
	Gdip_FillRectangle( G , Brush , -1 , -1 , 18 , 18 )
	Gdip_DeleteBrush( Brush )
	Gdip_DeleteGraphics( G )
	return pBitmap
}
User avatar
boiler
Posts: 6131
Joined: 21 Dec 2014, 02:44

Re: Create a Icon from pBitmap / hBitmap

25 Mar 2020, 08:42

As far as I know, you have to create an icon file from your image file using an external program, but I don’t see a reason why you couldn’t write the code to generate an icon format in AHK so it’s self-contained in your script. I don’t know how involved that would be.

Alternatively, you could use your code to generate the image, save it as a bmp or png file so you can use an icon generator app, then embed that icon file into your code using one of the binary-to-ASCII conversion routines. I know that’s not exactly what you’re looking for, but the end result would be self-contained.
User avatar
Hellbent
Posts: 1058
Joined: 23 Sep 2017, 13:34

Re: Create a Icon from pBitmap / hBitmap

25 Mar 2020, 09:14

boiler wrote:
25 Mar 2020, 08:42
Alternatively, you could use your code to generate the image, save it as a bmp or png file so you can use an icon generator app, then embed that icon file into your code using one of the binary-to-ASCII conversion routines. I know that’s not exactly what you’re looking for, but the end result would be self-contained.
Would that be something like using Base64?

Something like this:

Code: Select all

This.B64.BlueBirdFrames := "iVBORw0KGgoAAAANSUhEUgAAAZAAAAAzCAYAAAC5QF44AAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwA"
teadrinker
Posts: 1858
Joined: 29 Mar 2015, 09:41
Contact:

Re: Create a Icon from pBitmap / hBitmap  Topic is solved

25 Mar 2020, 09:31

Hellbent wrote: For example, if I wanted to take this and use it as a icon.
It's pretty simple:

Code: Select all

#Persistent
pToken := Gdip_Startup()
pBitmap := HB_BITMAP_MAKER()
hIcon := Gdip_CreateHICONFromBitmap(pBitmap)
Gdip_DisposeImage(pBitmap)
Menu, Tray, Icon, HICON:%hIcon%
Gdip_Shutdown(pToken)

HB_BITMAP_MAKER(){
   pBitmap := Gdip_CreateBitmap( 16 , 16 ) 
   G := Gdip_GraphicsFromImage( pBitmap )
   Gdip_SetSmoothingMode( G , 2 )
   Brush := Gdip_BrushCreateSolid( "0xFF3399FF" )
   Gdip_FillRectangle( G , Brush , -1 , -1 , 18 , 18 )
   Gdip_DeleteBrush( Brush )
   Gdip_DeleteGraphics( G )
   return pBitmap
}
User avatar
Hellbent
Posts: 1058
Joined: 23 Sep 2017, 13:34

Re: Create a Icon from pBitmap / hBitmap

25 Mar 2020, 09:39

@teadrinker

Thank you very much.
That is exactly what I was hoping for.

Return to “Ask For Help”

Who is online

Users browsing this forum: mmmax, songdg and 51 guests