// MenuImageManager_Dlg.cpp : 实现文件
//

#include "stdafx.h"
#include "CombineSubjectDrawTest.h"
#include "MenuImageManager_Dlg.h"
#include "afxdialogex.h"

#include "ChildView.h"
#include "PublicObj.h"
// CMenuImageManager_Dlg 对话框

IMPLEMENT_DYNAMIC(CMenuImageManager_Dlg, CDialogEx)

CMenuImageManager_Dlg::CMenuImageManager_Dlg(CWnd* pParent /*=NULL*/)
	: CDialogEx(IDD_DIALOG_IMAGE, pParent)
{
	m_pParent = NULL;
}

CMenuImageManager_Dlg::~CMenuImageManager_Dlg()
{
}

void CMenuImageManager_Dlg::DoDataExchange(CDataExchange* pDX)
{
	CDialogEx::DoDataExchange(pDX);
	DDX_Control(pDX, IDC_LIST_FILE, m_file_list);
}


BEGIN_MESSAGE_MAP(CMenuImageManager_Dlg, CDialogEx)
	ON_BN_CLICKED(IDC_PIC_BTN, &CMenuImageManager_Dlg::OnBnClickedPicBtn)
	ON_BN_CLICKED(IDOK, &CMenuImageManager_Dlg::OnBnClickedOk)
	ON_NOTIFY(NM_DBLCLK, IDC_LIST_FILE, &CMenuImageManager_Dlg::OnNMDblclkListFile)
END_MESSAGE_MAP()


// CMenuImageManager_Dlg 消息处理程序
void CMenuImageManager_Dlg::SetFileParent(CChildView* pIn)
{
	m_pParent = pIn;
}

void CMenuImageManager_Dlg::OnBnClickedPicBtn()
{
	//TCHAR szFilter[] = _T("JPG(*.jpg)|*.jpg|PNG(*.png)|*.png|BMP(*.bmp)|*.bmp||");
	//CFileDialog fileDlg(TRUE, _T("png"), NULL, 0, szFilter, this);
	//CString strFilePath;
	//if (fileDlg.DoModal() == IDOK)
	//{
	//	strFilePath = fileDlg.GetPathName();
	//	 
	//	long lImageID = g_image_mgr.AddFile(strFilePath);
	//	if (lImageID > 0)
	//	{
	//		CString strValue;
	//		strValue.Format(_T("%d"), lImageID);
	//		int nItem = m_file_list.InsertItem(m_file_list.GetItemCount(), strValue);
	//		m_file_list.SetItemText(nItem, 1, strFilePath);
	//		m_file_list.SetItemData(nItem, lImageID);
	//	
	//		 
	//		if (m_pParent != NULL)
	//		{
	//			m_pParent->AddFile(g_image_mgr.GetFileByIdx(lImageID));
	//		}
	//	}
	//	
	//	 
	//}
}


BOOL CMenuImageManager_Dlg::OnInitDialog()
{
	CDialogEx::OnInitDialog();

	//m_file_list.SetExtendedStyle(LVS_EX_FULLROWSELECT | LVS_EX_GRIDLINES);
	//m_file_list.InsertColumn(0, _T("图像ID"),LVCFMT_LEFT, 150);
	//m_file_list.InsertColumn(1, _T("图像文件名"), LVCFMT_LEFT, 260*2);

	//CArray<CImageFileManager::stFileInfo*, CImageFileManager::stFileInfo*> tmpArray;
	//g_image_mgr.GetAllFileInfo(tmpArray);

	//CString strValue;
	//for (int i = 0; i < tmpArray.GetSize(); i++)
	//{
	//	CImageFileManager::stFileInfo* pInfo = tmpArray.GetAt(i);
	//	strValue.Format(_T("%d"), pInfo->lImageIdx);
	//	int nItem = m_file_list.InsertItem(m_file_list.GetItemCount(),strValue);
	//	m_file_list.SetItemText(nItem,1,pInfo->strFileName);
	//	m_file_list.SetItemData(nItem, pInfo->lImageIdx);
	//}
	return TRUE;  // return TRUE unless you set the focus to a control
				  // 异常: OCX 属性页应返回 FALSE
}


void CMenuImageManager_Dlg::OnBnClickedOk()
{
	// TODO: 在此添加控件通知处理程序代码
	CDialogEx::OnOK();
}


void CMenuImageManager_Dlg::OnNMDblclkListFile(NMHDR *pNMHDR, LRESULT *pResult)
{
	//LPNMITEMACTIVATE pNMItemActivate = reinterpret_cast<LPNMITEMACTIVATE>(pNMHDR);
	// 

	//long lImageIdx = m_file_list.GetItemData(pNMItemActivate->iItem);
	//if (m_pParent != NULL)
	//{
	//	m_pParent->SeekFile(lImageIdx);
	//}

	*pResult = 0;
}
