Jump to content

[SOLVED] _GUICtrlMenu_SetItemBmp


Recommended Posts

Lets see how dumb I feel after I get replies.

$icon1 = FileOpen( @ScriptDir & "\" & "icon1.png" )

_GUICtrlMenu_SetItemBmp( $h_control_menu, 2, $icon1 )

Gives the control an icon, but it's one of those system-default "missing-icon" icons.

Icon1.png is inside the same directory.

bmp, ico, various other formats didn't work, and all I found in the help file for adding an image was:

_WinAPI_CreateSolidBitmap

I'm not sure what format to use, or maybe I'm just missing something.

Edited by caleb41610
Link to comment
Share on other sites

Hi,

You need a bitmap handle, not the bitmap binary for the 3rd parameter of the function _GUICtrlMenu_SetItemBmp

Here you go :

#include <GDIPlus.au3>
...

Global $hDC, $hCDC, $hBmp, $hGraphic, $hImage

_GDIPlus_Startup()

$hDC = _WinAPI_GetDC($hGUI)
$hCDC = _WinAPI_CreateCompatibleDC($hDC)
$hBmp = _WinAPI_CreateCompatibleBitmap($hDC, 11, 11)
_WinAPI_SelectObject($hCDC, $hBmp)
$hGraphic = _GDIPlus_GraphicsCreateFromHDC($hCDC)

$hImage = _GDIPlus_BitmapCreateFromFile("toto.bmp")
_GDIPlus_GraphicsDrawImageRect($hGraphic, $hImage, 0, 0, 11, 11)

_GDIPlus_ImageDispose($hImage)
_GDIPlus_GraphicsDispose($hGraphic)
_WinAPI_ReleaseDC($hGUI, $hDC)
_WinAPI_DeleteDC($hCDC)

_GDIPlus_Shutdown()

_GUICtrlMenu_SetItemBmp($h_control_menu, 2, $hBmp)
...

Br, FireFox.

Link to comment
Share on other sites

I have it working, but there is one last problem. Transparency is black.

Win7 x64

Any ways to change that?

Here's a snippet from my script.

$bmp_server_binary = "0xFFD8FFE000104A46494600010101006000600000FFDB004300080606070605080707070909080A0C140D0C0B0B0C1912130F141D1A1F1E1D1A1C1C20242E2720222C231C1C2837292C30" & _
"313434341F27393D38323C2E333432FFDB0043010909090C0B0C180D0D1832211C213232323232323232323232323232323232323232323232323232323232323232323232323232323232323232323232323232FFC" & _
"00011080020002003012200021101031101FFC4001F0000010501010101010100000000000000000102030405060708090A0BFFC400B5100002010303020403050504040000017D0102030004110512213141061351" & _
"6107227114328191A1082342B1C11552D1F02433627282090A161718191A25262728292A3435363738393A434445464748494A535455565758595A636465666768696A737475767778797A838485868788898A92939" & _
"495969798999AA2A3A4A5A6A7A8A9AAB2B3B4B5B6B7B8B9BAC2C3C4C5C6C7C8C9CAD2D3D4D5D6D7D8D9DAE1E2E3E4E5E6E7E8E9EAF1F2F3F4F5F6F7F8F9FAFFC4001F01000301010101010101010100000000000001" & _
"02030405060708090A0BFFC400B51100020102040403040705040400010277000102031104052131061241510761711322328108144291A1B1C109233352F0156272D10A162434E125F11718191A262728292A35363" & _
"738393A434445464748494A535455565758595A636465666768696A737475767778797A82838485868788898A92939495969798999AA2A3A4A5A6A7A8A9AAB2B3B4B5B6B7B8B9BAC2C3C4C5C6C7C8C9CAD2D3D4D5D6" & _
"D7D8D9DAE2E3E4E5E6E7E8E9EAF2F3F4F5F6F7F8F9FAFFDA000C03010002110311003F00E1F49F85506A1A2586A375E2BD3AC1AF2112AC37002900FD5866B417E0CD8BF4F1E68BF9AFFF0017497F722DF41F0A9288F" & _
"9D280C38C8E49E7EB55A1BB51F7781D8139A00B4DF066C53AF8F345FCD7FF008BACFD5FE155BE9FA26A1A8DAF8AF4ED41ACE132B436E031201F50C71F954971760A9E6A4D22E165D07C58A0E71A637FE84280337C4B" & _
"79E4E87E1451D7FB317FF4235891EA6F8FBD8ADB3A9783757D17488B57BAD521BAB1B51015B745DA7049CF20D4421F8763FE627AF7FDF09FFC450063CB7E5872C4FE35B3E199CC9A2F8A867FE618DFFA10A430FC3B3" & _
"FF313D7BFEF84FF00E22A51A9783748D17578B48BAD526BABEB53005B845DA3241EC05007FFD9"
$h_server_img = Load_BMP_From_Mem( $bmp_server_binary, True )
_GUICtrlMenu_SetItemBmp( $h_control_menu, 0, $h_server_img )


Func Load_BMP_From_Mem($mem_image, $hHBITMAP = False) ;coded by UEZ - thanks to progandy for the MemGlobalAlloc and tVARIANT lines
    Local $memBitmap, $len, $tMem, $hImage, $hData, $pData, $hBitmap, $aStream, $tVARIANT, $aCall, $hHBmp
    $memBitmap = Binary($mem_image) ;load image  saved in variable (memory) and convert it to binary
    $len = BinaryLen($memBitmap) ;get length of image
    $hData = _MemGlobalAlloc($len, $GMEM_MOVEABLE) ;allocates movable memory  ($GMEM_MOVEABLE = 0x0002)
    $pData = _MemGlobalLock($hData) ;translate the handle into a pointer
    $tMem = DllStructCreate("byte[" & $len & "]", $pData) ;create struct
    DllStructSetData($tMem, 1, $memBitmap) ;fill struct with image data
    _MemGlobalUnlock($hData) ;decrements the lock count  associated with a memory object that was allocated with GMEM_MOVEABLE
    $aStream = DllCall("ole32.dll", "int", "CreateStreamOnHGlobal", "handle", $pData, "int", True, "ptr*", 0)
    $hBitmap = DllCall($ghGDIPDll, "uint", "GdipCreateBitmapFromStream", "ptr", $aStream[3], "int*", 0) ;Creates a Bitmap object based on an IStream COM interface
    $hBitmap = $hBitmap[2]
    $tVARIANT = DllStructCreate("word vt;word r1;word r2;word r3;ptr data; ptr")
    $aCall = DllCall("oleaut32.dll", "long", "DispCallFunc", "ptr", $aStream[3], "dword", 8 + 8 * @AutoItX64, _
            "dword", 4, "dword", 23, "dword", 0, "ptr", 0, "ptr", 0, "ptr", DllStructGetPtr($tVARIANT)) ;release memory from $hStream to avoid memory leak
    $tMem = 0
    If $hHBITMAP Then
        $hHBmp = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hBitmap)
        _GDIPlus_BitmapDispose($hBitmap)
        Return $hHBmp
    EndIf
    Return $hBitmap
EndFunc   ;==>Load_BMP_From_Mem
Link to comment
Share on other sites

Try the code from here: http://www.autoit.de/index.php?page=Thread&threadID=21001

Br,

UEZ

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Link to comment
Share on other sites

I will modify the UDF and inform you when it's done (be patient because today and tomorrow I'm working on a file migration for a customer!).

Br,

UEZ

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Link to comment
Share on other sites

Ok, I found some time and modified it! Have a look to _GUICtrlMenu_CreateBitmap Example 2.au3 on German AutoIt site!

You must also download _GUICtrlMenu_CreateBitmap.au3 otherwise display binary image from memory will not work!

If you find some bugs please report it! :)

Br,

UEZ

Edited by UEZ

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Link to comment
Share on other sites

Ok, I found some time and modified it! Have a look to _GUICtrlMenu_CreateBitmap Example 2.au3 on German AutoIt site!

You must also download _GUICtrlMenu_CreateBitmap.au3 otherwise display binary image from memory will not work!

If you find some bugs please report it! :)

Br,

UEZ

The image doesn't seem to show up in the menu

Link to comment
Share on other sites

You mean the embedded image in example 2? It should be the 1st icon for New (torus).

Br,

UEZ

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

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...