Skitty Posted June 25, 2012 Share Posted June 25, 2012 The topic title is straight up. How does one set the bmp button images to the toolbar and keep the transparency? For example, look at scite, it adds a custom bmp which is the paper with the [x] in the lower right corner and it has full transparency. The below example will use the same image scite does, but fail to be transparent. expandcollapse popup#include <GuiToolbar.au3> #include <GuiImageList.au3> #include <WindowsConstants.au3> #include <Constants.au3> #include <gdiplus.au3> $Debug_TB = False ; Check ClassName being passed to functions, set to True and use a handle to another control to see it work Global $iMemo _Main() Func _Main() Local $hGUI, $hToolbar, $hNormal, $hDisabled, $hHot Local Enum $id1 = 1000, $id2, $id3 ; Create GUI $hGUI = GUICreate("Toolbar", 400, 300) GUISetBkColor(0) $hToolbar = _WinAPI_CreateWindowEx(0, "ToolbarWindow32", "",BitOR($WS_CHILD, $WS_CLIPSIBLINGS, $WS_VISIBLE, $TBSTYLE_TOOLTIPS),0,0,0,0, $hGUI) __GUICtrlToolbar_ButtonStructSize($hToolbar) _SendMessage($hToolbar, $TB_SETSTYLE, 0, 0x54000901) $iMemo = GUICtrlCreateEdit("", 2, 36, 396, 262, $WS_VSCROLL) GUICtrlSetFont($iMemo, 10, 400, 0, "Courier New") GUISetState() Local $CloseBMP = _ImgProcess(Binary("0x424DEE000000000000007600000028000000100000000F00000001000" & _ "4000000000078000000120B0000120B00001000000010000000000000000000800000800000008080008" & _ "00000008000800080800000C0C0C000808080000000FF0000FF000000FFFF00FF000000FF00FF00FFFF0" & _ "000FFFFFF0077777777888888887777777F777777787770000F707770787770FFFF770707787770FFFF7" & _ "77077787770FFFF770707787770FFFF707770787770FFFF777777787770FFFFFFFFFFF77770FFFFFFFFF" & _ "0777770FFFFFFFFF0777770FFFFFF0000777770FFFFFF0F07777770FFFFFF0077777770000000077777")); Binary BMP image for the "File Close" icon ; Create normal image list $hNormal = _GUIImageList_Create(16, 16, 5) _GUIImageList_Add($hNormal, $STD_COPY) _GUIImageList_Add($hNormal, $CloseBMP) _GUIImageList_Add($hNormal, $STD_FIND) Local $hPrevImageList = _GUICtrlToolbar_SetImageList($hToolbar, $hNormal) MemoWrite("Previous Image list handle .: 0x" & Hex($hPrevImageList)) MemoWrite("IsPtr = " & IsPtr($hPrevImageList) & " IsHWnd = " & IsHWnd($hPrevImageList)) _GUICtrlToolbar_AddBitmap($hToolbar, 1, -1, $IDB_STD_SMALL_COLOR) ; Add buttons _GUICtrlToolbar_AddButtonSep($hToolbar) _GUICtrlToolbar_AddButton($hToolbar, $id1, 0 ) _GUICtrlToolbar_AddButtonSep($hToolbar) _GUICtrlToolbar_AddButton($hToolbar, $id2, 1) _GUICtrlToolbar_AddButtonSep($hToolbar) _GUICtrlToolbar_AddButton($hToolbar, $id3, 2) MemoWrite("Normal list handle ...: 0x" & Hex(_GUICtrlToolbar_GetImageList($hToolbar))) ; Loop until user exits Do Until GUIGetMsg() = -3 EndFunc ;==>_Main Func _ImgProcess(Const $bBinary);Merged code by Progandy and Zedna Local $iLen = BinaryLen($bBinary) If $iLen = 0 Then Return SetError(2, 0, 0) Local $hMem = _MemGlobalAlloc($iLen, $GMEM_MOVEABLE) If @error Or Not $hMem Then Return SetError(3, 0, 0) DllStructSetData(DllStructCreate("byte[" & $iLen & "]", _MemGlobalLock($hMem)), 1, $bBinary) If @error Then _MemGlobalUnlock($hMem) _MemGlobalFree($hMem) Return SetError(4, 0, 0) EndIf _MemGlobalUnlock($hMem) _GDIPlus_Startup() Local $aResult = DllCall("ole32.dll", "int", "CreateStreamOnHGlobal", "handle", $hMem, "bool", True, "ptr*", 0) If @error Or $aResult[0] <> 0 Or $aResult[3] = 0 Then Return SetError(5, @error, 0) Local $hImage = DllCall($ghGDIPDll, "uint", "GdipLoadImageFromStream", "ptr", $aResult[3], "int*", 0) Local $error = @error Local $tVARIANT = DllStructCreate("word vt;word r1;word r2;word r3;ptr data; ptr") DllCall("oleaut32.dll", "long", "DispCallFunc", "ptr", $aResult[3], "dword", 8 + 8 * @AutoItX64, "dword", 4, "dword", 23, "dword", 0, "ptr", 0, "ptr", 0, "ptr", DllStructGetPtr($tVARIANT)) If @error Then Return SetError(6, $error, 0) If $hImage[2] = 0 Then Return SetError(7, 0, $hImage[2]) Local $hBitmap = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hImage[2]) _GDIPlus_ImageDispose($hImage[2]) _GDIPlus_Shutdown() Return SetError(0, 0, $hBitmap) EndFunc ;==>_ImgProcess ; Write message to memo Func MemoWrite($sMessage = "") GUICtrlSetData($iMemo, $sMessage & @CRLF, 1) EndFunc ;==>MemoWrite Link to comment Share on other sites More sharing options...
UEZ Posted June 25, 2012 Share Posted June 25, 2012 (edited) I converted your BMP to PNG and it seems to be working: expandcollapse popup#include <GuiToolbar.au3> #include <GuiImageList.au3> #include <WindowsConstants.au3> #include <Constants.au3> #include <gdiplus.au3> $Debug_TB = False ; Check ClassName being passed to functions, set to True and use a handle to another control to see it work Global $iMemo _Main() Func _Main() Local $hGUI, $hToolbar, $hNormal, $hDisabled, $hHot Local Enum $id1 = 1000, $id2, $id3, $id4 ;~ Local $CloseBMP = _ImgProcess(Binary("0x424DEE000000000000007600000028000000100000000F00000001000" & _ ;~ "4000000000078000000120B0000120B00001000000010000000000000000000800000800000008080008" & _ ;~ "00000008000800080800000C0C0C000808080000000FF0000FF000000FFFF00FF000000FF00FF00FFFF0" & _ ;~ "000FFFFFF0077777777888888887777777F777777787770000F707770787770FFFF770707787770FFFF7" & _ ;~ "77077787770FFFF770707787770FFFF707770787770FFFF777777787770FFFFFFFFFFF77770FFFFFFFFF" & _ ;~ "0777770FFFFFFFFF0777770FFFFFF0000777770FFFFFF0F07777770FFFFFF0077777770000000077777")); Binary BMP image for the "File Close" icon Local $CloseBMP = _ImgProcess(Binary("0x89504E470D0A1A0A0000000D49484452000000100000000F0806000000ED734F2F000000097048597300000B1300000B1301009A9C180000008049444154785E9D93610A80200C85F7C2837934BBD93CD98B09239865CD0F4A067BDFDC0F41B981086501AD255024403E3B00589A517248029243B22D0030AD5A12D383C86FB0CFBE80E4F8FD5AA1F72E6F686BFC75835A6BAC732BA8AA87ECB43A0812120F67051EB6732D00E0DF1436A2A47C3C167AC88935286BCED6962D1714C53BA791E5B88A0000000049454E44AE426082")); Binary PNG image for the "File Close" icon ; Create GUI $hGUI = GUICreate("Toolbar", 400, 300) ;~ GUISetBkColor(0) $hToolbar = _GUICtrlToolbar_Create($hGUI, $TBSTYLE_FLAT) _GUICtrlToolbar_SetBitmapSize($hToolbar, 16, 16) _GUICtrlToolbar_AddBitmap($hToolbar, 1, 0, $CloseBMP) _GUICtrlToolbar_AddButton($hToolbar, $id1, 0) _GUICtrlToolbar_AddButtonSep($hToolbar) _GUICtrlToolbar_AddBitmap($hToolbar, 1, -1, $IDB_STD_SMALL_COLOR) _GUICtrlToolbar_AddButton($hToolbar, $id2, 1) _GUICtrlToolbar_AddButtonSep($hToolbar) _GUICtrlToolbar_AddButton($hToolbar, $id3, 2) _GUICtrlToolbar_AddButtonSep($hToolbar) _GUICtrlToolbar_AddButton($hToolbar, $id4, 3) $iMemo = GUICtrlCreateEdit("", 2, 36, 396, 262, $WS_VSCROLL) GUICtrlSetFont($iMemo, 10, 400, 0, "Courier New") GUISetState() ; Loop until user exits Do Until GUIGetMsg() = -3 EndFunc ;==>_Main Func _ImgProcess(Const $bBinary);Merged code by Progandy and Zedna Local $iLen = BinaryLen($bBinary) If $iLen = 0 Then Return SetError(2, 0, 0) Local $hMem = _MemGlobalAlloc($iLen, $GMEM_MOVEABLE) If @error Or Not $hMem Then Return SetError(3, 0, 0) DllStructSetData(DllStructCreate("byte[" & $iLen & "]", _MemGlobalLock($hMem)), 1, $bBinary) If @error Then _MemGlobalUnlock($hMem) _MemGlobalFree($hMem) Return SetError(4, 0, 0) EndIf _MemGlobalUnlock($hMem) _GDIPlus_Startup() Local $aResult = DllCall("ole32.dll", "int", "CreateStreamOnHGlobal", "handle", $hMem, "bool", True, "ptr*", 0) If @error Or $aResult[0] <> 0 Or $aResult[3] = 0 Then Return SetError(5, @error, 0) Local $hImage = DllCall($ghGDIPDll, "uint", "GdipLoadImageFromStream", "ptr", $aResult[3], "int*", 0) Local $error = @error Local $tVARIANT = DllStructCreate("word vt;word r1;word r2;word r3;ptr data; ptr") DllCall("oleaut32.dll", "long", "DispCallFunc", "ptr", $aResult[3], "dword", 8 + 8 * @AutoItX64, "dword", 4, "dword", 23, "dword", 0, "ptr", 0, "ptr", 0, "ptr", DllStructGetPtr($tVARIANT)) If @error Then Return SetError(6, $error, 0) If $hImage[2] = 0 Then Return SetError(7, 0, $hImage[2]) Local $hBitmap = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hImage[2]) _GDIPlus_ImageDispose($hImage[2]) _GDIPlus_Shutdown() Return SetError(0, 0, $hBitmap) EndFunc ;==>_ImgProcess ; Write message to memo Func MemoWrite($sMessage = "") GUICtrlSetData($iMemo, $sMessage & @CRLF, 1) EndFunc ;==>MemoWrite Br, UEZ Edited June 25, 2012 by UEZ Skitty 1 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 More sharing options...
AZJIO Posted June 25, 2012 Share Posted June 25, 2012 _GUIImageList_Create + _GUIImageList_AddIconexample Skitty and mvk25 2 My other projects or all Link to comment Share on other sites More sharing options...
Skitty Posted June 25, 2012 Author Share Posted June 25, 2012 (edited) I converted your BMP to PNG and it seems to be working: ~~ Br, UEZ Incredible, when posting this thread, I had a feeling the answer was within you. Thanks UEZ! I searched and searched, I don't know why the hell I didn't think about just using a png.... And I'm curious (for compatability reasons), why did you remove the method I used to create the toolbar? I used that method because it is the only way I could set that particular style for the toolbar where the background color is a sort of bone white. That and by just setting the flat style after its creation, creating it with the style initially does not work as I have found. Edit: Setting it any other ways seems to make the separator buttons invisible... This is exactly the effect I was after. expandcollapse popup#include <GuiToolbar.au3> #include <GuiImageList.au3> #include <WindowsConstants.au3> #include <Constants.au3> #include <gdiplus.au3> $Debug_TB = False ; Check ClassName being passed to functions, set to True and use a handle to another control to see it work Global $iMemo _Main() Func _Main() Local $hGUI, $hToolbar, $hNormal, $hDisabled, $hHot Local Enum $id1 = 1000, $id2, $id3, $id4 Local $CloseBMP = _ImgProcess(Binary("0x89504E470D0A1A0A0000000D49484452000000100000000F0803000000DAADBF1D0000001974455874536F6674776172650041646F626520496D616765526561647971C9653C0000000C504C5445000000808080FFFFFFFFFFFF788A14520000000474524E53FFFFFF00402AA9F4000000454944415478DA848DD10A0020080397FBFF7FAEA9A006D13D081E6303492414BA30274C17863BA14C13725F615682C12A11134D9C0F23117D8FC4617488B1E262255B800100EE9901EEBBDA13030000000049454E44AE426082")); Binary PNG image for the "File Close" icon ; Create GUI $hGUI = GUICreate("Toolbar", 400, 300) ;Create bone whiteish color and allow seperators to be visible ;~ $hToolbar = _WinAPI_CreateWindowEx(0, "ToolbarWindow32", "",BitOR($WS_CHILD, $WS_CLIPSIBLINGS, $WS_VISIBLE, $TBSTYLE_TOOLTIPS),0,0,0,0, $hGUI) ;~ __GUICtrlToolbar_ButtonStructSize($hToolbar) ;~ _SendMessage($hToolbar, $TB_SETSTYLE, 0, 0x54000901) ;Same thing as above but more behind the scene script operations... $hToolbar = _GUICtrlToolbar_Create($hGUI, $TBSTYLE_TOOLTIPS) _GUICtrlToolbar_SetStyleFlat($hToolbar,1) ;~ $hToolbar = _GUICtrlToolbar_Create($hGUI, $TBSTYLE_TOOLTIPS+$TBSTYLE_FLAT); creating it this way doesn't work (win xp), that is why I use either of above methods _GUICtrlToolbar_SetBitmapSize($hToolbar, 16, 16) _GUICtrlToolbar_AddBitmap($hToolbar, 1, 0, $CloseBMP) _GUICtrlToolbar_AddButton($hToolbar, $id1, 0) _GUICtrlToolbar_AddButtonSep($hToolbar) _GUICtrlToolbar_AddBitmap($hToolbar, 1, -1, $IDB_STD_SMALL_COLOR) _GUICtrlToolbar_AddButton($hToolbar, $id2, 1) _GUICtrlToolbar_AddButtonSep($hToolbar) _GUICtrlToolbar_AddButton($hToolbar, $id3, 2) _GUICtrlToolbar_AddButtonSep($hToolbar) _GUICtrlToolbar_AddButton($hToolbar, $id4, 3) $iMemo = GUICtrlCreateEdit("", 2, 36, 396, 262, $WS_VSCROLL) GUICtrlSetFont($iMemo, 10, 400, 0, "Courier New") GUISetState() ; Loop until user exits Do Until GUIGetMsg() = -3 EndFunc ;==>_Main Func _ImgProcess(Const $bBinary);Merged code by Progandy and Zedna Local $iLen = BinaryLen($bBinary) If $iLen = 0 Then Return SetError(2, 0, 0) Local $hMem = _MemGlobalAlloc($iLen, $GMEM_MOVEABLE) If @error Or Not $hMem Then Return SetError(3, 0, 0) DllStructSetData(DllStructCreate("byte[" & $iLen & "]", _MemGlobalLock($hMem)), 1, $bBinary) If @error Then _MemGlobalUnlock($hMem) _MemGlobalFree($hMem) Return SetError(4, 0, 0) EndIf _MemGlobalUnlock($hMem) _GDIPlus_Startup() Local $aResult = DllCall("ole32.dll", "int", "CreateStreamOnHGlobal", "handle", $hMem, "bool", True, "ptr*", 0) If @error Or $aResult[0] <> 0 Or $aResult[3] = 0 Then Return SetError(5, @error, 0) Local $hImage = DllCall($ghGDIPDll, "uint", "GdipLoadImageFromStream", "ptr", $aResult[3], "int*", 0) Local $error = @error Local $tVARIANT = DllStructCreate("word vt;word r1;word r2;word r3;ptr data; ptr") DllCall("oleaut32.dll", "long", "DispCallFunc", "ptr", $aResult[3], "dword", 8 + 8 * @AutoItX64, "dword", 4, "dword", 23, "dword", 0, "ptr", 0, "ptr", 0, "ptr", DllStructGetPtr($tVARIANT)) If @error Then Return SetError(6, $error, 0) If $hImage[2] = 0 Then Return SetError(7, 0, $hImage[2]) Local $hBitmap = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hImage[2]) _GDIPlus_ImageDispose($hImage[2]) _GDIPlus_Shutdown() Return SetError(0, 0, $hBitmap) EndFunc ;==>_ImgProcess ; Write message to memo Func MemoWrite($sMessage = "") GUICtrlSetData($iMemo, $sMessage & @CRLF, 1) EndFunc ;==>MemoWrite Edited June 26, 2012 by ApudAngelorum Link to comment Share on other sites More sharing options...
UEZ Posted June 26, 2012 Share Posted June 26, 2012 I wasn't aware of what you have tried to achieve and I minimized the code for better understanding. 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 More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now