ExtListView.cs 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. using System;
  2. using System.Runtime.InteropServices;
  3. using System.Windows.Forms;
  4. namespace FastReport.Controls
  5. {
  6. internal sealed class ExtListView : ListView
  7. {
  8. public event EventHandler FetchMoreItems;
  9. private void OnScroll()
  10. {
  11. var scrollInfo = GetFullScrollInfo(false);
  12. if (scrollInfo.nMax - scrollInfo.nPage < scrollInfo.nPos)
  13. {
  14. FetchMoreItems?.Invoke(this, EventArgs.Empty);
  15. }
  16. }
  17. protected override void WndProc(ref Message m)
  18. {
  19. base.WndProc(ref m);
  20. if (m.Msg == 0x115 || (m.Msg == 0x114) || (m.Msg == 0x020A))
  21. {
  22. //Trap WM_VSCROLL
  23. this.OnScroll();
  24. }
  25. }
  26. private const int SIF_RANGE = 0x0001;
  27. private const int SIF_PAGE = 0x0002;
  28. private const int SIF_POS = 0x0004;
  29. private const int SIF_TRACKPOS = 0x0010;
  30. private const int SIF_ALL = (SIF_RANGE | SIF_PAGE | SIF_POS | SIF_TRACKPOS);
  31. private const int SB_HORZ = 0;
  32. private const int SB_VERT = 1;
  33. [StructLayout(LayoutKind.Sequential)]
  34. private class SCROLLINFO
  35. {
  36. public int cbSize = Marshal.SizeOf(typeof(SCROLLINFO));
  37. public int fMask;
  38. public int nMin;
  39. public int nMax;
  40. public int nPage;
  41. public int nPos;
  42. public int nTrackPos;
  43. }
  44. [DllImport("user32.dll", CharSet = CharSet.Auto, ExactSpelling = true)]
  45. private static extern bool GetScrollInfo(IntPtr hWnd, int fnBar, SCROLLINFO scrollInfo);
  46. private SCROLLINFO GetFullScrollInfo(bool horizontalBar)
  47. {
  48. int fnBar = (horizontalBar ? SB_HORZ : SB_VERT);
  49. SCROLLINFO scrollInfo = new SCROLLINFO();
  50. scrollInfo.fMask = SIF_ALL;
  51. if (GetScrollInfo(Handle, fnBar, scrollInfo))
  52. return scrollInfo;
  53. else
  54. return null;
  55. }
  56. }
  57. }