Jump to content

[Solved] Add png Image to TabItem


Recommended Posts

Hi.

I want change tab image and for do this, i found this example that work very well but it don't work on .png files.

#include <GUIConstantsEx.au3>
#include <GuiImageList.au3>
#include <GuiTab.au3>
#include <WinAPI.au3>
#include <GDIPlus.au3>

Example()

Func Example()
    _GDIPlus_Startup()

    Local $hGUI = GUICreate("Tab Control Set Item Image", 400, 300)
    Local $idTab = GUICtrlCreateTab(2, 2, 396, 296)
    Local $hImageList = _GUIImageList_Create(50, 20)
    Local $aImages[4]
    
    For $i = 0 To 3
        ; Load the GDI+ bitmap
        Local $hBitmapTmp = _GDIPlus_BitmapCreateFromFile("Tab" & $i & ".jpg")
        ; Conver the GDI+ bitmap to a HBitmap
        $aImages[$i] = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hBitmapTmp)
        ; Get rid of the GDI+ bitmap
        _GDIPlus_BitmapDispose($hBitmapTmp)
        ; Add the HBitmap to the image list
        _GUIImageList_Add($hImageList, $aImages[$i])
    Next
    
    _GUICtrlTab_SetImageList($idTab, $hImageList)
    For $i = 0 To 3
        _GUICtrlTab_InsertItem($idTab, $i, "")
        _GUICtrlTab_SetItemImage($idTab, $i, $i)
    Next

    GUISetState(@SW_SHOW)

    Do
    Until GUIGetMsg() = $GUI_EVENT_CLOSE
    GUIDelete()
    
    ; Dispose of the HBitmap objects properly
    For $i = 0 To 3
        _WinAPI_DeleteObject($aImages[$i])
    Next
EndFunc   ;==>Example

https://www.autoitscript.com/forum/topic/185596-adding-images-to-tab/

I have seen some expamle for add png image to GUI and Button, but them won't work for TabItem.

dose anyone know how can use .png file?

Edited by behdadsoft
Link to comment
Share on other sites

  • Moderators

behdadsoft,

Please do not bump your own threads within 24 hours.

Remember this is not a 24/7 support forum - those who answer are only here because they like helping others and have some time to spare.  You just have to wait until someone who knows something about your particular problem, and is willing to help, comes online.  Be patient and someone will answer eventually.

M23

 

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

4 hours ago, behdadsoft said:

any idea?

Yes just change a little and your linked example works:

#include <GUIConstantsEx.au3>
    #include <GuiImageList.au3>
    #include <GuiTab.au3>
    #include <WinAPI.au3>
    #include <GDIPlus.au3>

    Example()

    Func Example()
        _GDIPlus_Startup()

        Local $hGUI = GUICreate("Tab Control Set Item Image", 400, 300)
        Local $idTab = _GUICtrlTab_Create($hGUI, 2, 2, 396, 296, BitOR($TCS_FORCEICONLEFT, $TCS_FIXEDWIDTH))
        Local $hImageList = _GUIImageList_Create(20, 20)    ;don't change size of images 
        Local $aImages[4]
        Local $sAutoItPath = StringReplace(StringReplace(@AutoItExe, '_x64', ''), 'autoit3.exe', '')
        For $i = 0 To 2
            ; Load the GDI+ bitmap
            $sPNG_Path = $sAutoItPath & "Include\autoit-winhttp-1.6.3.8\Images\fwd" & $i & ".png"
            Local $hBitmapTmp = _GDIPlus_BitmapCreateFromFile($sPNG_Path)
            ConsoleWrite($sPNG_Path & ':' & @TAB & $hBitmapTmp & @TAB & @error & @CRLF)
            ; Conver the GDI+ bitmap to a HBitmap
            $aImages[$i] = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hBitmapTmp)
            ; Get rid of the GDI+ bitmap
            _GDIPlus_BitmapDispose($hBitmapTmp)
            ; Add the HBitmap to the image list
            _GUIImageList_Add($hImageList, $aImages[$i])
        Next

        _GUICtrlTab_SetImageList($idTab, $hImageList)
        For $i = 0 To 2
            _GUICtrlTab_InsertItem($idTab, $i, $i)
            _GUICtrlTab_SetItemImage($idTab, $i, $i)
        Next

        GUISetState(@SW_SHOW)

        Do
        Until GUIGetMsg() = $GUI_EVENT_CLOSE
        GUIDelete()

        ; Dispose of the HBitmap objects properly
        For $i = 0 To 3
            _WinAPI_DeleteObject($aImages[$i])
        Next
    EndFunc   ;==>Example

 

Edited by AutoBert
Link to comment
Share on other sites

My script works:

5b1ad395a3ef3_112_TabControlSetItemImage.jpg.292c0038ff0135e23cf830fdc7537b50.jpg

Original is #2 in your link, that the images have a white background is a behaviour of the control.

Important: all sizes of the images*.png and the size in the Imagelist must the same. Also the Style attributes: BitOR($TCS_FORCEICONLEFT, $TCS_FIXEDWIDTH) by creating the Tabcontrol are helpfull, maybe there's a better combination.

 

 

Link to comment
Share on other sites

Quote

Important: all sizes of the images*.png and the size in the Imagelist must the same

Yes, They are.

This code don't work correctly because In your image, you have white background under square arrows. png image should be completely transparent.

 

5b1ad395a3ef3_112_TabControlSetItemImage.jpg.292c0038ff0135e23cf830fdc7537b50.jpg

Edited by behdadsoft
Link to comment
Share on other sites

17 hours ago, behdadsoft said:

This code don't work correctly because In your image, you have white background under square arrows. png image should be completely transparent.

My used images are transparent but as already sayed:

 

17 hours ago, AutoBert said:

that the images have a white background is a behaviour of the control.

Sorry for miss understanding

On 7.6.2018 at 11:22 PM, behdadsoft said:

I have seen some expamle for add png image to GUI and Button, but them won't work for TabItem.

But you can test:

in OwnTab.au3 (the UDF) you must change #19: from:

Opt("OnExitFunc", "_OwnTab_OnExit")

to

OnAutoItExitRegister("_OwnTab_OnExit")

and in #483 $ghGDIPDll must no named $__g_hGDIPDll.

Link to comment
Share on other sites

5 hours ago, behdadsoft said:

I have seen OwnTab.au3 before, but thanks for fix errors.

The errors are the result of script breaking changes. In 2009, as @funkey has createted the script, the script runs.

5 hours ago, behdadsoft said:

Unfortunately, it only work with icon and not image. :(

I haven't tried but i think when you uses a tool which creates a DLL and pack there your png-files (renamed to .ico?) owntab will work.

Link to comment
Share on other sites

Quote

I haven't tried but i think when you uses a tool which creates a DLL and pack there your png-files (renamed to .ico?) owntab will work.

Incidentally, I also thought that I would put my files in an dll file.
But, I have to test this.

And thanks for tried to help me.:)

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