Jump to content

Recommended Posts

Posted

I've updated the zip file in bottom of first post to fix the error about the default font as described in posts 19 and 20.

A note about fonts: To define a font for an item or a subitem you use the functions ListViewColorsFonts_SetItemFonts (fonts only) or ListViewColorsFonts_SetItemColorsFonts (colors and fonts). The font name and the font style are parameters in the functions. Instead of a font name you can use a font handle (pointer) as parameter. Leave the font style as the default value (0). In this way you can control many more characteristics of the font. Eg. the width and height of the font to make it fit into the listview cell. See "Examples\7) Original examples\lvCustDrawFonts.au3" for an example.

Like in the example about editing listview cells it's also the plan that this UDF should support colors and fonts in virtual listviews. And I actually think that it already does, but it's not tested. I'll add some examples in next version.

  • 2 months later...
Posted (edited)
  On 3/20/2016 at 9:23 AM, LarsJ said:

<zot>

... Comments are welcome. Let me know if there are any issues. ...

<zot>

Expand  

Hi,

... about setting style of items:


I see you can set style by setting the $iFontStyle in function calls as following:

 

;                  $iFontStyle   - Text style of item or subitem
;                                  Use the following values for $iFontStyle
;                                      0: Normal text style (default)
;                                      1: Bold text style
;                                      2: Italic text style
;                                      3: Underline text style
;                                  These predefined constants can also be used:
;                                  $iFontStyleNormal, $iFontStyleBold, $iFontStyleItalic, $iFontStyleUnderline
;                                  If $sFontName is a font handle $iFontStyle is ignored

If allowed I would propose this:

Instead of using values 1 or 2 or 3 for bold or italic or underline respectively, It could be used 1, 2 , 4 (bit values) allowing in this way the use of more styles for a single item just summing values together,
so, for example bold AND underline become 5 (that is 1 + 4)
with a quick test, I've seen that it works by just changing this part in the UDF

Switch $iFontStyle
            Case 0 ; Normal
            Case 1 ; Bold
                DllStructSetData( $tLogFont, "Weight", BitOR( $iWeight, $FW_BOLD ) )
            Case 2 ; Italic
                DllStructSetData( $tLogFont, "Italic", True )
            Case 3 ; Underline
                DllStructSetData( $tLogFont, "Underline", True )
            Case Else
                If $sFontName Then DllStructSetData( $tLogFont, "FaceName", $sFaceName ) ; Reset $tLogFont on error
                Return SetError(5, 0, -1)                                                ; Invalid font style
        EndSwitch

with something like this for example:

If BitAND($iFontStyle,1) Then DllStructSetData( $tLogFont, "Weight", BitOR( $iWeight, $FW_BOLD ) ) ; Bold
        If BitAND($iFontStyle,2) Then DllStructSetData( $tLogFont, "Italic", True ) ; Italic
        If BitAND($iFontStyle,4) Then DllStructSetData( $tLogFont, "Underline", True ) ; Underline

if instead I have misunderstood how to use styles, then just forget all of what i've said above...
Thanks

Edited by Chimp

 

image.jpeg.9f1a974c98e9f77d824b358729b089b0.jpeg Chimp

small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt....

Posted
Posted

:offtopic:

@Chimp What means    <zot>    ?

Signature beginning:
Please remember: "AutoIt"..... *  Wondering who uses AutoIt and what it can be used for ? * Forum Rules *
ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Codefor other useful stuff click the following button:

  Reveal hidden contents

Signature last update: 2023-04-24

Posted (edited)
  On 7/27/2016 at 3:58 PM, LarsJ said:

Excellent suggestion. Why didn't I think at that myself? 

Expand  

The learning process never ends (of course, in most cases)
Unfortunately, in recent times I have not had time to read your manulas/textbooks ... I mean scripts.
;)

mLipok

Edited by mLipok

Signature beginning:
Please remember: "AutoIt"..... *  Wondering who uses AutoIt and what it can be used for ? * Forum Rules *
ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Codefor other useful stuff click the following button:

  Reveal hidden contents

Signature last update: 2023-04-24

Posted
  On 7/28/2016 at 2:41 AM, mLipok said:

:offtopic:

@Chimp What means    <zot>    ?

Expand  

isn't it used when you want to mark that in that point a part of the original message has been removed?.... or maybe it's <snip>... ???

  Reveal hidden contents

 

 

image.jpeg.9f1a974c98e9f77d824b358729b089b0.jpeg Chimp

small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt....

Posted

DR .... ZOT WHO ;)

 

 

Signature beginning:
Please remember: "AutoIt"..... *  Wondering who uses AutoIt and what it can be used for ? * Forum Rules *
ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Codefor other useful stuff click the following button:

  Reveal hidden contents

Signature last update: 2023-04-24

  • 1 year later...
Posted

Hi,

I've a couple of issues with the UDF:
- When I add 256 for the colors parameter (colors of selected Items without focus), the selected items lose the column alignment.
- Applying a font for a subitem changes the font for the following subitems as well, even though the font was not applied to them.

Also, is there anything I can do to improve the performance of this example?

Thanks.
 

#include <GUIConstantsEx.au3>
#include <ColorConstants.au3>
#include <ListViewColorsFonts.au3>

Global $Rows = 500, $Items[$Rows][15]

Test(1)
Func Test($ApplyColorsFonts = 1)
    $Cols = ''
    For $i = 1 To 15
        $Cols &= 'Column ' & $i & '|'
    Next
    CreateItems()

    GUICreate("Test", 1600, 750)
    GUISetFont(8, 400, 0, 'MS Sans Serif')
    $LV = GUICtrlCreateListView($Cols, 0, 0, 1600, 750, Default, BitOR($LVS_EX_FULLROWSELECT, $LVS_EX_DOUBLEBUFFER, $LVS_EX_HEADERDRAGDROP))

    _GUICtrlListView_AddArray($LV, $Items)
    For $i = 0 To 14
        _GUICtrlListView_JustifyColumn($LV, $i, 2)
        _GUICtrlListView_SetColumnWidth($LV, $i, $LVSCW_AUTOSIZE_USEHEADER)
    Next

    If $ApplyColorsFonts Then
        $Color_Selected = 0x3399FF

        If $ApplyColorsFonts = 2 Then
            $hFont = _WinAPI_CreateFont(6, 0, 0, 0, 400, False, False, False, $DEFAULT_CHARSET, $OUT_DEFAULT_PRECIS, $CLIP_DEFAULT_PRECIS, $DEFAULT_QUALITY, 0, 'Arial')
            ListViewColorsFonts_Init($LV, 7 + 128 + 256, $Rows, False)
        Else
            ListViewColorsFonts_Init($LV, 1 + 2 + 128 + 256, $Rows, False)
        EndIf

        For $i = 0 To $Rows - 1
            ListViewColorsFonts_SetItemColors($LV, $i, -1, 0, 0, 0, 0, $Color_Selected, $Color_White)

            ListViewColorsFonts_SetItemColors($LV, $i, 0, $Color_White, $Color_Red, 0, 0, $Color_Selected, $Color_White)
            If $ApplyColorsFonts = 2 Then
                ListViewColorsFonts_SetItemColorsFonts($LV, $i, 2, $hFont, 0, $Color_Gray, $Color_White, $Color_Gray, $Color_White, $Color_Selected, $Color_White)
            Else
                ListViewColorsFonts_SetItemColors($LV, $i, 2, $Color_Gray, $Color_White, $Color_Gray, $Color_White, $Color_Selected, $Color_White)
            EndIf
            ListViewColorsFonts_SetItemColors($LV, $i, 4, $Color_White, $Color_Blue, 0, 0, $Color_Selected, $Color_White)
            ListViewColorsFonts_SetItemColors($LV, $i, 6, $Color_Red, $Color_White, $Color_Red, $Color_White, $Color_Red, $Color_White)
            ListViewColorsFonts_SetItemColors($LV, $i, 8, $Color_Green, $Color_White, $Color_Green, $Color_White, $Color_Selected, $Color_White)
            ListViewColorsFonts_SetItemColors($LV, $i, 10, $Color_White, $Color_Purple, 0, 0, $Color_Selected, $Color_White)
            ListViewColorsFonts_SetItemColors($LV, $i, 12, $Color_Blue, $Color_White, $Color_Blue, $Color_White, $Color_Selected, $Color_White)
        Next
        ListViewColorsFonts_Redraw($LV)
    EndIf

    GUISetState()
    While GUIGetMsg() <> $GUI_EVENT_CLOSE
    WEnd
EndFunc

Func CreateItems()
    For $i = 0 To $Rows - 1
        For $y = 0 To 14
            $Items[$i][$y] = RandomText()
        Next
    Next
EndFunc

Func RandomText($Min = 10, $Max = 30, $StartChr = 97, $EndChr = 122)
    Local $RES
    For $i = 1 To Random($Min, $Max, 1)
        $RES &= Chr(Random($StartChr, $EndChr, 1))
    Next
    Return $RES
EndFunc

 

Posted

Anas, I'm working on a complete new version of this UDF, but it'll not be soon. This means that there'll be no more updates of existing code.

The problem in your first point is that the functionality is not supported. All functionality is demonstrated in examples. If you use functionality that's not demonstrated, it'll probably not work.

The second point seems to be a bug. As I said, I do not want to do anything about it. Sorry.

The main reason for the performance issues in your last point is the number of columns. You have 15 columns but only half are visible. But all 15 columns will be updated, eg. when you are scrolling. Half of the columns are thus updated to no avail because they are not visible. That's the problem. Create 2 listviews in 2 tabs. It'll provide much better performance. When you want to run as much code, there should be no horizontal scrollbar.


I've taken advantage of the opportunity to update the images in first post (new links).

  • 8 months later...
Posted

Hello LarsJ,

if I make the width of the columns greater than 109 in this demo, the header in the last column is no longer completely colored. The larger the column width, the more columns in the header are no longer properly colored.

;-- TIME_STAMP   2018-11-20 22:46:23

#Region    ;************ Includes ************
;~ #Include <WindowsConstants.au3>
;~ #Include <GuiListView.au3>
#include <GUIConstantsEx.au3>
#include "..\..\..\UDFs\ListViewColorsFonts.au3"
;~ #include "..\..\..\UDFs\GuiListViewEx.au3"
#EndRegion ;************ Includes ************

; @ScriptFullPath = 'F:\_Archive\_Programmieren\AutoIt3\UDFs\ListViewColorsFonts\Examples\0) UDF examples\7) ListViewColorsFonts_Redraw\_GUICtrlListView_AddArray.au3'

_GUICtrlListView_AddArray_Demo()

Func _GUICtrlListView_AddArray_Demo()
    #Region - GUI Create
    Local $hGUI = GUICreate('GUICtrlCreateListView', 400, 300, 400, -1, BitOR($GUI_SS_DEFAULT_GUI, $WS_MAXIMIZEBOX, $WS_SIZEBOX), $WS_EX_WINDOWEDGE)
    Local $idLV = GUICtrlCreateListView('Name|Status1|Status2|Status3|Status4|Status5|Status6|Status7|Status8|Status9|Status10|Status11|Status12|Status13|Status14|Status15|Status16|Status17|Status18|Status19|Status20|Status21|Status22|Status23|Status24|Status25|Status26|Status27|Status28|Status29|Status30|Status31', 2, 2, 396, 296)
    GUISetState(@SW_MAXIMIZE)
    #EndRegion

    Local $aLV[16][32], $sAdd
    For $i = 0 To UBound($aLV) -1 Step 1
        $aLV[$i][0] = 'Name' & $i + 1
        For $j = 1 To UBound($aLV, 2) -1 Step 1
            $aLV[$i][$j] = 'Status' & $j
        Next
    Next

    Local $iAllColSize = 0, $iWidth = 150
    Local $aWJLV = [[$iWidth, 0], [$iWidth, 2], [$iWidth, 2], [$iWidth, 2], [$iWidth, 2], [$iWidth, 2], [$iWidth, 2], [$iWidth, 2], [$iWidth, 2], [$iWidth, 2], [$iWidth, 2], [$iWidth, 2], [$iWidth, 2], [$iWidth, 2], [$iWidth, 2], [$iWidth, 2], [$iWidth, 2], [$iWidth, 2], [$iWidth, 2], [$iWidth, 2], [$iWidth, 2], [$iWidth, 2], [$iWidth, 2], [$iWidth, 2], [$iWidth, 2], [$iWidth, 2], [$iWidth, 2], [$iWidth, 2], [$iWidth, 2], [$iWidth, 2], [$iWidth, 2], [$iWidth, 2], [$iWidth, 2]]
    For $i = 0 To UBound($aWJLV) -1 Step 1
        $iAllColSize += $aWJLV[$i][0]
        _GUICtrlListView_SetColumnWidth($idLV, $i, $aWJLV[$i][0])
        _GUICtrlListView_JustifyColumn($idLV, $i, $aWJLV[$i][1]) ; 0 left, 1 right, 2 center
    Next
    ConsoleWrite('> $iAllColSize = ' & $iAllColSize & @CRLF)
;~  $iWidth = 109, $iAllColSize = 3597 --> OK
;~  $iWidth = 110, $iAllColSize = 3630 --> BAD HEADER COLOR (Status 31)
;~  $iWidth = 150, $iAllColSize = 4950 --> BAD HEADER COLOR (Status 23 to Status 31)

    _GUICtrlListView_AddArray($idLV, $aLV)

    ; Perform initializations to add colors/fonts to single items/subitems
    ListViewColorsFonts_Init( $idLV, 7 ) ; $fColorsFonts = 7, ( $iAddRows = 100, $bNative = False )

    ; Set a green back color for all odd entire items and a yellow back color for all even entire items
    Local $iItemCount = _GUICtrlListView_GetItemCount($idLV)
    For $i = 0 To $iItemCount -1 Step 1
        ListViewColorsFonts_SetItemColors( $idLV, $i, -1, Mod($i, 2) ? 0xCCFFCC : 0xFFFFCC) ; Green or Yellow back color for entire item
    Next

    ; Force an update of local variables in drawing function
    ListViewColorsFonts_Redraw( $idLV )

    #Region - GUI SwitchLoop
    While True
        Switch GUIGetMsg()
            Case $GUI_EVENT_CLOSE
                Exit
        EndSwitch
    WEnd
    #EndRegion
EndFunc  ;==>_GUICtrlListView_AddArray_Demo

 

Bad_Header_Color.png

Posted

Hello Bitnugger. I've run your script as 64 bit code on Windows 7 and Windows 10. I don't see the issue with the header as shown in the picture.

But both of my PCs run with standard graphical settings. I haven't changed anything since the installation.

From the picture it appears that you are using a graphic theme or the like. And that may well be the cause of the problem.

If you have the possibility to test the script on a PC with default graphics setup, you'll probably not see the issue.

I think the problem is related to your graphical settings. And so, I do not think I can do anything about it. Sorry.

Posted
  On 11/21/2018 at 5:53 PM, LarsJ said:

I think the problem is related to your graphical settings.

Expand  

Right, I just tested it - it's the theme! With the default theme it works fine!

Thanks for the testing and the quick feedback!

  • 7 months later...
Posted (edited)

Hi, LarsJ - Great stuff!  Thanks!

Would you kindly elaborate on the difference between "native" and "UDF / Non-native" list views?  I'm unclear on how to set the $bNative parameter in the ListViewColorsFonts_Init() call. I wanted to use the list view's control ID elsewhere in the code, so I set it True. But then the Init call always failed (I don't know why). If I specify False, the call succeeds.  The failed @error value is 1, invalid list view.

Thank you for your hard work and time!

Edited by Mbee
Revised issue

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
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...