PlanetSquires Forums

Please login or register.

Login with username, password and session length
Advanced search  
Pages: [1] 2

Author Topic: WinFBE - 2.0.2 - ListView  (Read 578 times)

SeaVipe

  • Senior Member
  • ***
  • Posts: 277
  • Windows 10
WinFBE - 2.0.2 - ListView
« on: December 22, 2019, 03:55:37 PM »

Hi Paul,
I've had GetLastError() = 6, AfxGetWinErrMsg: "The handle is invalid." somewhere in my code that wasn't causing my error trapping to fire. (On Error GoTo...)
It turns out to be in the Event frmMain_Load.
Code: [Select]
'' GetLastError() = 0
'' This code functions correctly, populating the ListView header
With frmMain.ListView1 '' <-- This does not throw an error
    ? .Items.Count    '' <-- This does not throw Windows error 6, with the following lines are commented out. Prints 0
    '' Any if these cause "The handle is invalid." error
   .Items.Clear
   .Columns.Add( "Time",     50, TextAlignment.Center )
   .Columns.Add( "Entry",    720, TextAlignment.Left  )
   .Columns.Add( "ID",       45, TextAlignment.Center )
   .Columns.Add( "Event",    90, TextAlignment.Center )
End With
'' GetLastError() = 6
With/End With makes no difference.
« Last Edit: December 22, 2019, 04:08:51 PM by SeaVipe »
Logged
Clive Richey
There is nothing government can give you that it hasn't already taken from you in the first place. Winston Churchill

Paul Squires

  • Administrator
  • Guru Member
  • *****
  • Posts: 8974
  • Windows 10
    • PlanetSquires Software
Re: WinFBE - 2.0.2 - ListView
« Reply #1 on: December 23, 2019, 08:21:55 AM »

Thanks Clive I am able to reproduce this. Seems to be somewhat related to the win api call I make in the Clear method to set the number of items of the listview (SetItemCountEx). Seems to be, but I'm not 100% sure yet. I haven't had much programming time since Christmas has started.
Logged
Paul Squires
PlanetSquires Software
WinFBE Editor and Visual Designer

SeaVipe

  • Senior Member
  • ***
  • Posts: 277
  • Windows 10
Re: WinFBE - 2.0.2 - ListView
« Reply #2 on: December 24, 2019, 03:32:36 PM »

Hi Paul, something for after the holidays:
My app started crashing at:
Code: [Select]
frmMain.ListView1.Items.ClearI moved this line to the line immediately after frmMain.ListView1.BeginUpdate and no more crashing and the ListView refreshed very fast.
Off-Topic: StatusBar appears as expected the first time a form (popup form in this case) is shown, but the StatusBar does not appear on subsiquent show/showdialog. App restart is required.
« Last Edit: December 24, 2019, 07:54:31 PM by SeaVipe »
Logged
Clive Richey
There is nothing government can give you that it hasn't already taken from you in the first place. Winston Churchill

SeaVipe

  • Senior Member
  • ***
  • Posts: 277
  • Windows 10
Re: WinFBE - 2.0.2 - ListView - Colour Changes
« Reply #3 on: January 07, 2020, 04:45:41 PM »


Hi Paul,
wfxListView.inc:
To solve a very slow refresh:
I tried commenting out AfxRedrawWindow(this.hWindow) at Lines 661 and 678 which was being called each time a fore or back colour was changed. This added approx 175ms to the refresh each time per change. So a ListView with 10 colour changes had almost 2 seconds added to when the system gave back control. (Slow enough that the Rows could be counted as they reappeared from the bottom to the top Row.)
As Refresh is required to display colour changes, after commenting out the above, I added the following to my code at the end of the colour change routine:
Code: [Select]
If IsWindowVisible( ListView.hWindow ) Then '' Probably not required.
        ListView.Refresh   
End If
Colour changes and a ListView.Refresh is now visually instantaneous on my machine.
This was just an experiment, but it worked.
Logged
Clive Richey
There is nothing government can give you that it hasn't already taken from you in the first place. Winston Churchill

Paul Squires

  • Administrator
  • Guru Member
  • *****
  • Posts: 8974
  • Windows 10
    • PlanetSquires Software
Re: WinFBE - 2.0.2 - ListView
« Reply #4 on: January 08, 2020, 08:39:07 AM »


Hi Paul,
wfxListView.inc:
To solve a very slow refresh:
I tried commenting out AfxRedrawWindow(this.hWindow) at Lines 661 and 678 which was being called each time a fore or back colour was changed. This added approx 175ms to the refresh each time per change. So a ListView with 10 colour changes had almost 2 seconds added to when the system gave back control. (Slow enough that the Rows could be counted as they reappeared from the bottom to the top Row.)
As Refresh is required to display colour changes, after commenting out the above, I added the following to my code at the end of the colour change routine:
Code: [Select]
If IsWindowVisible( ListView.hWindow ) Then '' Probably not required.
        ListView.Refresh   
End If
Colour changes and a ListView.Refresh is now visually instantaneous on my machine.
This was just an experiment, but it worked.

Hi Clive, when I uploaded version 2.0.2 on December 16th, I added code to those functions to help reduce the refresh problem. Does your code look like the following? If not, then maybe you don't have the latest code?

Code: [Select]
property wfxListViewSubItem.BackColor() as COLORREF
   property = _BackColor
end property

property wfxListViewSubItem.BackColor( byval nValue as COLORREF )
   _BackColor = nValue
   if this.hWindow THEN
      if ListView_IsItemVisible(this.hWindow, this.ItemIndex) then
         AfxRedrawWindow(this.hWindow)
      end if   
   end if
end property

property wfxListViewSubItem.ForeColor() as COLORREF
   property = _ForeColor
end property

property wfxListViewSubItem.ForeColor( byval nValue as COLORREF )
   _ForeColor = nValue
   if this.hWindow THEN
      if ListView_IsItemVisible(this.hWindow, this.ItemIndex) then
         AfxRedrawWindow(this.hWindow)
      end if   
   end if
end property
Logged
Paul Squires
PlanetSquires Software
WinFBE Editor and Visual Designer

SeaVipe

  • Senior Member
  • ***
  • Posts: 277
  • Windows 10
Re: WinFBE - 2.0.2 - ListView
« Reply #5 on: January 08, 2020, 12:22:28 PM »

Hi Paul,
Here is the code that I was referring to:
Code: [Select]

property wfxListViewSubItem.BackColor() as COLORREF
   property = _BackColor
end property

property wfxListViewSubItem.BackColor( byval nValue as COLORREF )
   _BackColor = nValue
   'if this.hWindow THEN
      'if ListView_IsItemVisible(this.hWindow, this.ItemIndex) then
         'AfxRedrawWindow(this.hWindow)
      'end if   
   'end if
end property

property wfxListViewSubItem.ForeColor() as COLORREF
   property = _ForeColor
end property

property wfxListViewSubItem.ForeColor( byval nValue as COLORREF )
   _ForeColor = nValue
   'if this.hWindow THEN
   '   if ListView_IsItemVisible(this.hWindow, this.ItemIndex) then
         'AfxRedrawWindow(this.hWindow)
   '   end if   
   'end if
end property
Logged
Clive Richey
There is nothing government can give you that it hasn't already taken from you in the first place. Winston Churchill

Paul Squires

  • Administrator
  • Guru Member
  • *****
  • Posts: 8974
  • Windows 10
    • PlanetSquires Software
Re: WinFBE - 2.0.2 - ListView
« Reply #6 on: January 08, 2020, 04:18:33 PM »

I am a little confused. You have the important lines commented out. If you uncomment them, does it speed up the coloring? Or did you comment them because you were testing for solution to slowness?
Logged
Paul Squires
PlanetSquires Software
WinFBE Editor and Visual Designer

SeaVipe

  • Senior Member
  • ***
  • Posts: 277
  • Windows 10
Re: WinFBE - 2.0.2 - ListView
« Reply #7 on: January 08, 2020, 04:42:48 PM »

Commented out - Fast update, not commented out - very Slow update.
Logged
Clive Richey
There is nothing government can give you that it hasn't already taken from you in the first place. Winston Churchill

Paul Squires

  • Administrator
  • Guru Member
  • *****
  • Posts: 8974
  • Windows 10
    • PlanetSquires Software
Re: WinFBE - 2.0.2 - ListView
« Reply #8 on: January 08, 2020, 09:15:53 PM »

Thanks Clive, I understand the problem better now. To fix it, I gave every Item and SubItem access to the flag that indicates that BeginUpdate is active. If that flag is True then I do not issue a redraw. When EndUpdate is called, a redraw is done. My few tests seem to confirm that this new logic is working correctly.
Logged
Paul Squires
PlanetSquires Software
WinFBE Editor and Visual Designer

SeaVipe

  • Senior Member
  • ***
  • Posts: 277
  • Windows 10
Re: WinFBE - 2.0.2 - ListView
« Reply #9 on: January 08, 2020, 09:22:39 PM »

Thanks, Paul!
Logged
Clive Richey
There is nothing government can give you that it hasn't already taken from you in the first place. Winston Churchill

Paul Squires

  • Administrator
  • Guru Member
  • *****
  • Posts: 8974
  • Windows 10
    • PlanetSquires Software
Re: WinFBE - 2.0.2 - ListView
« Reply #10 on: January 08, 2020, 09:29:56 PM »

Try the new files attached to this post to see how it reacts to the data in your project. Please let me know if it works and there is a speed up when BeginUpdate is activated.
Logged
Paul Squires
PlanetSquires Software
WinFBE Editor and Visual Designer

SeaVipe

  • Senior Member
  • ***
  • Posts: 277
  • Windows 10
Re: WinFBE - 2.0.2 - ListView
« Reply #11 on: January 08, 2020, 09:45:20 PM »

Hi Paul, a bit slow to populate the ListView. Very slow to apply colour changes after the ListView is populated. 6 Col x 30 Rows.
I make a lot of colour changes depending on the view. The subject portion of my main app is the Journal. It's limited to the 6 x 30 for now. The ListView gets repopulated as often as the User make additions to the day. After each modification (1 Row at a time Ex. 07:30 | User entry text | ID1 | ID2 | Type | Category ) The colours reflect the Type/Category values per Row (Reminder, Complete etc.) Plus the overall ListView has 3 default colour themes based on Past, Present and Future dates. So lots of colour changes.
« Last Edit: January 08, 2020, 09:59:44 PM by SeaVipe »
Logged
Clive Richey
There is nothing government can give you that it hasn't already taken from you in the first place. Winston Churchill

Paul Squires

  • Administrator
  • Guru Member
  • *****
  • Posts: 8974
  • Windows 10
    • PlanetSquires Software
Re: WinFBE - 2.0.2 - ListView
« Reply #12 on: January 09, 2020, 07:39:53 AM »

Interesting. For your function that applies the color changes to the rows, do you wrap that in a BeginUpdate and EndUpdate ?
I really need to figure out why such a slowdown would be seen. I will go over the code again today to see if I've missed something.
Logged
Paul Squires
PlanetSquires Software
WinFBE Editor and Visual Designer

Paul Squires

  • Administrator
  • Guru Member
  • *****
  • Posts: 8974
  • Windows 10
    • PlanetSquires Software
Re: WinFBE - 2.0.2 - ListView
« Reply #13 on: January 09, 2020, 08:31:21 AM »

...and I assume that you have the OddRowColorEnabled property set to False.
Logged
Paul Squires
PlanetSquires Software
WinFBE Editor and Visual Designer

Paul Squires

  • Administrator
  • Guru Member
  • *****
  • Posts: 8974
  • Windows 10
    • PlanetSquires Software
Re: WinFBE - 2.0.2 - ListView
« Reply #14 on: January 09, 2020, 08:45:19 AM »

For my test, I am using a 1000 row ListView with 4 columns. All cells get recolored (foreground and background) whenever I press a button. The average time to recolor is 0.015 seconds. That's pretty fast and I don't see any visual on-screen flicker.


Here is the recolor routine that I am using:

Code: [Select]
Sub set_rows_colour( byref ListView as wfxListView, ByVal bg as COLORREF, byval fg as COLORREF )
   ? "Recolor start: "
   dim as double t1, t2
   t1 = timer
   With ListView
      ' Because we are manually setting specific foreground and
      ' background colors, we do not want any color defined for
      ' the OddRowColor property to interfere.
      .OddRowColorEnabled = false
      .BeginUpdate
      For iRow as long = 0 to .Items.Count - 1
         For iCol as long = 0 to .Item(iRow).SubItems.Count - 1
            .Item(iRow).SubItem(iCol).ForeColor = fg
            .Item(iRow).SubItem(iCol).BackColor = bg
         next iCol
      Next iRow
      .EndUpdate
   End With
   t2 = timer
   ? "Recolor end: "; t2 - t1; " seconds."
End Sub
Logged
Paul Squires
PlanetSquires Software
WinFBE Editor and Visual Designer
Pages: [1] 2