// VideoView.cpp : implementation file
//

#include "stdafx.h"
#include "LT_UVC_MFCDlg.h"
#include "VideoView.h"
#include "LT_UVC_MFCDlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CVideoView
extern Video_Parame g_VideoSystemParamter;
CVideoView::CVideoView()
{
}

CVideoView::~CVideoView()
{
}


BEGIN_MESSAGE_MAP(CVideoView, CStatic)
	//{{AFX_MSG_MAP(CVideoView)
	ON_WM_LBUTTONDBLCLK()
	ON_WM_LBUTTONDOWN()
	ON_WM_PAINT()
	//}}AFX_MSG_MAP
	ON_WM_RBUTTONDOWN()
	ON_COMMAND(ID_VIDEOSETTING_MU, &CVideoView::OnVideosettingMu)
	ON_COMMAND(ID_VIDEOSETTING_CLOSEVIDEO, &CVideoView::OnVideosettingClosevideo)
	ON_COMMAND(ID_VIDEOSETTING_AUDIOPLAY, &CVideoView::OnVideosettingAudioplay)
	ON_COMMAND(ID_VIDEOSETTING_PAUSEAUDIO, &CVideoView::OnVideosettingPauseaudio)
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CVideoView message handlers

void CVideoView::OnLButtonDblClk(UINT nFlags, CPoint point) 
{
	// TODO: Add your message handler code here and/or call default
	AfxGetMainWnd()->PostMessage(WM_VIEW_DBCLICK,m_nIndex,(LPARAM)this);
	CStatic::OnLButtonDblClk(nFlags, point);
}

void CVideoView::OnLButtonDown(UINT nFlags, CPoint point) 
{
	// TODO: Add your message handler code here and/or call default
	AfxGetMainWnd()->PostMessage(WM_VIEW_CLICK,m_nIndex,(LPARAM)this);
	CStatic::OnLButtonDown(nFlags, point);
}

void CVideoView::PreSubclassWindow() 
{
	// TODO: Add your specialized code here and/or call the base class
	this->ModifyStyle(NULL,SS_NOTIFY);
	CStatic::PreSubclassWindow();
}

void CVideoView::OnPaint() 
{
	CPaintDC dc(this); // device context for painting
	
	// TODO: Add your message handler code here
	COLORREF g_OverlayColor = RGB(1, 0, 0);
	CRect rect;
	this->GetClientRect(&rect);
	dc.FillSolidRect(&rect,g_OverlayColor);
	// Do not call CStatic::OnPaint() for painting messages
}


void CVideoView::OnRButtonDown(UINT nFlags, CPoint point)
{
	// TODO: 在此添加消息处理程序代码和/或调用默认值
	if((g_VideoSystemParamter.m_Max_Video_Channels>0)||(g_VideoSystemParamter.m_Max_Audio_Channels>0))
	{
			CPoint pt;
            GetCursorPos(&pt);/// 获取当前鼠标的位置
            CMenu menuObject;
			//if(g_save_file_ctl.m_curr_lan == 0)
            menuObject.LoadMenu(IDR_VIDEO_MENU);/// IDR_MENU_NOTIFYICON为菜单资源
			//else
			// menuObject.LoadMenu(IDR_MENU_TRAY_EN);/// IDR_MENU_NOTIFYICON为菜单资源
            CMenu *pSubMenu = menuObject.GetSubMenu(0);
            if(NULL != pSubMenu)
            {
                /// 前置窗口，为了能够捕捉窗口消息
                this->SetForegroundWindow();
                /// 弹出菜单
                pSubMenu->TrackPopupMenu(TPM_LEFTALIGN|TPM_RIGHTBUTTON,pt.x,pt.y,this);
            }
	}
	CStatic::OnRButtonDown(nFlags, point);
}


void CVideoView::OnVideosettingMu()
{
	// TODO: 在此添加命令处理程序代码
	// TODO: 在此添加命令处理程序代码
	CLT_UVC_MFCDlg*  dlg1 = (CLT_UVC_MFCDlg*)this->GetParent();
	dlg1->OnSet(m_nIndex);
}


void CVideoView::OnVideosettingClosevideo()
{
	// TODO: 在此添加命令处理程序代码
	CLT_UVC_MFCDlg*  dlg1 = (CLT_UVC_MFCDlg*)this->GetParent();
	dlg1->CloseVideo(m_nIndex);
	dlg1->CloseAudio(m_nIndex);
}


void CVideoView::OnVideosettingAudioplay()
{
	// TODO: 在此添加命令处理程序代码
	AudioOutPlay(m_nIndex);
}


void CVideoView::OnVideosettingPauseaudio()
{
	// TODO: 在此添加命令处理程序代码
	AudioOutPause(m_nIndex);
}
