//------------------------------------------------------------------------------
/// <copyright from='2004' to='2005' company='Christian Forsberg'>
///		Copyright (c) Christian Forsberg, chris@businessanyplace.net.
///
///   This program is distributed in the hope that it will be useful,
///   but WITHOUT ANY WARRANTY; without even the implied warranty of
///   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
/// </copyright>
//------------------------------------------------------------------------------
using System;
using System.Runtime.InteropServices;

namespace TaskManager
{
	/// <summary>
	/// Summary description for Helper.
	/// </summary>
	public class ListViewHelper
	{
    private const uint LVM_GETEXTENDEDLISTVIEWSTYLE = 0x1000 + 55;
    private const uint LVM_SETEXTENDEDLISTVIEWSTYLE = 0x1000 + 54;
    private const uint LVM_GETTOPINDEX = 0x1000 + 39;
    private const int LVS_EX_GRIDLINES = 0x1;
    private const int LVS_EX_GRADIENT = 0x20000000;

    public ListViewHelper()
		{
		}

    public static void SetGradient(System.Windows.Forms.ListView listView)
    {
      //listView.Capture = true;
      //IntPtr hWnd = GetCapture();
      int extendedStyle = SendMessage(listView.Handle, LVM_GETEXTENDEDLISTVIEWSTYLE, 0, 0);
      extendedStyle |= LVS_EX_GRADIENT;
      SendMessage(listView.Handle, LVM_SETEXTENDEDLISTVIEWSTYLE, 0, extendedStyle);
      //listView.Capture = false;
      listView.Refresh();
    } 

    public static int GetTopIndex(System.Windows.Forms.ListView listView)
    {
      //listView.Capture = true;
      //IntPtr hWnd = GetCapture();
        int topIndex = SendMessage(listView.Handle, LVM_GETTOPINDEX, 0, 0);
      //listView.Capture = false;
      listView.Refresh();
      return topIndex;
    }

    public static void SetGridLines(System.Windows.Forms.ListView listView)
    {
      //listView.Capture = true;
      //IntPtr hWnd = GetCapture();
        int extendedStyle = SendMessage(listView.Handle, LVM_GETEXTENDEDLISTVIEWSTYLE, 0, 0);
      extendedStyle |= LVS_EX_GRIDLINES;
      SendMessage(listView.Handle, LVM_SETEXTENDEDLISTVIEWSTYLE, 0, extendedStyle);
      //listView.Capture = false;
      listView.Refresh();
    }

    
    //[DllImport("coredll.dll")]
    //private static extern IntPtr GetCapture(); 

    [DllImport("coredll.dll")]
    private static extern int SendMessage(IntPtr hWnd, uint wMsg, int wParam, int lParam);
    
  }
}
