Results 1 to 3 of 3

Thread: how to use alpha png for buttons,Transparent toolbar Control by vb6

  1. #1

    Thread Starter
    PowerPoster
    Join Date
    Jan 2020
    Posts
    3,746

    how to use alpha png for buttons,Transparent toolbar Control by vb6

    it's use ImageList1.MaskColor ,how to use alpha png for buttons ?or use api without imagelist control ?

    [VB6] ListView / TreeView Extended and Custom Checkboxes-VBForums
    https://www.vbforums.com/showthread....tom-Checkboxes


    Code:
    Private Declare Function SetClassLong Lib "user32" Alias "SetClassLongA" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwnewlong As Long) As Long
    Private Declare Function OleTranslateColor Lib "oleaut32.dll" (ByVal lOleColor As Long, ByVal lHPalette As Long, ByRef lColorRef As Long) As Long
    Private Declare Function CreateSolidBrush Lib "gdi32.dll" (ByVal crColor As Long) As Long
    Private Declare Function DeleteObject Lib "gdi32.dll" (ByVal hObject As Long) As Long
    Private Declare Function CreatePatternBrush Lib "gdi32.dll" (ByVal hBitmap As Long) As Long
    Private Declare Function InvalidateRect Lib "user32" (ByVal hwnd As Long, lpRect As Long, ByVal bErase As Long) As Long
    
    Private Const GCL_HBRBACKGROUND As Long = -10
    
    Private Function GDI_TranslateColor(OleClr As OLE_COLOR, Optional hPal As Integer = 0) As Long
        ' used to return the correct color value of OleClr as a long
        If OleTranslateColor(OleClr, hPal, GDI_TranslateColor) Then
            GDI_TranslateColor = &HFFFF&
        End If
    End Function
    
    Function GDI_CreateSoildBrush(bColor As OLE_COLOR) As Long
        'Create a Brush form a picture handle
        GDI_CreateSoildBrush = CreateSolidBrush(GDI_TranslateColor(bColor))
    End Function
    
    Public Sub SetToolbarBG(hwnd As Long, hBmp As Long)
        'Set the toolbars background image
        DeleteObject SetClassLong(hwnd, GCL_HBRBACKGROUND, CreatePatternBrush(hBmp))
        InvalidateRect 0&, 0&, False
    End Sub
    
    Public Sub SetToolbarBK(hwnd As Long, hColor As OLE_COLOR)
        ' Set a toolbars Backcolor
        DeleteObject SetClassLong(hwnd, GCL_HBRBACKGROUND, GDI_CreateSoildBrush(hColor))
        InvalidateRect 0&, 0&, False
    End Sub
    
    Private Sub cmdBk_Click()
        Call SetToolbarBK(Toolbar1.hwnd, vbYellow)
    End Sub
    
    Private Sub Command1_Click()
        SetToolbarBG Toolbar1.hwnd, Image1.Picture
    End Sub
    Attached Images Attached Images  
    Last edited by xiaoyao; Apr 10th, 2021 at 06:38 AM.

  2. #2

    Thread Starter
    PowerPoster
    Join Date
    Jan 2020
    Posts
    3,746

    Re: how to use alpha png for buttons,Transparent toolbar Control by vb6

    winapi - How to create an imagelist from a PNG? - Stack Overflow
    https://stackoverflow.com/questions/...ist-from-a-png

    vcl-styles-utils/PngImageList.pas at master · RRUZ/vcl-styles-utils
    https://github.com/RRUZ/vcl-styles-u...gImageList.pas

    Icon.FromHandle + ImageList = decreased color depth
    https://microsoft.public.dotnet.fram...ed-color-depth
    IIcon icon = IconFromExtension(extension, SHGFI_SMALLICON);
    _imageList.Images.Add(extension, icon);

    Everything works, except that icons look ugly. It seems that
    color depth is decreased and alpha blending is not applied
    at all. Here's screenshot fragment to illustrate the
    problem:

    Adding bitmaps with semi-transparency to imagelist - Ask for Help - AutoHotkey Community
    https://autohotkey.com/board/topic/7...-to-imagelist/


    pBitmapIn := Gdip_CreateBitmapFromFile("axmb_logo.png")

    Gdip_GetDimensions(pBitmapIn, Width1, Height1)


    hBitmap:=Gdip_CreateHBITMAPFromBitmap(pBitmapIn)
    ; hBitmap:=Gdip_CreateHBITMAPFromBitmap(pBitmapIn, 0xa2a2a2a2) ; change the color tint


    ILC_COLOR := 0x20 ; This flag is required as we are about to store 32bit Bitmaps
    InitCount := 1 ; Initial count of images.


    hIL := DllCall( "ImageList_Create", Int,Width1, Int,Height1, UInt,ILC_COLOR, Int,InitCount, Int,1 )

    ;
    img:=ImageList_Add(hIL, hBitmap)

    PngComponents 1.1 Full Source D2009-DXE8 » Delphi .Net : Best Choice for Developer
    https://delphidotnet.com/delphi/848-...2009-dxe8.html
    Last edited by xiaoyao; Apr 9th, 2021 at 08:04 AM.

  3. #3

    Thread Starter
    PowerPoster
    Join Date
    Jan 2020
    Posts
    3,746

    Re: how to use alpha png for buttons,Transparent toolbar Control by vb6

    https://www.coder.work/article/3244021
    ImageList with PNG/Alpha channel images
    Original tag c++ windows listview mfc imagelist

    I have never figured out how to create an ImageList control using a PNG file with an alpha channel. I want to use it as a small image in a ListView control.

    I have been trying for a few hours, and the descriptions of what I have tried seem to be too numerous to list. I have searched the Internet, but I haven't found anything.

    Most of the operations I have tried will only cause the listview to appear without any images.

    Then, I tried to import the following files as resources into my project.
    Best answer

    As suggested by xMRi, I can do this by saving the PNG image as a 32-bit/alpha channel BMP file.

    There are some restrictions on the support of loaded resources. For example, CBitmap::GetBitmapDimensionreturn an empty rectangle. Moreover, there is no support for Alpha channel and high-quality bitmaps in Visual Studio.

    However, if I hard-code the image size, it does work. When the item is selected, my ListView control correctly highlights the image, but not the transparent area. Therefore, the Alpha channel can be correctly identified.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width