Jump to content

Set menu item icon


rexx
 Share

Recommended Posts

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
Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...