Jump to content
Tuts 4 You
Sign in to follow this  
LCF-AT

.ICO to Bitmap...

Recommended Posts

LCF-AT

Hi guys,

I have another small question about icons / ico files.Is it possible to load ico files from resources and change them to bitmap icons?I would like to use the "SetMenuItemBitmaps" function but its not working with normal ico files.Normaly I am mostly just using ico files and I dont wanna convert them to another bitmap icons if I need them in this format.So is it doable to load & convert ico files / handle on fly with any xy function (Icon2BitmapIcon etc) and using them with SetMenuItemBitmaps function?

greetz

Share this post


Link to post
fearless
  • Load icon
  • Create a compatible bitmap same size as icon
  • Use DrawIcon / DrawIconEx to draw the icon into the hdc's bitmap
  • return the hBitmap and free any resources not required - dc's, icon (if not needed anymore)
  • Use the SetMenuItemBitmaps

Might need to include a few other steps but the basics outlined should convert the icon to a bitmap.

  • Like 2

Share this post


Link to post
LCF-AT

Hi,

ok thanks.One more question about it.How to make the bitmap transparent?In this case I need again to fill it with some color or seting back color of Menu in DrawIconEx flickerfreedraw flag. :( Is there no way only to use that icon as it is etc without to handle any back color stuff anymore?

greetz

Share this post


Link to post
Zulu

I think you can simply use almost any image editing software, select the area you want to make transparent (e.g. using magic wand tool) and then simply use the DEL key to delete the area. Then the deleted area should have a checkered texture which means it's transparent.

  • Like 1

Share this post


Link to post
LCF-AT

Hi again,

so my goal was it not to create extern bmp files from ico files.I only wanna use ico files and wanna change them to bitmap icons on fly and using it with SetMenuItemBitmaps function.

I made a example ico icon with alpha blend.Its just a rounded corner icon wich is transparent inside / outside and look so.

ico.png.1cabb1abb19c1f80e6a46a5bbd919ab8.png

Now I wanna load that ico and change it to bitmap and calling it with SetMenuItemBitmaps function and the icon should be shown like on pic above.

If I change the ico file to bmp file (extern) then the transparent parts are all black color like this....

ico2.png.186f41b72830453fd61adf8adbf7a22b.png

...in this case I could use the function LoadImage with LR_CREATEDIBSECTION flag and calling then SetMenuItemBitmaps function and the icon gets shown correctly.The black parts are then transparent.

ico3.png.ff8af61b9b9e47896d4af4ebeabd3968.png

All correctly.The question is how to get same results using / loading normal ico files change it to bitmap on fly  and calling SetMenuItemBitmaps function.

Below I did attch the ico file and bmp ico file too for testing.

greetz

Icos.rar

Share this post


Link to post
LCF-AT

Hi again,

ok I played a little around and created a function what does work so far to change ico to bitmap.Problem I still have its only working for ico files with alpha blend.

Example: Below my function I wrote.

		    invoke CreateBitmapIconFromIcon,NormalIconID,hInstance
		    .if eax != FALSE
		        mov _IconBitmapObject,eax
                        invoke SetMenuItemBitmaps,handle,MEN_1, MF_BYCOMMAND, _IconBitmapObject, _IconBitmapObject
		    .endif
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;


CreateBitmapIconFromIcon proc  uses edi esi ebx edx ecx _ResID:DWORD,_hInstance:DWORD

local _iconinfo:ICONINFO
local _BITMAP:BITMAP
local _hbitmap:DWORD

    invoke LoadImage,_hInstance,_ResID,IMAGE_ICON,16, 16,LR_DEFAULTCOLOR
    .if eax != FALSE
        mov edi, eax
        invoke GetIconInfo,edi,addr _iconinfo
        .if eax != FALSE
            .if _iconinfo.ICONINFO.fIcon == TRUE && _iconinfo.ICONINFO.hbmColor != FALSE && _iconinfo.ICONINFO.hbmMask != FALSE
                invoke GetObject,_iconinfo.ICONINFO.hbmColor,sizeof _BITMAP,addr _BITMAP
                .if eax != FALSE
                    .if _BITMAP.BITMAP.bmWidth > NULL && _BITMAP.BITMAP.bmHeight > NULL
                        invoke CopyImage,_iconinfo.ICONINFO.hbmColor,IMAGE_BITMAP,0,0,LR_DEFAULTCOLOR
                        .if eax != FALSE
                            mov _hbitmap, eax
                            invoke CopyImage,_hbitmap,IMAGE_BITMAP,0,0,LR_DEFAULTCOLOR or LR_CREATEDIBSECTION
                            .if eax != FALSE
                                mov esi, eax ; final
                                invoke DeleteObject,_hbitmap
                                invoke DeleteObject,_iconinfo.ICONINFO.hbmColor
                                invoke DeleteObject,_iconinfo.ICONINFO.hbmMask
                                invoke DestroyIcon,edi
                                mov eax, esi ; final
                            .else
                                invoke DeleteObject,_hbitmap
                                jmp @F
                            .endif
                        .else
                            jmp @F
                        .endif
                    .else
                        jmp @F
                    .endif
                .else
                    jmp @F
                .endif
            .else
                @@:
                invoke DeleteObject,_iconinfo.ICONINFO.hbmColor
                invoke DeleteObject,_iconinfo.ICONINFO.hbmMask
                invoke DestroyIcon,edi
                mov eax,FALSE
            .endif
        .else
            invoke DestroyIcon,edi
            mov eax, FALSE
        .endif
    .endif
	Ret

CreateBitmapIconFromIcon endp

The problem I still got is that lower color icons gets shown just with white color.

ico4.png.34167c41a85399b4a8c06b541483c7cf.png

In this white area should be the orange icon to see.Anyhow still not working as I want yet.Has anybody some hints how to adjust my function to make it work correctly with all icons to make them to bitmap with transparent parts etc?

greetz

Share this post


Link to post
kao

Read about LR_LOADTRANSPARENT flag for LoadImage. That's how it was done in the old days before alpha blending..

  • Like 2

Share this post


Link to post
fearless

If you know the background color, then you can fake it by painting with the background color first (FillRect), then drawing over that.

  • Like 1

Share this post


Link to post
LCF-AT
Posted (edited)

Hi again,

are there any other function I can use to set normal ico icons into a menu without using SetMenuItemBitmaps function?Is there no function to set none bitmap icons into a menu?

Example: If I call LoadIcon function & SendMessage with WM_SETICON flag then the loaded icon will set into the app bar etc you know what I mean.The icon is shown like it is.Also if I create a toolbar then I can also set normal icons into.Should it not also be possible with menus too without using a ownerdraw?Did I miss something that I only find and see that one function called SetMenuItem>Bitmaps<?No function like SetMenuItemIcon?Just asking only.I am getting confused again with that whole icon stuff ico/bmp/transparent etc.As I said,normaly I am just using ico icons and no bitmap icons or wanna just use ico icons only.But I also dont wanna do some extra work for this to convert to bmp icon +/- making some area of the icon transparent / filling with color xy or whatever you know.

greetz

EDIT: How can I check whether a loaded icon used alpha blend mode?

Edited by LCF-AT (see edit history)

Share this post


Link to post
kao

I believe you have 2 options:

1) continue insisting on " I am just using ico icons and no bitmap icons or wanna just use ico icons only". You'll spend hours or perhaps days trying to cover all possibilities (alpha/non-alpha/monochrome/what not), writing code that analyzes ICO file, converts ICO to BMP on the fly, etc.;

2) you take an image editor and convert all your ICO to BMP. It's a one time effort. Even if it takes 1 minute per icon, you'll be done in 30 minutes or so.

From where I stand, the choice is clear. 

  • Like 1

Share this post


Link to post
fearless

I usually use XnView's XnShell to right click on an image file in explorer to convert to ICO/BMP/PNG. For images that I use in toolbars and menus I open them up in in IcoFX and flood fill the background of the image with the grey color seen in the menus/toolbars and save as bitmaps. Saves a lot of time.

Only other possibility is to create your own control that mimics menus and have it display what you want. As you have wrote so much code, at this point you could put it into a custom control, which might give you the flexibility that the ownerdrawn stuff hasn't. I once created a custom control / menu type control that could emulate the look of the steam UI:

HotMenu.gif

Share this post


Link to post
LCF-AT

Hi again,

so I see another problems using bmp icons.For example I am using a bones.ico file from MASM set.Its a ico file and I changed it to bmp icon.The icon has a size of 32x32 only.Now if I load this bmp bitmap icon with size of 16x16 and using LR_CREATEDIBSECTION flag (LR_LOADTRANSPARENT dosent work) and using this handle now with SetMenuItemBitmaps function then its transparent but looks not correctly.Some icon pixel are not shown etc.On the other hand if I load the same icon as ico file using LoadIcon function and set this into App bar via WM_SETICON then its shown correctly.This I dont check.Windows does make the icon smaller to 16x16 but its still looking like 32x32 icon so I mean it looks same but in my case not.You know what I mean?Ok ,looks almost same.Hhmm.

T1.png.9125bb88fbfe5f4292b8a216119dfe22.pngT2.png.739ccb0c94eef98785d0b5bfccf34bc6.pngT3.png.8041c26d004d81118c964c1c5ac16b44.png

Anyway,this whole icon thing sucks more or less now a little.Maybe I should it be etc.

Thanks again so far guys.

Share this post


Link to post
fearless

Windows has a default size for icons, and will scale down icons for the titlebar. For menus and bitmaps I think I've always opted for size 24x24 for the bitmaps if i recall correctly.

  • Like 1

Share this post


Link to post
LCF-AT

Ok thanks fearless.

Ok one more try maybe.So I see if I am using the function above I made then its working only for icons with alpha blend.In the tool IcoFX I changed some icons to alpha icons.If I now just only change all icons I wanna use to alpha icons + using my function then I get good results I can live with.But now I just wanna change my function a little to check some paramter xy to verify whether the icon used alpha or not (if not then I can aboard the process and sending a error out).If I use a not alpha icon then its just draws white color only what I wanna prevent.Now I am just looking for any checking method if alpha used or not you know.So is it possible to find that out with any bitmap struct and how?I tried already some like BITMAPINFO & BITMAPINFOHEADER but getting just same datas into also not all.Maybe I am using it wrong or so.If I read it right then I should use BITMAPINFOHEADER struct and checking for biBitCount for 32 right?Not sure yet but also in BITMAP struct I only get this and same datas for alpha and not alpha icons...

Structure
Address    Name                              Type      Value             Hex Dump
002CF3BC   bmType                            DWORD     00000000
002CF3C0   bmWidth                           DWORD     00000010
002CF3C4   bmHeight                          DWORD     00000010
002CF3C8   bmWidthBytes                      DWORD     00000040
002CF3CC   bmPlanes                          WORD      0001
002CF3CE   bmBitsPixel                       WORD      0020
002CF3D0   bmBits                            DWORD     00000000

greetz

Share this post


Link to post
LCF-AT

Hi again,

I am still working and trying without success.

For example: Using CreateCompatibleBitmap & DrawIconEx function with or without hbrFlickerFreeDraw flag with the Menu color to fill the transparent parts of icon is only a 50% solution.If I select this menu entry with the icon with the mouse then the transparent part has a other color like this....

A1.png.cf20b89ad806ceadda2cbc6de84cc143.png

A2.png.7a8fc8cb1eab2ae9cceda545ef38794f.png

....exactly this dosent happen if I load bitmap icons.Maybe you will see on the pics that the diffrent is almost not to see but if you use a color picker then you see it.So my question is whether its now really possible anyhow to load a ico file and make this icon handle to a bitmap handle (some magic xy) and using it via SetMenuItemBitmap function?Maybe some of you coders using any xy language could try this out.Maybe you have for this special macro function you can use or something like that and if it should work then you could post this code of this what makes the ico to bitmap.At the end it should look like this so I mean the area..

A3.png.5d62a23dae5a8eaa526c592d038a448c.png

...below I have attched the ico file..

bones.ico

...as I said,just wanna know whether its doable now or not anyhow and if yes then I would like to know how its done and if its really not doable (maybe) then I can also forget it to work and test go on with that icon stuff and do convert ico to bmp icons in the future if I wanna have a 100% showing result you know.Would be nice if some of you could check that out a little.

Thank you and greetz

Share this post


Link to post
Teddy Rogers

Does this only happen with your own transparent icons?

Ted.

  • Like 1

Share this post


Link to post
LCF-AT

Hi Ted,

with all icons.Just test the one I did attach above.

invoke LoadImage,hInstance,300,IMAGE_ICON,16, 16,LR_DEFAULTCOLOR ;or LR_CREATEDIBSECTION
invoke IconToBmp,eax,16,hWnd
mov _IconBitmapObject,eax

_IconBitmapObject used with SetMenuItemBitmaps function
----------------
IconToBmp PROC hICON:DWORD,ix:DWORD,hManagerDlg:DWORD
LOCAL myDC :DWORD
LOCAL hDC :DWORD
LOCAL PrevBmp :DWORD
LOCAL hBrush :DWORD
LOCAL OldObj :DWORD
LOCAL hRgn :DWORD
LOCAL hBmp :DWORD

invoke GetDC, hManagerDlg
mov hDC,eax
invoke CreateCompatibleDC, hDC
mov myDC, eax
invoke CreateCompatibleBitmap,hDC, ix, ix
mov hBmp, eax
invoke SelectObject, myDC, eax
mov PrevBmp, eax
invoke ReleaseDC,hManagerDlg,hDC

invoke GetSysColor,COLOR_MENU
invoke CreateSolidBrush, eax;0FFFFFFh
mov hBrush,eax

invoke SelectObject, myDC, hBrush
mov OldObj,eax

invoke CreateRectRgn, 0, 0, ix, ix
mov hRgn,eax
invoke PaintRgn, myDC, hRgn
invoke DeleteObject,hRgn
invoke SelectObject,myDC,OldObj
invoke DeleteObject,hBrush

invoke GetSysColor, COLOR_MENU ; default menu system color
invoke CreateSolidBrush,eax
invoke DrawIconEx, myDC, 0, 0, hICON, ix, ix, 0,eax, DI_NORMAL

invoke SelectObject, myDC, PrevBmp
invoke DeleteDC, myDC
invoke DestroyIcon, hICON

mov eax,hBmp
ret 
IconToBmp ENDP

...maybe its possible to convert the ico file from resources to bitmap file anyhow and loading it then.Not sure.Maybe much more work again to do that.Something like that..

- load ico via LoadImage | IMAGE_ICON = ico handle

- convert ico handle to bitmap handle or extern bmp file (if its not doable to do it on fly in memory)

- load new temporary bmp via LoadImage IMAGE_BITMAP

...maybe like this?

But I think it should be anyhow possible to load the icon and doing something with the ICONINFO.hbmColor etc but what and how is the question you know.

greetz

Share this post


Link to post
LCF-AT

Hi again,

I made some  new code....

		     invoke LoadImage,hInstance,400,IMAGE_ICON,16, 16,LR_DEFAULTSIZE or LR_CREATEDIBSECTION
		     mov edi,eax

		     invoke GetIconInfo,edi,addr _iconinfo
		     invoke DeleteObject,_iconinfo.ICONINFO.hbmMask
		     invoke DestroyIcon,edi
		     mov eax,_iconinfo.ICONINFO.hbmColor  ; bitmap of icon
		     mov _IconBitmapObject,eax

		     invoke GlobalAlloc,GMEM_FIXED + GMEM_ZEROINIT,3000h
		     mov allocs,eax
		     
             invoke RtlZeroMemory,addr _BITMAPINFOHEADER,sizeof _BITMAPINFOHEADER
		     lea eax, _BITMAPINFOHEADER
		     mov [eax].BITMAPINFO.bmiHeader.biSize, sizeof BITMAPINFOHEADER
		     mov [eax].BITMAPINFO.bmiHeader.biWidth, 16
		     mov [eax].BITMAPINFO.bmiHeader.biHeight, 16
		     mov [eax].BITMAPINFO.bmiHeader.biPlanes, 1
		     mov [eax].BITMAPINFO.bmiHeader.biBitCount, 32
		     mov [eax].BITMAPINFO.bmiHeader.biCompression, BI_RGB
		     
		     invoke CreateCompatibleDC, NULL
		     mov myDC, eax
		     invoke CreateDIBSection,myDC,addr _BITMAPINFOHEADER,DIB_RGB_COLORS,addr Bits,NULL,NULL
		     mov cDIB, eax
		     invoke SelectObject,myDC, eax
		     mov PrevBmp, eax			     
		     
		     invoke GetDIBits,myDC,_IconBitmapObject,0,16, allocs,addr _BITMAPINFOHEADER,DIB_RGB_COLORS
		     
		     invoke SetDIBits,myDC,cDIB,0,16, allocs,addr _BITMAPINFOHEADER,DIB_RGB_COLORS
		     
		     invoke SelectObject,myDC,PrevBmp
		     mov _IconBitmapObject,eax	

....so this works but only with alpha icons.For other icons nothing gets drawn / visible.Below a picture.First entry used with alpha icon and code above.The second icon is a 256 color bitmap icon used with LoadImage IMAGE_BITMAP flag.Both are shown right.

A4.png.512bb3ecdf6735b7e2c0f35a7c73e30f.png

You see the selected icon is transparent and no menu color is to see when its selected.Also same for second icon which is already a bitmap.Ok,now if I try my code with a not alpha icon then I get nothing....

A5.png.5b3511070846c98c714e9e7edd994e58.png

....the question is how to get it work for not alpha icons?So if I use my code above with a bitmap icon then it works too.I tried to debug the LoadImage function and I see it does the same as my code what means with a real bitmap anyway whether 32 / 24 or lower bits and colors it works....but it dosent work for icons using the ICONINFO.hbmColor handle as bitmap.You know what I mean?Below I have attached new icons I made.All diffrent.3x ico and 3x bmp with and without alpha.Maybe if anyone wants to test with them etc.

NewIconsAsIcoAndBmp.rar

greetz

Share this post


Link to post
LCF-AT

Hi again,

after longer time of working on that ico stuff I did it today and found a method how to change a icon handle into bitmap handle and using it with SetMenuItemBitmaps function and to draw it perfectly transparent without any issues. 😀 The solution was it to use GDI+ functions (never really used before) what does the work already.After while of checking how to use GDI+ functions I did manage it and created a own function code to do the work and it works with all the diffrent ico files I have and also postet above in earlier post.Just great Baby!Special self congrats to me this time hehe.Anyway,I am just really really happy that I got it working now after long time of trying etc.Below my code function so far....

Create HBITMAP Handles from Icon resources
.................................................................................................................
		        invoke CreateHBITMAPfromResICON,hInstance,400,16
		        .if eax != FALSE
		        mov _IconBitmapObject,eax  ; invoke DeleteObject,_IconBitmapObject if no more needed
		        .endif
		        invoke CreateHBITMAPfromResICON,hInstance,401,16
		        .if eax != FALSE
		        mov _IconBitmapObject2,eax  ; invoke DeleteObject,_IconBitmapObject2 if no more needed
		        .endif		        
		        invoke CreateHBITMAPfromResICON,hInstance,402,16
		        .if eax != FALSE
		        mov _IconBitmapObject3,eax  ; invoke DeleteObject,_IconBitmapObject3 if no more needed
		        .endif			        
		        invoke CreateHBITMAPfromResICON,hInstance,200,16
		        .if eax != FALSE
		        mov _IconBitmapObject4,eax  ; invoke DeleteObject,_IconBitmapObject4 if no more needed
		        .endif	
.................................................................................................................
	            invoke SetMenuItemBitmaps,popupmenuhandle,MEN_1, MF_BYCOMMAND, _IconBitmapObject, _IconBitmapObject
	            invoke SetMenuItemBitmaps,popupmenuhandle,MEN_2, MF_BYCOMMAND, _IconBitmapObject2, _IconBitmapObject2
	            invoke SetMenuItemBitmaps,popupmenuhandle,MEN_3, MF_BYCOMMAND, _IconBitmapObject3, _IconBitmapObject3
	            invoke SetMenuItemBitmaps,popupmenuhandle,MEN_4, MF_BYCOMMAND, _IconBitmapObject4, _IconBitmapObject4
.................................................................................................................
CreateHBITMAPfromResICON proc uses edi esi _hInstance:DWORD,_ResID:DWORD,_size:DWORD

local _hicon:DWORD
local _bitmap:DWORD
local _Hbitmap:DWORD
local _graphics:PVOID
local _gsi:GdiplusStartupInput
local _gtkn:PULONG	

	invoke LoadImage,_hInstance,_ResID,IMAGE_ICON,_size, _size,LR_DEFAULTSIZE
	.if eax != FALSE
	    mov _hicon, eax
	    mov _gsi.GdiplusVersion,TRUE
	    mov _gsi.DebugEventCallback,NULL
	    mov _gsi.SuppressBackgroundThread,NULL
	    mov _gsi.SuppressExternalCodecs,NULL
	    invoke GdiplusStartup,ADDR _gtkn,ADDR _gsi,NULL
	    .if eax == NULL ; OK
	        invoke GdipCreateBitmapFromHICON,_hicon,addr _bitmap
	        .if eax == NULL
	            invoke GdipCreateHBITMAPFromBitmap,_bitmap,addr _Hbitmap,NULL
	            .if eax == FALSE
	                invoke GdipDisposeImage,_bitmap
	                invoke GdiplusShutdown,_gtkn
	                invoke DestroyIcon,_hicon
	                mov eax, _Hbitmap
	            .else
	                invoke GdipDisposeImage,_bitmap
	                invoke GdiplusShutdown,_gtkn
	                invoke DestroyIcon,_hicon
	                mov eax, FALSE
	            .endif
	        .else
	            invoke GdiplusShutdown,_gtkn
	            invoke DestroyIcon,_hicon
	            mov eax, FALSE
	        .endif
	    .else
	        invoke DestroyIcon,_hicon
	        mov eax, FALSE
	    .endif
	.else
	    mov eax, FALSE
	.endif
	Ret
CreateHBITMAPfromResICON endp

....and this I got to see now when I select all menu items with the mouse....

B1.png.7be7bf4716087113434f4d42cca17da6.png

B2.png.4ca9eebacc936f0f378ae9127e1bdefa.png

B3.png.68f8ea514c10445804db63ccdaeae73e.png

B4.png.b8a588dbaa3ded2f1716f5b29bf9ea33.png

.....do you see it now?Only the icon itself is visible without any other menu color around (like using with DrawIconEx / see pic from older posts above).All 4 diffrent ico icons / sizes gets handled perfecty like real bitmap icons.Thats it and all what I wanted.Just using normal ico icons without creating and using extra bitmap icons.Doing all directly on fly.So what do you think?Its good so or could my function using GDI make some problems later etc?Just asking so I didnt used GDI+ before.

I found some references about GDI+ functions here...

http://www.jose.it-berater.org/gdiplus/iframe/index.htm

....does anyone know whether there are also some GDI / +  function help file to download?I mean similar like Win32 Programmers Reference or Windows Sockets 2 Application Program Interface with function descriptions you know.Just would like to know which references are all to get and to download for any xy modules.

greetz

  • Like 1

Share this post


Link to post
fearless

Jose Roca's site is the place to go for all GDIPlus stuff, or the MSDN/Microsoft Docs pages.

And the forums on that site for examples:

- GDI: http://www.jose.it-berater.org/smfforum/index.php?board=416.0

- GDI+: http://www.jose.it-berater.org/smfforum/index.php?board=417.0

Also I would suggest doing the GdiplusStartup at the beginning of the program and the GdiplusShutdown as the program is exiting rather than every time inside the function.

Looks pretty good. Glad you got it all working.

  • Like 1

Share this post


Link to post
LCF-AT

Hi fearless,

thanks. :) Yes,thats the only issue that I need to use the init and shutdown functions before.I would better like to have all in one function only instead of making two functions.Will see,maybe I can adapt the 2 / 3 functions code to a new function without to use init / shutdown anymore.At the moment I am just happy that I found a working method and knew it that there was any method I could use for that but it seems that nobody else did know it yet or didnt post it yet.Also just found those API functions by random used in some Auto-It codes and just tried them too.

greetz

Share this post


Link to post
LCF-AT

Hi guys,

I found a new problem with icons.This time its a issue with bitmap icon I do add to ImageList and using them as icons in menus.It seems that the scale of those icons arent working right maybe.I show you a example what I mean.

- I am using one ico icon and same icon as bitmap from resources

- The icon/s having a size of 32x32 and I wanna set them to 16x16

- I wanna use this icon in main dialog and in menu (putting icon to imagelist)

Now  a example code for the ico icon below...remember the original icon has a size of 32x32.

I load it with desired size of 16x16 and put it into imagelist with 16x16.Then calling GetIcon function and sending the handle to dialog with ICON_SMALL flag and into testicon2 what I am using for the menu via DrawIconEx.

		       invoke LoadImage,hInstance,200,IMAGE_ICON,16, 16,LR_DEFAULTSIZE
		       mov edi,eax
		       mov hbitmap,eax ; icon handle
		       invoke ImageList_Create,16,16,ILC_COLOR32 or ILC_MASK ,1, 1
		       mov edi, eax
		       invoke ImageList_AddIcon,edi,hbitmap
		       mov esi, eax
		       invoke ImageList_GetIcon,edi,esi,ILD_NORMAL
		       mov testicon,eax
		       mov testicon2,eax ; <--- icon for menu handle
		       invoke SendMessage,hWnd,WM_SETICON,ICON_SMALL,testicon

The results is correctly and look so....

S1.png.6c3399e799c8701acd5681a6fa5df032.png

...Ok.Good so far.The icon is shown right in dialog & Menu.Now I wanna do the same with the same icon as bitmap version.Below my code for that....

		       invoke LoadImage,hInstance,303,IMAGE_BITMAP,16, 16,LR_DEFAULTSIZE 
		       mov edi, eax
		       mov hbitmap,eax
		       invoke ImageList_Create,16,16,ILC_COLOR32 or ILC_MASK ,1, 1
		       mov edi, eax
		       invoke ImageList_AddMasked,edi,hbitmap,NULL
		       mov esi, eax
		       invoke ImageList_GetIcon,edi,esi,ILD_NORMAL
		       mov testicon,eax
		       mov testicon2,eax
		       invoke SendMessage,hWnd,WM_SETICON,ICON_SMALL,testicon

....code look almost same but I get other results to see.....

S2.png.c6668b39b5eb4d951ec3c6a27519b79e.png

...so like you can see they are looking diffrent now.Somehow edged and not good.Now I tried to change the code to this,loading the icon with original size....

		       invoke LoadImage,hInstance,303,IMAGE_BITMAP,0, 0,LR_DEFAULTSIZE 
		       mov edi, eax
		       mov hbitmap,eax
		       invoke ImageList_Create,32,32,ILC_COLOR32 or ILC_MASK ,1, 1
		       mov edi, eax
		       invoke ImageList_AddMasked,edi,hbitmap,NULL
		       mov esi, eax
		       invoke ImageList_GetIcon,edi,esi,ILD_NORMAL
		       mov testicon,eax
		       mov testicon2,eax
		       invoke SendMessage,hWnd,WM_SETICON,ICON_SMALL,testicon

...result is this.Only the dialog icon is shown correctly....and menu icons edged.

S3.png.3e21ec8c948ce013fb5aa3cb677fbfca.png

So my question is how I can scale the icon handle from Imagelist or the bitmap before I put it into imagelist to 16x16 to get the same results out like you can see in picture one above.

One more thing.If I am calling SendMessage with WM_SETICON with ICON_SMALL or ICON_BIG then the same icon I did take from imagelist is shown right.So why isnt it also working for menu?So what can I do now with those bitmap icons to show them right in menu same as in dialog.Maybe anyone can help with that problem.

Thank you

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  
×
×
  • Create New...