Jump to content
Sign in to follow this  
rexx

Set menu item icon

Recommended Posts

rexx

I have search the udf document and found _GUICtrlMenu_SetItemBmp()

But it needs a bitmap handle.

So I use GDI+ to load a image from file and create the bitmap handle.

_GDIPlus_Startup()
    $hImage = _GDIPlus_ImageLoadFromFile($sIconFile)
    $hBitmap = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hImage)
    _GDIPlus_ImageDispose($hImage)
;   _WinAPI_DeleteObject($hBitmap)
    _GDIPlus_ShutDown()

This works but I want to know if there's another way to create bitmap handle from a file without using the GDI+ lib.

I found this but he didn't give the works one.

Another question, I use _WinAPI_PrivateExtractIcon() to get icon from executables, but it returns icon handle.

How can I convert it to bitmap handle so that I can use it in _GUICtrlMenu_SetItemBmp()

I tried _WinAPI_GetIconInfo($hIcon) and uses "$aIcon[5] - Handle to the icon color bitmap", but I got a black square.

Thanks.

Edited by rexx

Share this post


Link to post
Share on other sites
Emiel Wieldraaijer

Search for ModernMenu


Best regards,Emiel Wieldraaijer

Share this post


Link to post
Share on other sites
oMBRa

try this:

Func _GdipCreateBitmapFromHICON($hIcon)
    Local $sBitmap
    $sBitmap = DllStructCreate('dword')
    $hBitmap = DllCall('gdiplus.dll', 'dword', 'GdipCreateBitmapFromHICON', 'hwnd', $hIcon, 'ptr', DllStructGetPtr($sBitmap))
    Return SetError(0, 0, DllStructGetData($sBitmap, 1))
EndFunc  ;==>_GdipCreateBitmapFromHICON

this converts an icon handle to a bitmap object, to create an handle to the bitmap you could use _GDIPlus_BitmapCreateHBITMAPFromBitmap

Share this post


Link to post
Share on other sites
rexx

Search for ModernMenu

Thanks.

I know this, but i dont want the menu style.

But maybe there will be something helpful.

I'll look it again.

try this:

Func _GdipCreateBitmapFromHICON($hIcon)
    Local $sBitmap
    $sBitmap = DllStructCreate('dword')
    $hBitmap = DllCall('gdiplus.dll', 'dword', 'GdipCreateBitmapFromHICON', 'hwnd', $hIcon, 'ptr', DllStructGetPtr($sBitmap))
    Return SetError(0, 0, DllStructGetData($sBitmap, 1))
EndFunc ;==>_GdipCreateBitmapFromHICON

this converts an icon handle to a bitmap object, to create an handle to the bitmap you could use _GDIPlus_BitmapCreateHBITMAPFromBitmap

Thanks, this works!

But the transparency seems not working. :D

Share this post


Link to post
Share on other sites
Emiel Wieldraaijer

Could you explain a bit more

Why does ModernMenu not work ?

You can add the icons to the exe and use them


Best regards,Emiel Wieldraaijer

Share this post


Link to post
Share on other sites
rexx

Could you explain a bit more

Why does ModernMenu not work ?

You can add the icons to the exe and use them

I didn't say it doesn't work.

I just don't like the style, I want a simply vista style icon.

Share this post


Link to post
Share on other sites

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  

×