Sign in to follow this  
Followers 0
SkellySoul

Transparent Tree View

15 posts in this topic

Hello ;)

This request has actually been requested quite a few times on the Autoit forums but I have never seen a example script as close as this one and I couldn't of have done it without the help of Melba23 and Tvern

So here is the example that I have put together with both of the scripts that Melba23 and Tvern provided me with

#include <WINAPI.au3>
#Include <GUITreeView.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <TreeViewConstants.au3>

Global $Tree_Flag = False, $iTransColor = 0x01010101 ;experiment to get the best look

$GUI_Parent = GUICreate("Test", 800, 500)
GUICtrlCreatePic(@DesktopDir & "\test.jpg", 0, 0, 800, 500)

$GUI_Child = GUICreate("", 300, 200, 10, 10, $WS_POPUP, BitOR($WS_EX_LAYERED, $WS_EX_MDICHILD), $GUI_Parent)
$Tree = GUICtrlCreateTreeView(0,0,300,200,BitOR($TVS_HASBUTTONS, $TVS_LINESATROOT, $TVS_DISABLEDRAGDROP, $TVS_SHOWSELALWAYS))
$Tree_Handle = GUICtrlGetHandle($Tree)
GUICtrlSetBkColor($Tree , $iTransColor)
_WinAPI_SetLayeredWindowAttributes($GUI_Child, $iTransColor, 255)
GUISetState(@SW_SHOW , $GUI_Child)
GUISwitch($GUI_Parent)

For $iParent = 0 To 4
    $Tree_Parent = GUICtrlCreateTreeViewItem($iParent,$Tree)
    For $iChild = 0 To 4
        $Tree_Child = GUICtrlCreateTreeViewItem($iParent & "." & $iChild,$Tree_Parent)
        For $iChild2 = 0 To 4
            GUICtrlCreateTreeViewItem($iParent & "." & $iChild & "." & $iChild2,$Tree_Child)
        Next
    Next
Next

GUISetState(@SW_SHOW)

GUIRegisterMsg($WM_NOTIFY, "_Tree_Info")

While 1
    $Msg = GUIGetMsg()
    Switch $Msg
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch
    If $Tree_Flag  Then
        $Tree_Flag = False
        ConsoleWrite(_GUICtrlTreeView_GetText($Tree, _GUICtrlTreeView_GetSelection($Tree)) & @CRLF)
        WinSetTitle($GUI_Parent, $GUI_Parent, "You clicked on: " & _GUICtrlTreeView_GetText($Tree, _GUICtrlTreeView_GetSelection($Tree)))
    EndIf
WEnd

Func _Tree_Info($hWnd, $iMsg, $wParam, $lParam)
    #forceref $hWnd, $iMsg, $wParam
    Local $tNMHDR = DllStructCreate($tagNMHDR, $lParam)
    $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom"))
    $iCode = DllStructGetData($tNMHDR, "Code")
    Switch $hWndFrom
        Case $Tree_Handle
            Switch $iCode
                Case $NM_CLICK
                    $Tree_Flag = True
                    Return 0
            EndSwitch
    EndSwitch
EndFunc

The main problem I have with this script is: Clicking only works on the parts of the treeview that are still visible, making it hard to click an item. (you have to click the actual text of each item)

This is just an example. It has a number of issues:

- Clicking only works on the parts of the treeview that are still visible, making it hard to click an item. (you have to click the actual text of each item)

- The fonts are smoothed against $iTransColor, meaning that, you can either choose a color that results in a pixelated look, or have a trace of the used color around the letters. (experiment untill satisfied)

- I havn't looked into changing the "expand/close" symbol, but I think that should be easy.

Thanks to everyone who helps and I would sometime like to see this become a UDF :)

Posted Image

Share this post


Link to post
Share on other sites



Bump :)

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

Is this what you wanted? :)

#AutoIt3Wrapper_Au3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6
#include <GUIConstantsEx.au3>
#include <GUITreeView.au3>
#include <TreeViewConstants.au3>
#include <WinAPI.au3>
#include <WindowsConstants.au3>


Global $iTreeView_Flag = False
Global $hChild, $hGUI, $hTreeView, $iTreeView, $iTreeView_Child, $iTreeView_Parent

$hGUI = GUICreate("Test", 800, 500)
GUICtrlCreatePic(@ScriptDir & "\Test.jpg", 0, 0, 800, 500)
GUICtrlSetState(-1, $GUI_DISABLE)
GUISetState(@SW_SHOW, $hGUI)

$hChild = GUICreate("", 300, 200, 10, 10, $WS_POPUP, BitOR($WS_EX_LAYERED, $WS_EX_MDICHILD), $hGUI)
GUISetBkColor(0xABCDEF, $hChild)
$iTreeView = GUICtrlCreateTreeView(0, 0, 300, 200, BitOR($TVS_HASBUTTONS, $TVS_LINESATROOT, $TVS_DISABLEDRAGDROP, $TVS_SHOWSELALWAYS))
$hTreeView = GUICtrlGetHandle($iTreeView)
GUICtrlSetBkColor($iTreeView, 0xABCDEF)
_WinAPI_SetLayeredWindowAttributes($hChild, 0xABCDEF, 255)
GUISetState(@SW_SHOW, $hChild)

GUISwitch($hGUI)

For $iParent = 0 To 4
    $iTreeView_Parent = GUICtrlCreateTreeViewItem($iParent, $iTreeView)
    For $iChild = 0 To 4
        $iTreeView_Child = GUICtrlCreateTreeViewItem($iParent & "." & $iChild, $iTreeView_Parent)
        For $iChild2 = 0 To 4
            GUICtrlCreateTreeViewItem($iParent & "." & $iChild & "." & $iChild2, $iTreeView_Child)
        Next
    Next
Next

GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit

    EndSwitch

    If $iTreeView_Flag Then
        $iTreeView_Flag = False
        ConsoleWrite(_GUICtrlTreeView_GetText($hTreeView, _GUICtrlTreeView_GetSelection($hTreeView)) & @CRLF)
        WinSetTitle($hGUI, $hGUI, "You Clicked On: " & _GUICtrlTreeView_GetText($hTreeView, _GUICtrlTreeView_GetSelection($hTreeView)))
    EndIf

WEnd

Func WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam)
    #forceref $hWnd, $iMsg, $iwParam
    Local $tNMHDR = DllStructCreate($tagNMHDR, $ilParam)
    Local $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom"))
    Local $iCode = DllStructGetData($tNMHDR, "Code")
    Switch $hWndFrom
        Case $hTreeView
            Switch $iCode
                Case $NM_CLICK
                    $iTreeView_Flag = True
            EndSwitch
    EndSwitch
    Return "GUI_RUNDEFMSG"
EndFunc   ;==>WM_NOTIFY
Edited by guinness

_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_DotNet_Load()/_DotNet_Unload()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 04/09/2015

Share this post


Link to post
Share on other sites

The problem I keep running into with this is that a transparancy color that looks ok. (greyish colors for black text) are hard to click, while 0xABCDEF works well, but looks like crap.

I've tried checking _GUICtrlTreeView_HitTestItem and _GUICtrlTreeView_HitTestItem on mouseclicks, wich reliable tells me what item should be clicked, but I ran into two problems:

1. Writing an event handler is a pain

2. The normal clicks interfere with the simulated ones if they do get through and blocking them (by blocking all messages to from the treeview) also blocks the simulated clicks.

Here's my attempt, maybe someone knows how to improve it.

#include <WINAPI.au3>
#Include <GUITreeView.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <TreeViewConstants.au3>
Global $fBlockTree = True, $iTransColor = 0x7F7F7F ;For black text this looks ok
$GUI_Parent = GUICreate("Test", 800, 500)
GUICtrlCreatePic(@DesktopDir & "\test.jpg", 0, 0, 800, 500)
$GUI_Child = GUICreate("", 300, 200, 10, 10, $WS_POPUP, BitOR($WS_EX_LAYERED, $WS_EX_MDICHILD), $GUI_Parent)
$Tree = GUICtrlCreateTreeView(0,0,300,200,BitOR($TVS_HASBUTTONS, $TVS_LINESATROOT, $TVS_DISABLEDRAGDROP, $TVS_SHOWSELALWAYS))
$Tree_Handle = GUICtrlGetHandle($Tree)
GUICtrlSetBkColor($Tree , $iTransColor)
_WinAPI_SetLayeredWindowAttributes($GUI_Child, $iTransColor, 255)
GUISetState(@SW_SHOW , $GUI_Child)
GUISwitch($GUI_Parent)

For $iParent = 0 To 4
    $Tree_Parent = GUICtrlCreateTreeViewItem($iParent,$Tree)
    For $iChild = 0 To 4
        $Tree_Child = GUICtrlCreateTreeViewItem($iParent & "." & $iChild,$Tree_Parent)
        For $iChild2 = 0 To 4
            GUICtrlCreateTreeViewItem($iParent & "." & $iChild & "." & $iChild2,$Tree_Child)
        Next
    Next
Next
GUISetState(@SW_SHOW)

GUIRegisterMsg($WM_NOTIFY, "_WM_NOTIFY")

While 1
    $Msg = GUIGetMsg()
    Switch $Msg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $GUI_EVENT_PRIMARYDOWN
            _ClickTree(0)
        Case $GUI_EVENT_PRIMARYUP
            _ClickTree(1)
        Case $GUI_EVENT_SECONDARYDOWN
            _ClickTree(2)
        Case $GUI_EVENT_SECONDARYUP
            _ClickTree(3)
    EndSwitch
WEnd

Func _ClickTree($iKey)
    Local $PosX = _WinAPI_GetMousePosX(True, $Tree_Handle)
    Local $PosY = _WinAPI_GetMousePosY(True, $Tree_Handle)
    Local $iHitTest = _GUICtrlTreeView_HitTest($Tree,$PosX , $PosY)
    Local $hHitItem = _GUICtrlTreeView_HitTestItem($Tree, $PosX, $PosY)
    Local $sItem = _GUICtrlTreeView_GetText($Tree,$hHitItem)
    Local $sKey
    ConsoleWrite("$iHitTest=" & $iHitTest & " and $hHitItem=" & $hHitItem & " and $iKey=" & $iKey & " meaning:" & @TAB)
    Switch $iKey
        Case 0
            $sKey = "PMB Down "
        Case 1
            $sKey = "PMB Up "
        Case 2
            $sKey = "SMB Down "
        Case 3
            $sKey = "SMB Up "
    EndSwitch
    Select
        Case BitAND($iHitTest, 1)
            ConsoleWrite($sKey & "In client, not on an item" & @CRLF)
        Case BitAND($iHitTest, 2)
            ConsoleWrite($sKey & "On the bitmap associated with item" & $sItem & @CRLF)
        Case BitAND($iHitTest, 4)
            ConsoleWrite($sKey & "On the text associated with item " & $sItem & @CRLF)
            If $iKey = 1 Then
                $fBlockTree = False
                _GUICtrlTreeView_SelectItem($Tree_Handle,$hHitItem,$TVGN_CARET)
                $fBlockTree = True
                WinSetTitle($GUI_Parent, $GUI_Parent, "You clicked on: " & $sItem)
            EndIf
        Case BitAND($iHitTest, 8)
            ConsoleWrite($sKey & "In the indentation associated with item" & $sItem & @CRLF)
        Case BitAND($iHitTest, 16)
            ConsoleWrite($sKey & "On the button of item " & $sItem & @CRLF)
            If $iKey = 1 Then
                $fBlockTree = False
                _SendMessage($Tree_Handle, $TVM_EXPAND, 0x0003, $hHitItem, 0, "wparam", "handle")
                $fBlockTree = True
            EndIf
        Case BitAND($iHitTest, 32)
            ConsoleWrite($sKey & "In the area to the right of item  " & $sItem & @CRLF)
        Case BitAND($iHitTest, 64)
            ConsoleWrite($sKey & "On the state icon for item " &  $sItem & " which is in a user-defined state" & @CRLF)
        Case BitAND($iHitTest, 128)
            ConsoleWrite($sKey & "Above the client area" & @CRLF)
        Case BitAND($iHitTest, 256)
            ConsoleWrite($sKey & "Below the client area" & @CRLF)
        Case BitAND($iHitTest, 512)
            ConsoleWrite($sKey & "To the left of the client area" & @CRLF)
        Case BitAND($iHitTest, 1024)
            ConsoleWrite($sKey & "To the right of the client area" & @CRLF)
    EndSelect
    If $iKey = 1 Or $iKey = 3 Then ConsoleWrite(@CRLF)
EndFunc

Func _WM_NOTIFY($hWnd, $iMsg, $wParam, $lParam)
    #forceref $hWnd, $iMsg, $wParam
    Local $tNMHDR = DllStructCreate($tagNMHDR, $lParam)
    $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom"))
    Switch $hWndFrom
        Case $Tree_Handle
            Return $fBlockTree ;Block messages that are not called from the _ClickTree function. (seems to fail a bit. :<)
    EndSwitch
EndFunc

Share this post


Link to post
Share on other sites

To me both of our Examples look the same when it comes to transparency! Or maybe its my eyes :)


_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_DotNet_Load()/_DotNet_Unload()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 04/09/2015

Share this post


Link to post
Share on other sites

To me both of our Examples look the same when it comes to transparency! Or maybe its my eyes :)

I think you may not be using font smoothing. (cleartype) if they look the same.

For me, your example has bright greenish edges around the letters where the color of the letters is blended with the background. If I use a grey color is looks better.

When using 0xABCDEF as color the items seem to be easier to click. (not sure about the logic behind this) but you still have to click pretty much on the text of the item, rather than anywhere in the item rectangle. This is what I was trying to fix, but so far I'm not happy with the result.

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

The items need a background to click on.

I've come up with a workaround using an implementation of mouse hover hot tracking.

(The $TVS_TRACKSELECT style by itself only adds underlining and text highlight).

EDIT: fixed typo, added BitOR($WS_CLIPCHILDREN, $WS_POPUP) to fix gui flash when expanded items show scrollbar

;modified from example by Tvern and Melba23
#AutoIt3Wrapper_au3check_parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6
#include <WINAPI.au3>
#include <GUITreeView.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <TreeViewConstants.au3>
#include <FontConstants.au3>

Opt('MustDeclareVars', 1)

Global $iTransColor = 0xDADADA ;experiment to get the best look

Global $sFilePath = @ScriptDir & "\BRUSHED-STAINLESS-CMYK.jpg"
If FileExists($sFilePath) = 0 Then
    Global $sURL = "http://www.dreamstime.com/brushed-metal-thumb2509190.jpg"
    InetGet($sURL, $sFilePath)
EndIf
Global $GUI_Parent, $GUI_Child, $Msg, $Tree, $Tree_Parent, $Tree_Handle, $Tree_Child, $Tree_Child2, $iCol, $hDC
Global $hLastItem = 0, $fTVEdit = False, $cPic, $hPic
$GUI_Parent = GUICreate("Transparent Treeview", 300, 300)
$cPic = GUICtrlCreatePic($sFilePath, 0, 0, 300, 300)
;pic must be enabled for treeview item label blank space clicking
$hPic = GUICtrlGetHandle(-1)

;$TVS_TRACKSELECT ; adds underline to item text
$GUI_Child = GUICreate("", 280, 280, 10, 10, BitOR($WS_CLIPCHILDREN, $WS_POPUP), BitOR($WS_EX_LAYERED, $WS_EX_MDICHILD), $GUI_Parent)
_WinAPI_SetLayeredWindowAttributes($GUI_Child, $iTransColor, 255)
$Tree = GUICtrlCreateTreeView(0, 0, 280, 280, _
BitOR($TVS_HASBUTTONS, $TVS_HASLINES, $TVS_CHECKBOXES, $TVS_LINESATROOT, $TVS_DISABLEDRAGDROP, $TVS_SHOWSELALWAYS, $WS_TABSTOP))
GUICtrlSetBkColor($Tree, $iTransColor)
_GUICtrlTreeView_SetLineColor($Tree, 0xFFFFFF)
$Tree_Handle = GUICtrlGetHandle($Tree)
GUISwitch($GUI_Parent)


GUIRegisterMsg($WM_SETCURSOR, "WM_SETCURSOR")
;GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY") ;optional reseting highlight when editing items
GUISetState(@SW_SHOW, $GUI_Child)
GUISetState(@SW_SHOW, $GUI_Parent)

GUICtrlSendMsg($Tree, $WM_SETREDRAW, 0, 0)
For $iParent = 0 To 4
    $Tree_Parent = GUICtrlCreateTreeViewItem($iParent & " New Item >              <", $Tree)
    For $iChild = 0 To 4
        $Tree_Child = GUICtrlCreateTreeViewItem($iParent & "." & $iChild & " >               <", $Tree_Parent)
        For $iChild2 = 0 To 4
            $Tree_Child2 = GUICtrlCreateTreeViewItem($iParent & "." & $iChild & "." & $iChild2 & " >              <", $Tree_Child)
        Next
    Next
Next
GUICtrlSendMsg($Tree, $WM_SETREDRAW, 1, 0)


While 1
    $Msg = GUIGetMsg()
    Switch $Msg
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch
WEnd


Func WM_SETCURSOR($hWnd, $iMsg, $wParam, $lParam)
    ;transparent treeview item hot track workaround
    ;coded by rover 2k11
    #forceref $hWnd, $iMsg, $wParam, $lParam
    Local $tPoint, $tHitTest, $hItem
    If $wParam = $hPic And $fTVEdit = False Then ;mouse over treeview background image
        $tPoint = _WinAPI_GetMousePos(True, $Tree_Handle)
        $tHitTest = _GUICtrlTreeView_HitTestEx($Tree_Handle, DllStructGetData($tPoint, "X"), DllStructGetData($tPoint, "Y"))
        If BitAND(DllStructGetData($tHitTest, "Flags"), $TVHT_ONITEMLABEL) <> 0 Then
            $hItem = DllStructGetData($tHitTest, "Item")
            If IsPtr($hItem) = 0 Then Return $GUI_RUNDEFMSG
            If BitAND(_GUICtrlTreeView_GetState($Tree_Handle, $hItem), $TVIS_SELECTED) <> $TVIS_SELECTED Then
                If $hLastItem <> $hItem Then
                    _GUICtrlTreeView_SetState($Tree_Handle, $hItem, $TVIS_DROPHILITED, 1)
                    If IsPtr($hLastItem) <> 0 Then _GUICtrlTreeView_SetState($Tree_Handle, $hLastItem, $TVIS_DROPHILITED, 0)
                    $hLastItem = $hItem
                EndIf
            EndIf
        Else
            If IsPtr($hLastItem) <> 0 Then
                _GUICtrlTreeView_SetState($Tree_Handle, $hLastItem, $TVIS_DROPHILITED, 0)
                $hLastItem = 0
            EndIf
        EndIf
    ElseIf $wParam = $Tree_Handle And $fTVEdit = False Then ;mouse over treeview elements
        $tPoint = _WinAPI_GetMousePos(True, $Tree_Handle)
        $tHitTest = _GUICtrlTreeView_HitTestEx($Tree_Handle, DllStructGetData($tPoint, "X"), DllStructGetData($tPoint, "Y"))
        If BitAND(DllStructGetData($tHitTest, "Flags"), $TVHT_ONITEMLABEL) <> 0 Then
            $hItem = DllStructGetData($tHitTest, "Item")
            If IsPtr($hItem) = 0 Then Return $GUI_RUNDEFMSG
            If BitAND(_GUICtrlTreeView_GetState($Tree_Handle, $hItem), $TVIS_SELECTED) = $TVIS_SELECTED Then
                If IsPtr($hLastItem) <> 0 Then
                    _GUICtrlTreeView_SetState($Tree_Handle, $hLastItem, $TVIS_DROPHILITED, 0)
                    $hLastItem = 0
                EndIf
            EndIf
        EndIf
    EndIf
    Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_SETCURSOR



;optional
;=======================================================================================

; Font Quality
;~ Global Const $DEFAULT_QUALITY = 0x0
;~ Global Const $DRAFT_QUALITY = 0x1
;~ Global Const $PROOF_QUALITY = 0x2
;~ Global Const $NONANTIALIASED_QUALITY = 0x3
;~ Global Const $ANTIALIASED_QUALITY = 0x4
;~ Global Const $CLEARTYPE_QUALITY = 0x05

;you could use the pixel functions or read from the the bitmap to get the approx. colour of background
;of the treeview item area for $iTransColor.
;if you cannot get a good blend of font to background, especially if the background is not a texture
;(e.g. picture), then set font with _CtrlGetFont()/GUICtrlSetFont() and set font quality with
;CLEARTYPE_QUALITY, ANTIALIASED_QUALITY or NONANTIALIASED_QUALITY.
;The results are not as good as a smoothed font, and you will need to add a WM_THEMECHANGED message handler
;to call _CtrlGetFont() and GUICtrlSetFont(), as the system control font can change with the theme.


;optional set font and get pixel functions
;~ Local $aFont = _CtrlGetFont(-1) ;get current font, either system font for gui elements or font set by theme
;~ GUICtrlSetFont($Tree, $aFont[1], $aFont[2], $aFont[3], $aFont[4], $CLEARTYPE_QUALITY)

;~ For $i = 0 To UBound($aFont) -1
;~  ConsoleWrite("+> $aFont[" & $i & "]: "&$aFont[$i] & @CRLF)
;~ Next
;~ ConsoleWrite(@CRLF)

;~ Opt("PixelCoordMode", 2);2=client
;~ $iCol = PixelGetColor(15, 20)
;~ ConsoleWrite('+PixelGetColor: 0x' & Hex($iCol, 6) & @CRLF)

;~ $hDC = _WinAPI_GetDC($hPic)
;~ $iCol = _WinAPI_GetPixel($hDC, 15, 20)
;~ _WinAPI_ReleaseDC($hPic, $hDC)
;~ ConsoleWrite('+GetPixel: 0x' & Hex($iCol, 6) & @CRLF)



Func WM_NOTIFY($hWnd, $iMsg, $wParam, $lParam)
    #forceref $hWnd, $iMsg, $wParam
    Local $hWndFrom, $iIDFrom, $iCode, $tNMHDR, $hItem, $tINFO
    #forceref $hWndFrom
    $tNMHDR = DllStructCreate($tagNMHDR, $lParam)
    $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom"))
    $iIDFrom = DllStructGetData($tNMHDR, "IDFrom")
    $iCode = DllStructGetData($tNMHDR, "Code")
    Switch $iIDFrom
        Case $Tree
            Switch $iCode
                Case $TVN_BEGINLABELEDITW
                    _GUICtrlTreeView_SetState($Tree_Handle, $hLastItem, $TVIS_DROPHILITED, 0)
                    $hLastItem = 0
                    $fTVEdit = True ;prevents other items from mouse highlighting when item in edit mode
                Case $TVN_ENDLABELEDITW ;clear item selection if edit cancelled by click on other item
                    $tINFO = DllStructCreate($tagNMTVDISPINFO, $lParam)
                    $hItem = DllStructGetData($tINFO, "hItem")
                    If $hItem <> $hLastItem Then
                        _GUICtrlTreeView_SetState($Tree_Handle, $hItem, $TVIS_FOCUSED, 0)
                        _GUICtrlTreeView_SetState($Tree_Handle, $hItem, $TVIS_SELECTED, 0)
                    EndIf
                    $fTVEdit = False
                    $hLastItem = 0
            EndSwitch
    EndSwitch
    Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_NOTIFY


Func _CtrlGetFont($hWnd)
    ;modified from __GUIGetFont()in _GUICtrlCreateTFLabel.au3
    ;Author G.Sandler a.k.a MrCreatoR
    ;Forum link...:  http://www.autoitscript.com/forum/index.php?showtopic=96986
    ; [0] - 5
    ; [1] - Size
    ; [2] - Weight
    ; [3] - Attribute
    ; [4] - Name
    ; [5] - Quality
    Local $Ret, $hDC, $hFont, $tFont
    Local $aFont[1] = [0]
    If IsHWnd($hWnd) = 0 Then $hWnd = GUICtrlGetHandle($hWnd)
    $hDC = _WinAPI_GetDC($hWnd)
    $hFont = _SendMessage($hWnd, $WM_GETFONT)
    $tFont = DllStructCreate($tagLOGFONT)
    $Ret = DllCall('gdi32.dll', 'int', 'GetObjectW', 'ptr', $hFont, 'int', DllStructGetSize($tFont), 'ptr', DllStructGetPtr($tFont))
    If (Not @error) And ($Ret[0]) Then
        Dim $aFont[6] = [5]
        $aFont[1] = -Round(DllStructGetData($tFont, 'Height') / _WinAPI_GetDeviceCaps($hDC, $LOGPIXELSY) * 72, 1)
        $aFont[2] = DllStructGetData($tFont, 'Weight')
        $aFont[3] = BitOR(2 * (DllStructGetData($tFont, 'Italic') <> 0), 4 * (DllStructGetData($tFont, 'Underline') <> 0), 8 * (DllStructGetData($tFont, 'Strikeout') <> 0))
        $aFont[4] = DllStructGetData($tFont, 'FaceName')
        $aFont[5] = DllStructGetData($tFont, 'Quality')
    EndIf
    _WinAPI_ReleaseDC($hWnd, $hDC)
    Return $aFont
EndFunc   ;==>_CtrlGetFont


; #FUNCTION# ====================================================================================================================
; Name...........: _WinAPI_GetPixel
; Description....: Retrieves the color value of the pixel at the specified coordinates.
; Syntax.........: _WinAPI_GetPixel ( $hDC, $iX, $iY )
; Parameters.....: $hDC    - Handle to the device context.
;                  $iX     - The x-coordinate, in logical units, of the pixel to be examined.
;                  $iY     - The y-coordinate, in logical units, of the pixel to be examined.
; Return values..: Success - The color of the pixel, in RGB.
;                  Failure - (-1) and sets the @error flag to non-zero.
; Author.........: Yashied
; Modified.......:
; Remarks........: None
; Related........:
; Link...........: @@MsdnLink@@ GetPixel
; Example........: Yes
; ===============================================================================================================================

Func _WinAPI_GetPixel($hDC, $iX, $iY)
    Local $Ret = DllCall('gdi32.dll', 'dword', 'GetPixel', 'hwnd', $hDC, 'int', $iX, 'int', $iY)
    If (@error) Or ($Ret[0] = 0xFFFFFFFF) Then
        Return SetError(1, 0, -1)
    EndIf
    Return _WinAPI_SwitchColor($Ret[0])
EndFunc   ;==>_WinAPI_GetPixel

; #FUNCTION# ====================================================================================================================
; Name...........: _WinAPI_SwitchColor
; Description....: Converts a color from BGR to RGB and vice versa.
; Syntax.........: _WinAPI_SwitchColor ( $iColor )
; Parameters.....: $iColor - The color to conversion.
; Return values..: Converted color (RGB or BGR - depends on the $iColor value, BGR > RGB > BGR etc).
; Author.........: Yashied
; Modified.......:
; Remarks........: None
; Related........:
; Link...........: None
; Example........: Yes
; ===============================================================================================================================

Func _WinAPI_SwitchColor($iColor)
    Return BitOR(BitAND($iColor, 0x00FF00), BitShift(BitAND($iColor, 0x0000FF), -16), BitShift(BitAND($iColor, 0xFF0000), 16))
EndFunc   ;==>_WinAPI_SwitchColor
Edited by rover

I see fascists...

Share this post


Link to post
Share on other sites

I'm not using font smoothing :) so thats why then. Nice Example rover.


_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_DotNet_Load()/_DotNet_Unload()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 04/09/2015

Share this post


Link to post
Share on other sites

rover,

Well up to your ususal standard! :)

I had tried using _GUICtrlTreeView_HitTest and could not make it work - I can now see how far off I was in my approach. ;)

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______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

 

Share this post


Link to post
Share on other sites

Thanks Melba23

Coming up with the idea of using the TVIS_DROPHILITED state to get the item background colour for hot tracking to solve the transparency issue was the easy part...

But it's not a useful workaround if drag and drop is needed though.


I see fascists...

Share this post


Link to post
Share on other sites

Thanks Guiness

I forgot to fix the gui glitch when the scrollbar shows.

Added BitOR($WS_CLIPCHILDREN, $WS_POPUP) to transparent child gui


I see fascists...

Share this post


Link to post
Share on other sites

Hmm that's a nice approach.

I'd still like to figure out a way to do this without drawing the item in another color, but that's mostly out of frustration at this point.

Share this post


Link to post
Share on other sites

#14 ·  Posted (edited)

I just have to say wow :)

I think this is on it's way to being a UDF and it's sure going to have a lot of credits ;)

A bit more work is needed and unfortunately I am not as skilled with this as much as all of you are and I hope that most, if not all of you continue to get it working and with your guys permission I would like to post all of your examples in examples scripts to let this been seen by more people and if it sparks interest which I am sure it will may be someone else will join in and help and come up with an idea of solving the remaining problems.

I started the topic for help for my own private script but I think we have something big here...well not me, all of you do anyways ;)

Also just want all of you to know that I appreciate all of your work and want to thank all of you so far for the excellent work.

Edited by SkellySoul

Share this post


Link to post
Share on other sites

Posted in Examples for feedback :)

Share this post


Link to post
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
Sign in to follow this  
Followers 0