// MyResListCtrl.cpp : implementation file
//

#include "stdafx.h"
#include "supervis.h"
#include "MyResListCtrl.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CMyResListCtrl

CMyResListCtrl::CMyResListCtrl()
{
}

CMyResListCtrl::~CMyResListCtrl()
{
}


BEGIN_MESSAGE_MAP(CMyResListCtrl, CListCtrl)
	//{{AFX_MSG_MAP(CMyResListCtrl)
	ON_NOTIFY_REFLECT(NM_CLICK, OnClick)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CMyResListCtrl message handlers

void CMyResListCtrl::OnClick(NMHDR* pNMHDR, LRESULT* pResult) 
{

	// Get the current mouse location and convert it to client
	// coordinates.
	DWORD pos = GetMessagePos();

	CPoint pt(LOWORD(pos), HIWORD(pos));
	ScreenToClient(&pt);

	// Get indexes of the first and last visible items in listview
	// control.
	int index = GetTopIndex();

	int last_visible_index = index + GetCountPerPage();

	if (last_visible_index > GetItemCount())
		last_visible_index = GetItemCount();

	// Loop until number visible items has been reached.

	while (index <= last_visible_index)
	{

		// Get the bounding rectangle of an item. If the mouse

		// location is within the bounding rectangle of the item,

		// you know you have found the item that was being clicked.

		CRect r;
		GetItemRect(index, &r, LVIR_BOUNDS);


		if (r.PtInRect(pt))
		{
			UINT flag = LVIS_SELECTED | LVIS_FOCUSED;

			SetItemState(index, flag, flag);

			//We add the new volume in the Volume EditBox
			CSupervisApp* pSuperVisApp = (CSupervisApp*)AfxGetApp();
			pSuperVisApp->m_SuperVisThread->SuperVisSheet->m_MixerPage.SetEditBoxVolume((unsigned long)GetItemData(index));
			break;

		}

		// Get the next item in listview control.
		index++;
	}

	
	*pResult = 0;	

}
