LarsJ

Colors and fonts in custom drawn ListViews - UDF version

27 posts in this topic




Very nice, I will keep this in my snippets directory.

Thanks!!

Share this post


Link to post
Share on other sites

Nice LarsJ.  Working great over Windows 10 x64. 

Saludos


 

venezuela.png Would you like to say thank to Danyfirex using a warmy way?  offer me a cup of coffee... coffee.png

autoit_scripter_blue_userbar.png

       AutoIt...

 

 

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

One little off topic question:

Whether this is possible to change collor for Selected but Unfocused rows ?

 

 

Edited by mLipok

Signature beginning:   Wondering who uses AutoIT and what it can be used for ?
* GHAPI UDF - modest begining - comunication with GitHub REST API *
ADO.au3 UDF     POP3.au3 UDF     XML.au3 UDF    How to use IE.au3  UDF with  AutoIt v3.3.14.x  for other useful stuff click the following button

Spoiler

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

My contribution (my own projects): * Debenu Quick PDF Library - UDF * Debenu PDF Viewer SDK - UDF * Acrobat Reader - ActiveX Viewer * UDF for PDFCreator v1.x.x * XZip - UDF * AppCompatFlags UDF * CrowdinAPI UDF * _WinMergeCompare2Files() * _JavaExceptionAdd() * _IsBeta() * Writing DPI Awareness App - workaround * _AutoIt_RequiredVersion() * Chilkatsoft.au3 UDF * TeamViewer.au3 UDF * JavaManagement UDF * VIES over SOAP * WinSCP UDF * GHAPI UDF - modest begining - comunication with GitHub REST API *

My contribution to others projects or UDF based on  others projects: * _sql.au3 UDF  * POP3.au3 UDF *  RTF Printer - UDF * XML.au3 - BETA * ADO.au3 UDF SMTP Mailer UDF *

Useful links: * Forum Rules * Forum etiquette *  Forum Information and FAQs * How to post code on the forum * AutoIt Online Documentation * AutoIt Online Beta Documentation * SciTE4AutoIt3 getting started * Convert text blocks to AutoIt code * Games made in Autoit * Programming related sites * Polish AutoIt Tutorial * DllCall Code Generator * 

Wiki: Expand your knowledge - AutoIt Wiki * Collection of User Defined Functions * How to use HelpFile * Best coding practices * 

IE Related:  * How to use IE.au3  UDF with  AutoIt v3.3.14.x * Why isn't Autoit able to click a Javascript Dialog? * Clicking javascript button with no ID * IE document >> save as MHT file * IETab Switcher (by LarsJ ) * HTML Entities * _IEquerySelectorAll() (by uncommon) * 

I encourage you to read: * Global Vars * Best Coding Practices * Please explain code used in Help file for several File functions * OOP-like approach in AutoIt * UDF-Spec Questions *  EXAMPLE: How To Catch ConsoleWrite() output to a file or to CMD *

"Homo sum; humani nil a me alienum puto" - Publius Terentius Afer
"Program are meant to be read by humans and only incidentally for computers and execute" - Donald Knuth, "The Art of Computer Programming"
:naughty:  :ranting:, be  :) and       \\//_.

Anticipating Errors :  "Any program that accepts data from a user must include code to validate that data before sending it to the data store. You cannot rely on the data store, ...., or even your programming language to notify you of problems. You must check every byte entered by your users, making sure that data is the correct type for its field and that required fields are not empty."

Signature last update: 2017-06-04

Share this post


Link to post
Share on other sites

in 

..\Examples\7) Original examples\lvCustDrawColors.au3

there is some issue with scrolling, scrollbar changes, but the rows on listview don not changes in all cases.

 

 


Signature beginning:   Wondering who uses AutoIT and what it can be used for ?
* GHAPI UDF - modest begining - comunication with GitHub REST API *
ADO.au3 UDF     POP3.au3 UDF     XML.au3 UDF    How to use IE.au3  UDF with  AutoIt v3.3.14.x  for other useful stuff click the following button

Spoiler

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

My contribution (my own projects): * Debenu Quick PDF Library - UDF * Debenu PDF Viewer SDK - UDF * Acrobat Reader - ActiveX Viewer * UDF for PDFCreator v1.x.x * XZip - UDF * AppCompatFlags UDF * CrowdinAPI UDF * _WinMergeCompare2Files() * _JavaExceptionAdd() * _IsBeta() * Writing DPI Awareness App - workaround * _AutoIt_RequiredVersion() * Chilkatsoft.au3 UDF * TeamViewer.au3 UDF * JavaManagement UDF * VIES over SOAP * WinSCP UDF * GHAPI UDF - modest begining - comunication with GitHub REST API *

My contribution to others projects or UDF based on  others projects: * _sql.au3 UDF  * POP3.au3 UDF *  RTF Printer - UDF * XML.au3 - BETA * ADO.au3 UDF SMTP Mailer UDF *

Useful links: * Forum Rules * Forum etiquette *  Forum Information and FAQs * How to post code on the forum * AutoIt Online Documentation * AutoIt Online Beta Documentation * SciTE4AutoIt3 getting started * Convert text blocks to AutoIt code * Games made in Autoit * Programming related sites * Polish AutoIt Tutorial * DllCall Code Generator * 

Wiki: Expand your knowledge - AutoIt Wiki * Collection of User Defined Functions * How to use HelpFile * Best coding practices * 

IE Related:  * How to use IE.au3  UDF with  AutoIt v3.3.14.x * Why isn't Autoit able to click a Javascript Dialog? * Clicking javascript button with no ID * IE document >> save as MHT file * IETab Switcher (by LarsJ ) * HTML Entities * _IEquerySelectorAll() (by uncommon) * 

I encourage you to read: * Global Vars * Best Coding Practices * Please explain code used in Help file for several File functions * OOP-like approach in AutoIt * UDF-Spec Questions *  EXAMPLE: How To Catch ConsoleWrite() output to a file or to CMD *

"Homo sum; humani nil a me alienum puto" - Publius Terentius Afer
"Program are meant to be read by humans and only incidentally for computers and execute" - Donald Knuth, "The Art of Computer Programming"
:naughty:  :ranting:, be  :) and       \\//_.

Anticipating Errors :  "Any program that accepts data from a user must include code to validate that data before sending it to the data store. You cannot rely on the data store, ...., or even your programming language to notify you of problems. You must check every byte entered by your users, making sure that data is the correct type for its field and that required fields are not empty."

Signature last update: 2017-06-04

Share this post


Link to post
Share on other sites

Thank you for feedback.

nend, Don't miss next version. I'll probably need additional 2,000 lines of code. I think it'll fit perfectly into your snippets folder.

Danyfirex, This is valuable information. It's obviously important that all this subclassing stuff is working. If not it would definitely be a showstopper.

Share this post


Link to post
Share on other sites

mLipok, I'm not quite sure if I understand your question in post 4 correctly. If not, please add a new post.

In a custom drawn listview it's possible to use custom back and fore colors for selected items even if the listview has not focus. The colors are drawn in the postpaint stage (after default drawing) immediately before the listview loses focus.

With the functions here you can define the colors as you wish. You set the colors with the parameters $iBackUnfocus and $iForeUnfocus in ListViewColorsFonts_Set-functions (provided that the value 256 is included in $fColorsFonts flag in ListViewColorsFonts_Init).

 

lvCustDrawColors.au3. I'm not able to verify the issue. Not even on my old XP which is very slow. When I drag the scroll bar with the mouse the rows in the listview are updated accordingly. I have tried many times this morning. I've tried with different tabs. I have not experienced any problems.

Do you experience the problem consistently every time, or has it just been a single time? How is the performance of "Examples\7) Original examples\Original\lvCustDrawColors.au3" (WM_NOTIFY message handler created with GUIRegisterMsg)? How is the performance of the other examples? Eg. "Examples\2) Entire columns\8 listviews\1) Colors and fonts, GUI.au3"?

Share this post


Link to post
Share on other sites

I make some testing My problem can be solved by changing Background color.
When Background color is not standard then selected+unfocused color also changing.

I ask as many computers uses old LCD monitors on which you do not see selected+unfocused listview item (unless you turn your head, or more precicly: You lay your head on the desk).


Signature beginning:   Wondering who uses AutoIT and what it can be used for ?
* GHAPI UDF - modest begining - comunication with GitHub REST API *
ADO.au3 UDF     POP3.au3 UDF     XML.au3 UDF    How to use IE.au3  UDF with  AutoIt v3.3.14.x  for other useful stuff click the following button

Spoiler

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

My contribution (my own projects): * Debenu Quick PDF Library - UDF * Debenu PDF Viewer SDK - UDF * Acrobat Reader - ActiveX Viewer * UDF for PDFCreator v1.x.x * XZip - UDF * AppCompatFlags UDF * CrowdinAPI UDF * _WinMergeCompare2Files() * _JavaExceptionAdd() * _IsBeta() * Writing DPI Awareness App - workaround * _AutoIt_RequiredVersion() * Chilkatsoft.au3 UDF * TeamViewer.au3 UDF * JavaManagement UDF * VIES over SOAP * WinSCP UDF * GHAPI UDF - modest begining - comunication with GitHub REST API *

My contribution to others projects or UDF based on  others projects: * _sql.au3 UDF  * POP3.au3 UDF *  RTF Printer - UDF * XML.au3 - BETA * ADO.au3 UDF SMTP Mailer UDF *

Useful links: * Forum Rules * Forum etiquette *  Forum Information and FAQs * How to post code on the forum * AutoIt Online Documentation * AutoIt Online Beta Documentation * SciTE4AutoIt3 getting started * Convert text blocks to AutoIt code * Games made in Autoit * Programming related sites * Polish AutoIt Tutorial * DllCall Code Generator * 

Wiki: Expand your knowledge - AutoIt Wiki * Collection of User Defined Functions * How to use HelpFile * Best coding practices * 

IE Related:  * How to use IE.au3  UDF with  AutoIt v3.3.14.x * Why isn't Autoit able to click a Javascript Dialog? * Clicking javascript button with no ID * IE document >> save as MHT file * IETab Switcher (by LarsJ ) * HTML Entities * _IEquerySelectorAll() (by uncommon) * 

I encourage you to read: * Global Vars * Best Coding Practices * Please explain code used in Help file for several File functions * OOP-like approach in AutoIt * UDF-Spec Questions *  EXAMPLE: How To Catch ConsoleWrite() output to a file or to CMD *

"Homo sum; humani nil a me alienum puto" - Publius Terentius Afer
"Program are meant to be read by humans and only incidentally for computers and execute" - Donald Knuth, "The Art of Computer Programming"
:naughty:  :ranting:, be  :) and       \\//_.

Anticipating Errors :  "Any program that accepts data from a user must include code to validate that data before sending it to the data store. You cannot rely on the data store, ...., or even your programming language to notify you of problems. You must check every byte entered by your users, making sure that data is the correct type for its field and that required fields are not empty."

Signature last update: 2017-06-04

Share this post


Link to post
Share on other sites

mLipok, I understand.

 

Sunday I forgot these lines in top of The UDF section:


To use the UDF you first calls ListViewColorsFonts_Init which stores information about the listview and the parent window, and creates the subclass that takes care of the actual drawing of the colors and fonts.

Then you call one or more of the ListViewColorsFonts_Set-functions to define the colors and fonts. Depending on the functions you might also need to call ListViewColorsFonts_Redraw. And that's all.

Finally you can call ListViewColorsFonts_Exit to remove the subclass before the script exits. If you don't call ListViewColorsFonts_Exit it's called automatically by the UDF.


The lines are added. Added a code example in Examples section.

1 person likes this

Share this post


Link to post
Share on other sites

#10 ·  Posted (edited)

If you have tested "Examples\2) Entire columns\8 listviews\1) Colors and fonts, GUI.au3", where all listviews are created directly in the GUI, you have seen that ListView 8 performs much better than ListView 1. This is evident in particular on a not too fast PC, if you drag the scrollbar up and down with the mouse.

What's the reason for the difference in performance? According to the message flow in this picture (copied from the Subclassing section)

Subclassing-1_zpspxopipsb.png

the performance should be the same in all listviews.

I've studied this example more carefully by adding some ConsoleWrite statements to the callback function. It turns out that if you work intensively in the same listview for example by dragging the scrollbar, the message flow looks as shown here:

Subclassing-1_zpslhg3tq7l.png

The messages from ListView 1 are sent to callback function 1, 2 and 3. But the messages from ListView 3 are sent only to callback function 3. It's clear that ListView 3 performs better than ListView 1.

If you work intensively in a listview the vast majority of messages follows the last diagram and only a few messages (before you start and after you have finished) follows the first diagram.

The listview that performs best is the listview that's subclassed as the last one. You can verify this by adding the following lines

; Stop subclassing ListView1
ListViewColorsFonts_Exit( $idListView1 )

; Start subclassing ListView1
ListViewColorsFonts_Init( $idListView1, 8 ) ; $fColorsFonts = 8, ( $iAddRows not used, $bNative not used )
ListViewColorsFonts_SetColumnColorsFonts( $idListView1, 0, "", 0, 0xCCCCFF ) ; Column 0: Back color = Blue
ListViewColorsFonts_SetColumnColorsFonts( $idListView1, 2, "", 0, 0xFFCCCC ) ; Column 2: Back color = Red

immediately after these lines (after line 240)

; Initialize listview to support column colors/fonts
ListViewColorsFonts_Init( $idListView8, 8 ) ; $fColorsFonts = 8, ( $iAddRows not used, $bNative not used )
ListViewColorsFonts_SetColumnColorsFonts( $idListView8, 1, "", $iFontStyleItalic )    ; Column 1: Style = Italic
ListViewColorsFonts_SetColumnColorsFonts( $idListView8, 2, "", $iFontStyleUnderline ) ; Column 2: Style = Underline

in the example.

Now ListView 1 is subclassed as the last one, and it'll perform best.

The above applies if all listviews are created directly in main GUI.

Edited by LarsJ
1 person likes this

Share this post


Link to post
Share on other sites

Awesome documentation as always  :)

 


Signature beginning:   Wondering who uses AutoIT and what it can be used for ?
* GHAPI UDF - modest begining - comunication with GitHub REST API *
ADO.au3 UDF     POP3.au3 UDF     XML.au3 UDF    How to use IE.au3  UDF with  AutoIt v3.3.14.x  for other useful stuff click the following button

Spoiler

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

My contribution (my own projects): * Debenu Quick PDF Library - UDF * Debenu PDF Viewer SDK - UDF * Acrobat Reader - ActiveX Viewer * UDF for PDFCreator v1.x.x * XZip - UDF * AppCompatFlags UDF * CrowdinAPI UDF * _WinMergeCompare2Files() * _JavaExceptionAdd() * _IsBeta() * Writing DPI Awareness App - workaround * _AutoIt_RequiredVersion() * Chilkatsoft.au3 UDF * TeamViewer.au3 UDF * JavaManagement UDF * VIES over SOAP * WinSCP UDF * GHAPI UDF - modest begining - comunication with GitHub REST API *

My contribution to others projects or UDF based on  others projects: * _sql.au3 UDF  * POP3.au3 UDF *  RTF Printer - UDF * XML.au3 - BETA * ADO.au3 UDF SMTP Mailer UDF *

Useful links: * Forum Rules * Forum etiquette *  Forum Information and FAQs * How to post code on the forum * AutoIt Online Documentation * AutoIt Online Beta Documentation * SciTE4AutoIt3 getting started * Convert text blocks to AutoIt code * Games made in Autoit * Programming related sites * Polish AutoIt Tutorial * DllCall Code Generator * 

Wiki: Expand your knowledge - AutoIt Wiki * Collection of User Defined Functions * How to use HelpFile * Best coding practices * 

IE Related:  * How to use IE.au3  UDF with  AutoIt v3.3.14.x * Why isn't Autoit able to click a Javascript Dialog? * Clicking javascript button with no ID * IE document >> save as MHT file * IETab Switcher (by LarsJ ) * HTML Entities * _IEquerySelectorAll() (by uncommon) * 

I encourage you to read: * Global Vars * Best Coding Practices * Please explain code used in Help file for several File functions * OOP-like approach in AutoIt * UDF-Spec Questions *  EXAMPLE: How To Catch ConsoleWrite() output to a file or to CMD *

"Homo sum; humani nil a me alienum puto" - Publius Terentius Afer
"Program are meant to be read by humans and only incidentally for computers and execute" - Donald Knuth, "The Art of Computer Programming"
:naughty:  :ranting:, be  :) and       \\//_.

Anticipating Errors :  "Any program that accepts data from a user must include code to validate that data before sending it to the data store. You cannot rely on the data store, ...., or even your programming language to notify you of problems. You must check every byte entered by your users, making sure that data is the correct type for its field and that required fields are not empty."

Signature last update: 2017-06-04

Share this post


Link to post
Share on other sites
On 19/3/2016 at 10:23 AM, LarsJ said:

...
Comments are welcome.
....

Hi LarsJ

could you add in your ListView* udf(s) a facility that easily allows you to set the option that will highlight only the clicked item or the single subitem clicked, (or display gridlines around selected item and subitems, as well), instead of the normal behaviour that, when an item/subitem is selected (clicked), that item and all its subitems are highlighted alltoghether...(?)


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

Share this post


Link to post
Share on other sites

Share this post


Link to post
Share on other sites

Hi

I'm palyng with this UDF and I have a dobut:
Can "Item colors" and "Alternating row colors" functions be combined together?
Here is a listing for testing where I'm trying to use both functionalities at the same time without success.
If I use Line 33 as this it works (sunday is red):

;(setting 7 alone as second parameter it works)
ListViewColorsFonts_Init( $idListView, 7  ) ; 7 = Back and fore colors

If I use Line 34 as this it works (Alternating rows colors):

; (setting 16 alone as second parameter it works)
ListViewColorsFonts_Init( $idListView, 16 ) ; 16 = Alternating row colors (for entire listview)


If I try to combine both of above In Line 35, it doesn't work.

; Combining both together it doesn't work
ListViewColorsFonts_Init($idListview, BitOR(7, 16)) ; 7 and 16  combined


What am I doing wrong? any help is welcome
Thanks

#include <GUIConstantsEx.au3>
#include <GuiListView.au3>
#include <date.au3>

#include ".\UDFs\ListViewColorsFonts.au3"
#include ".\UDFs\GuiListViewEx.au3"

Example()

Func Example()

    Local $bISO = True ; if True = 1° Day week Moonday ; if False = 1° Day week Sunday
    Local $aDaysOfWeek, $sDaysOfWeekISO, $iDayLen = 3
    For $i = 1 To 7
        $sDaysOfWeekISO &= StringLeft(_DateDayOfWeek($i, $DMW_LOCALE_LONGNAME), $iDayLen) & "|"
    Next
    $sDaysOfWeekISO = ($bISO) ? StringMid($sDaysOfWeekISO, $iDayLen + 2) & StringLeft($sDaysOfWeekISO, $iDayLen) : StringLeft($sDaysOfWeekISO, $iDayLen * 7 + 6) ;
    $aDaysOfWeek = StringSplit($sDaysOfWeekISO, '|')
    ; _ArrayDisplay($aDaysOfWeek,$sDaysOfWeekISO)

    Local $hGui = GUICreate("ListView test", 1300, 500)

    ; Create the "skeleton" of the ListView (an empty ListView)
    Local $iColumns = 32 ; desired columns in the ListView (0 to 31)
    Local $iRows = 12 ; nr. of rows (in addition to the header)
    Local $sColumns = StringReplace(StringFormat('%' & $iColumns & 's', ""), " ", '|') ; as many separators as desired nr. of columns
    Local $idListview = GUICtrlCreateListView($sColumns, 2, 2, 1296, 496, Default, BitOR($LVS_EX_FULLROWSELECT, $LVS_EX_DOUBLEBUFFER, $LVS_EX_GRIDLINES))
    For $i = 1 To 12 ; create the rows (in addition to the header)
        GUICtrlCreateListViewItem($sColumns, $idListview)
    Next

    ; Initialize ListView to support alternating row colors
     ListViewColorsFonts_Init( $idListView, 7  ) ; 7 = Back and fore colors                             <--- this alone works OK
    ;~ ListViewColorsFonts_Init( $idListView, 16 ) ; 16 = Alternating row colors (for entire listview)      <--- this alone works OK
    ;~ ListViewColorsFonts_Init($idListview, BitOR(7, 16)) ; 7 and 16  combined                             <--- above combined together doesn't work ???

    ListViewColorsFonts_SetAlternatingColors($idListview, _
            1, 1, _           ; $iRows        = 1,        $iCols        = 1
            0xCCFFFF, -1) ; $iBackColor   = Cyan,     $iForeColor   = Default (black)


    GUISetState(@SW_SHOW)

    ; Fill all rows and columns with wanted data
    _GUICtrlListView_BeginUpdate($idListview)

    ; Set columns (headers)
    _GUICtrlListView_SetColumn($idListview, 0, @YEAR, 140, 0) ; First column header (Year)
    For $i = 1 To 31 ; Days of month
        _GUICtrlListView_SetColumn($idListview, $i, $i, 37)
    Next

    ; Set items Text
    Local $iYear = @YEAR, $iDayOfWeek
    For $iMonth = 1 To 12
        _GUICtrlListView_SetItemText($idListview, $iMonth - 1, _DateToMonth($iMonth, $DMW_LOCALE_LONGNAME)) ; Month name
        for $iDay = 1 To _DateDaysInMonth($iYear, $iMonth)
            $iDayOfWeek = ($bISO) ? _DateToDayOfWeekISO($iYear, $iMonth, $iDay) : _DateToDayOfWeek($iYear, $iMonth, $iDay)
            _GUICtrlListView_SetItemText($idListview, $iMonth - 1, $aDaysOfWeek[$iDayOfWeek], $iDay)
            If _DateToDayOfWeekISO($iYear, $iMonth, $iDay) = 7 Then
                ListViewColorsFonts_SetItemColors($idListview, $iMonth - 1, $iDay, 0xCCCCFF, 0xFF0000) ; Blue,   Red
            EndIf
        Next ; Next day
    Next; Next Month

    ; Set Today Green
    ListViewColorsFonts_SetItemColors($idListview, @MON - 1, @MDAY,  0x00FF00, 0xFF0000) ; Blue,   Green

    ; Adjust height of GUI and ListView to fit ten rows
    Local $iLvHeight = _GUICtrlListView_GetHeightToFitRows($idListview, $iRows)
    WinMove($hGui, "", Default, Default, Default, WinGetPos($hGui)[3] - WinGetClientSize($hGui)[1] + $iLvHeight + 20)
    WinMove($idListview, "", Default, Default, Default, $iLvHeight)

    ; Redraw listview
    ListViewColorsFonts_Redraw($idListview)
    _GUICtrlListView_EndUpdate($idListview)

    ; Loop until the user exits.
    Do
    Until GUIGetMsg() = $GUI_EVENT_CLOSE
    GUIDelete()
EndFunc   ;==>Example

 

1 person likes this

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

Share this post


Link to post
Share on other sites

That was a lot of columns. You are not doing anything wrong but flags 7 and 16 cannot be combined. Item colors (flag 7) and alternating row colors (flag 16) are drawn by two different functions. And a listview can only use one drawing function.

If you had checked @error you would have seen @error = 2 with this description in the UDF:

2 - $fColorsFonts is invalid or an invalid combination of otherwise valid flags

I'll take a closer look tomorrow and see if I can do something.

Regards Lars.

Share this post


Link to post
Share on other sites

That was easy. Check the code. Weekdays and months are in danish on my PC. Nice.

#include <GUIConstantsEx.au3>
#include <date.au3>

#include ".\UDFs\ListViewColorsFonts.au3"
#include ".\UDFs\GuiListViewEx.au3"

Example()

Func Example()

    Local $bISO = True ; if True = 1° Day week Moonday ; if False = 1° Day week Sunday
    Local $aDaysOfWeek, $sDaysOfWeekISO, $iDayLen = 3
    For $i = 1 To 7
        $sDaysOfWeekISO &= StringLeft(_DateDayOfWeek($i, $DMW_LOCALE_LONGNAME), $iDayLen) & "|"
    Next
    $sDaysOfWeekISO = ($bISO) ? StringMid($sDaysOfWeekISO, $iDayLen + 2) & StringLeft($sDaysOfWeekISO, $iDayLen) : StringLeft($sDaysOfWeekISO, $iDayLen * 7 + 6) ;
    $aDaysOfWeek = StringSplit($sDaysOfWeekISO, '|')
    ; _ArrayDisplay($aDaysOfWeek,$sDaysOfWeekISO)

    Local $hGui = GUICreate("ListView test", 1300, 500)

    ; Create the "skeleton" of the ListView (an empty ListView)
    Local $iColumns = 32 ; desired columns in the ListView (0 to 31)
    Local $iRows = 12 ; nr. of rows (in addition to the header)
    Local $sColumns = StringReplace(StringFormat('%' & $iColumns & 's', ""), " ", '|') ; as many separators as desired nr. of columns
    Local $idListview = GUICtrlCreateListView($sColumns, 2, 2, 1296, 496, Default, BitOR($LVS_EX_FULLROWSELECT, $LVS_EX_DOUBLEBUFFER, $LVS_EX_GRIDLINES))
    For $i = 1 To 12 ; create the rows (in addition to the header)
        GUICtrlCreateListViewItem($sColumns, $idListview)
    Next

    ; Initialize ListView to support alternating row colors
     ListViewColorsFonts_Init( $idListView, 7  ) ; 7 = Back and fore colors                             <--- this alone works OK

    ; Set columns (headers)
    _GUICtrlListView_SetColumn($idListview, 0, @YEAR, 140, 0) ; First column header (Year)
    For $i = 1 To 31 ; Days of month
        _GUICtrlListView_SetColumn($idListview, $i, $i, 37)
    Next

    ; Set items Text
    Local $iYear = @YEAR, $iDayOfWeek
    For $iMonth = 1 To 12
        _GUICtrlListView_SetItemText($idListview, $iMonth - 1, _DateToMonth($iMonth, $DMW_LOCALE_LONGNAME)) ; Month name
        If Not Mod( $iMonth, 2 ) Then ListViewColorsFonts_SetItemColors($idListview, $iMonth - 1, -1, 0xCCFFFF ) ; Cyan <<<<<<<<<<<<
        ;If Mod( $iMonth, 6 ) > 2 Then ListViewColorsFonts_SetItemColors($idListview, $iMonth, -1, 0xCCFFFF ) ; Cyan, quarters
        for $iDay = 1 To _DateDaysInMonth($iYear, $iMonth)
            $iDayOfWeek = ($bISO) ? _DateToDayOfWeekISO($iYear, $iMonth, $iDay) : _DateToDayOfWeek($iYear, $iMonth, $iDay)
            _GUICtrlListView_SetItemText($idListview, $iMonth - 1, $aDaysOfWeek[$iDayOfWeek], $iDay)
            If _DateToDayOfWeekISO($iYear, $iMonth, $iDay) = 7 Then
                ListViewColorsFonts_SetItemColors($idListview, $iMonth - 1, $iDay, 0xCCCCFF, 0xFF0000) ; Blue,   Red
            EndIf
        Next ; Next day
    Next; Next Month

    ; Set Today Green
    ListViewColorsFonts_SetItemColors($idListview, Int(@MON)-1, Int(@MDAY),  0x00FF00, 0xFF0000) ; Blue,   Green

    ; Adjust height of GUI and ListView to fit ten rows
    Local $iLvHeight = _GUICtrlListView_GetHeightToFitRows($idListview, $iRows)
    WinMove($hGui, "", Default, Default, Default, WinGetPos($hGui)[3] - WinGetClientSize($hGui)[1] + $iLvHeight + 4 )
    WinMove(GUICtrlGetHandle($idListview), "", Default, Default, Default, $iLvHeight + 4 ) ; 4 additional pixels to account for gridlines

    ; Redraw listview
    ListViewColorsFonts_Redraw($idListview)

    GUISetState(@SW_SHOW)

    ; Loop until the user exits.
    Do
    Until GUIGetMsg() = $GUI_EVENT_CLOSE
    GUIDelete()
EndFunc   ;==>Example

 

1 person likes this

Share this post


Link to post
Share on other sites

Hi @LarsJ
Thanks for the answer(s) and for the working code.
I see, setting SubItem value to -1 will affect the entire row
You are the boss of the ListViews  :P

Thank You.


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

Share this post


Link to post
Share on other sites

#19 ·  Posted (edited)

Hi LarsJ, sorry, but I'm again stuck on this little issue,

I use only the ListViewColorsFonts_SetItemColorsFonts() function to set styles on items and subitems (without mixing it with other setting functions), but I got a little problem and I don't know if it's a bug, or if I am doing an improper use of this function.

See line 61 on the listing, where I try to change the font and style just for "today's" cell, the new font and style (bold) is repeated also for the next cells on the same row (till next sunday's cell).

also, if I comment out line 47, where I set the background pink color for the entire row of current month, then problem of the repetition of the bold style on line 61 doesn't arise instead.... I'm a bit confused about this behaviour of the udf....

What am I doing wrong?

Thanks a lot for any advise.

#include <GUIConstantsEx.au3>
#include <date.au3>
#include ".\UDFs\ListViewColorsFonts.au3"
#include ".\UDFs\GuiListViewEx.au3"

Example()

Func Example()
    Local $bISO = True ; if True = 1° Day week Moonday ; if False = 1° Day week Sunday
    Local $aDaysOfWeek, $sDaysOfWeekISO, $iDayLen = 3
    For $i = 1 To 7
        $sDaysOfWeekISO &= StringLeft(_DateDayOfWeek($i, $DMW_LOCALE_LONGNAME), $iDayLen) & "|"
    Next
    $sDaysOfWeekISO = ($bISO) ? StringMid($sDaysOfWeekISO, $iDayLen + 2) & StringLeft($sDaysOfWeekISO, $iDayLen) : StringLeft($sDaysOfWeekISO, $iDayLen * 7 + 6) ;
    $aDaysOfWeek = StringSplit($sDaysOfWeekISO, '|')
    ; _ArrayDisplay($aDaysOfWeek,$sDaysOfWeekISO)

    Local $hGui = GUICreate("ListView test", 1300, 500)

    ; Create the "skeleton" of the ListView (an empty ListView)
    Local $iColumns = 32 ; desired columns in the ListView (0 to 31)
    Local $iRows = 12 ; nr. of rows (in addition to the header)
    Local $sColumns = StringReplace(StringFormat('%' & $iColumns & 's', ""), " ", '|') ; as many separators as desired nr. of columns
    Local $idListview = GUICtrlCreateListView($sColumns, 2, 2, 1296, 496, Default, BitOR($LVS_EX_FULLROWSELECT, $LVS_EX_DOUBLEBUFFER, $LVS_EX_GRIDLINES))
    For $i = 1 To 12 ; create the rows (in addition to the header)
        GUICtrlCreateListViewItem($sColumns, $idListview)
    Next

    ; Initialize ListView
    ListViewColorsFonts_Init($idListview, 7) ; 7 = Back and fore colors
    Local $iYear = @YEAR, $iDayOfWeek
    ; Set columns (headers)
    _GUICtrlListView_SetColumn($idListview, 0, $iYear, 140, 0) ; First column header (Year)

    For $i = 1 To 31 ; Days of month
        _GUICtrlListView_SetColumn($idListview, $i, $i, 37)
    Next

    ; Set items Text
    For $iMonth = 1 To 12 ; scan all months (each month for each listview row)
        _GUICtrlListView_SetItemText($idListview, $iMonth - 1, _DateToMonth($iMonth, $DMW_LOCALE_LONGNAME)) ; Month name

        ; altenating rows background color
        If Not Mod($iMonth, 2) Then ListViewColorsFonts_SetItemColorsFonts($idListview, $iMonth - 1, -1, "", 0, 0xCCFFFF)

        ; set background color of current month ; current month pink on the entire row
        If @MON = $iMonth Then ListViewColorsFonts_SetItemColorsFonts($idListview, $iMonth - 1, -1, "", 0, 0xFFCCCC)

        ; set day of week on each cell of the current month
        For $iDay = 1 To _DateDaysInMonth($iYear, $iMonth)
            $iDayOfWeek = ($bISO) ? _DateToDayOfWeekISO($iYear, $iMonth, $iDay) : _DateToDayOfWeek($iYear, $iMonth, $iDay)
            _GUICtrlListView_SetItemText($idListview, $iMonth - 1, $aDaysOfWeek[$iDayOfWeek], $iDay)

            If _DateToDayOfWeekISO($iYear, $iMonth, $iDay) = 7 Then ; is it Sunday ? set colour for sunday
                ListViewColorsFonts_SetItemColorsFonts($idListview, $iMonth - 1, $iDay, "", 0, 0xCCCCFF, 0xFF0000) ; Blue,   Red
            EndIf
        Next ; Next day
    Next; Next Month

    ; Set font, color and style only for 'Today' (Bold, green background, blue forground)
    ListViewColorsFonts_SetItemColorsFonts($idListview, Int(@MON) - 1, Int(@MDAY), "Arial Black", $iFontStyleBold, 0x00ff00, 0x0000FF)

    ; Adjust height of GUI and ListView to fit ten rows
    Local $iLvHeight = _GUICtrlListView_GetHeightToFitRows($idListview, $iRows)
    WinMove($hGui, "", Default, Default, Default, WinGetPos($hGui)[3] - WinGetClientSize($hGui)[1] + $iLvHeight + 4)
    WinMove(GUICtrlGetHandle($idListview), "", Default, Default, Default, $iLvHeight + 4) ; 4 additional pixels to account for gridlines

    ; Redraw listview
    ListViewColorsFonts_Redraw($idListview)

    GUISetState(@SW_SHOW)

    ; Loop until the user exits.
    Do
    Until GUIGetMsg() = $GUI_EVENT_CLOSE
    GUIDelete()
EndFunc   ;==>Example

 

Edited by Chimp
1 person likes this

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

Share this post


Link to post
Share on other sites

#20 ·  Posted (edited)

Chimp, You are not doing anything wrong. This is a bug. Thank you. When SubItem is -1 and the font is the default font, I had simply forgot to handle the font. Sorry. Fixed in the zip. I'll test the code over the weekend for any unforeseen side effects.

ListViewColorsFonts.7z

Edited by LarsJ
1 person likes this

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