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

#include "stdafx.h"
#include "HansAdvInterfaceTest.h"
#include "HansAdvInterfaceTestDlg.h"

#include "math.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#endif



// 用于应用程序“关于”菜单项的 CAboutDlg 对话框

class CAboutDlg : public CDialog
{
public:
	CAboutDlg();

// 对话框数据
	enum { IDD = IDD_ABOUTBOX };

	protected:
	virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV 支持

// 实现
protected:
	DECLARE_MESSAGE_MAP()
};

CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
}

void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
}

BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
END_MESSAGE_MAP()


 void MsgFlyMarkCall(UINT uCard,int nID, UINT64 nMarkTime)
{
	CHansAdvInterfaceTestDlg* pDlg=(CHansAdvInterfaceTestDlg *)AfxGetApp()->m_pMainWnd;
	if(pDlg->Card()==uCard)
	{
	   if(nID==0)
	   {
		   UINT nTime = nMarkTime;
		  
		   CString str = _T("IO FlyMark finish...! It took ");
		   CString strTime;
		   strTime.Format(_T("%d ms."), nTime);
		   pDlg->SetNote(str+strTime);
	   }
	   else
	     pDlg->SetNote(_T("IO FlyMark Error"));
	}
}


// test
UINT Thread_TransformMark1(LPVOID para)
{
	double* xOffsets = new double[1];
	double* yOffsets = new double[1];
	double* xCenter = new double[1];
	double* yCenter = new double[1];
	double* angle = new double[1];

	for(int i=0; i<8; i++)
	{
		xOffsets[0] = 5;
		yOffsets[0] = 5;
		xCenter[0] = 5;
		yCenter[0] = 5;
		angle[0] = 30;
	}

	HS_SetTransformMarkParamEx(0, xOffsets, yOffsets, xCenter, yCenter, angle, 1);
	int nret = HS_Mark(0, 0, FALSE, TRUE, 0, FALSE);
	if(nret != HL_ERR_SUCCESS)
		AfxMessageBox(_T("1"));

	// Delete...

	return 0;
}

// test
UINT Thread_TransformMark2(LPVOID para)
{
	double* xOffsets = new double[8];
	double* yOffsets = new double[8];
	double* xCenter = new double[8];
	double* yCenter = new double[8];
	double* angle = new double[8];

	for(int i=0; i<8; i++)
	{
		xOffsets[i] = i+2 + 0.1;
		yOffsets[i] = i+2 + 0.2;
		xCenter[i] = i+2 + 0.3;
		yCenter[i] = i+2 + 0.4;
		angle[i] = i+2 + 0.5;
	}

	HS_SetTransformMarkParamEx(1, xOffsets, yOffsets, xCenter, yCenter, angle, 8);
	int nret = HS_Mark(1, 0, FALSE, TRUE, 0, TRUE);
	if(nret != HL_ERR_SUCCESS)
		AfxMessageBox(_T("2"));

	// Delete...

	return 0;
}

UINT Thread_MotorMove(LPVOID para)
{
	CHansAdvInterfaceTestDlg* pDlg = (CHansAdvInterfaceTestDlg*)para;
	if(pDlg == NULL)
		return 999;

	double dbValue[8] = {0};
	dbValue[0] = pDlg->m_dbMoveValue;
	dbValue[1] = pDlg->m_dbMoveValue1;
	dbValue[2] = pDlg->m_dbMoveValue2;
	dbValue[3] = pDlg->m_dbMoveValue3;

	int nAxisEx = (pDlg->m_bEnableAxis0) | (pDlg->m_bEnableAxis1<<1) | (pDlg->m_bEnableAxis2<<2) | (pDlg->m_bEnableAxis3<<3);

	int nRtn = HS_MoveMotorVEx(pDlg->m_uCard, nAxisEx, dbValue, pDlg->m_nMoveModel, pDlg->m_nMoveType);

	return nRtn;
}

// CHansAdvInterfaceTestDlg 对话框




CHansAdvInterfaceTestDlg::CHansAdvInterfaceTestDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CHansAdvInterfaceTestDlg::IDD, pParent)
	, m_strObjAlias(_T(""))
	, m_strObjContent(_T(""))
	, m_dbParam1(0)
	, m_dbParam2(0)
	, m_dbParam3(0)
	, m_nIsTouch(0)
	, m_bCheckTouch(FALSE)
	, m_nCheckTouchCount(0)
	, m_bMove(FALSE)
	, m_bBoxSelect(FALSE)
	, m_pntMoveStart(0, 0)
	, m_bMarking(FALSE)
	, m_bMarkingFly(FALSE)
	, m_strCfg1(_T(""))
	, m_strCfg2(_T(""))
	, m_strReadOutPort(_T(""))
	, m_strInPort(_T(""))
	, m_nMarkModel(0)
	, m_nFlyType(0)
	, m_bFlyReveral(FALSE)
	, m_dSpeed(0)
	, m_nMarkType(0)
	, m_strCurrentObjName(_T(""))
	, m_strBmpObjName(_T(""))
	, m_nPPR(0)
	, m_nMoveModel(1)
	, m_nMoveType(0)
	, m_bSoftHome(FALSE)
	, m_bEnableAxis0(TRUE)
	, m_bEnableAxis1(TRUE)
	, m_bEnableAxis2(TRUE)
	, m_bEnableAxis3(TRUE)
	, m_dbMoveValue(1)
	, m_dbMoveValue1(1)
	, m_dbMoveValue2(1)
	, m_dbMoveValue3(1)
{
	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);

	m_bInitOk = FALSE;
	m_dbViewRate = 0.75;
	m_dbViewX = 0;
	m_dbViewY = 0;
	m_uCard=0;
	m_pThreadMoveEx = NULL;
}

void CHansAdvInterfaceTestDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	DDX_Control(pDX, IDC_TAB_DOC, m_tabDoc);
	DDX_Control(pDX, IDC_COMBO_LANG, m_cbLang);
	DDX_Text(pDX, IDC_EDIT_ALIAS, m_strObjAlias);
	DDX_Text(pDX, IDC_EDIT_TEXT, m_strObjContent);
	DDX_Text(pDX, IDC_EDIT_PARAM1, m_dbParam1);
	DDX_Text(pDX, IDC_EDIT_PARAM2, m_dbParam2);
	DDX_Text(pDX, IDC_EDIT_PARAM3, m_dbParam3);
	DDX_Text(pDX, IDC_EDIT_ISTOUCH, m_nIsTouch);
	DDX_Check(pDX, IDC_CHECK_CHECKTOUCH, m_bCheckTouch);
	DDX_Text(pDX, IDC_EDIT_READOUTPORT, m_strReadOutPort);
	DDX_Text(pDX, IDC_EDIT_READINPORT, m_strInPort);
	DDX_Control(pDX, IDC_COMBO_WRITEOUTPORT, m_cbOutPort);
	DDX_Control(pDX, IDC_COMBO_CARD, m_cbCard);
	DDX_Radio(pDX, IDC_RADIO_MARKTYPE_NORMAL, m_nMarkModel);
	DDV_MinMaxInt(pDX, m_nMarkModel, 0, 3);
	DDX_Radio(pDX, IDC_RADIO_FLYTYPE, m_nFlyType);
	DDV_MinMaxInt(pDX, m_nFlyType, 0, 2);
	DDX_Check(pDX, IDC_CHECK_FLY_REVERSAL, m_bFlyReveral);
	DDX_Text(pDX, IDC_EDIT_FLY_PARAM, m_dSpeed);
	DDV_MinMaxDouble(pDX, m_dSpeed, 0, 999999);
	DDX_Control(pDX, IDC_COMBO_OBJECT, m_cbObjcet);
	DDX_Radio(pDX, IDC_RADIO_MARKTYPE_LASER, m_nMarkType);
	DDX_Text(pDX, IDC_EDIT_OBJNAME, m_strCurrentObjName);
	DDX_Text(pDX, IDC_EDIT_BMPNAME, m_strBmpObjName);
	DDX_Text(pDX, IDC_EDIT_FLY_PARAM2, m_nPPR);
	DDX_Radio(pDX, IDC_RADIO_AMOVE, m_nMoveModel);
	DDX_Radio(pDX, IDC_RADIO_MOVELOAD, m_nMoveType);
	DDX_Check(pDX, IDC_CHECK_SOFTHOME, m_bSoftHome);
	DDX_Check(pDX, IDC_CHECK_AXIS_0, m_bEnableAxis0);
	DDX_Check(pDX, IDC_CHECK_AXIS_1, m_bEnableAxis1);
	DDX_Check(pDX, IDC_CHECK_AXIS_2, m_bEnableAxis2);
	DDX_Check(pDX, IDC_CHECK_AXIS_3, m_bEnableAxis3);
	DDX_Text(pDX, IDC_EDIT_MOVEVALUE, m_dbMoveValue);
	DDX_Text(pDX, IDC_EDIT_MOVEVALUE_1, m_dbMoveValue1);
	DDX_Text(pDX, IDC_EDIT_MOVEVALUE_2, m_dbMoveValue2);
	DDX_Text(pDX, IDC_EDIT_MOVEVALUE_3, m_dbMoveValue3);
}

BEGIN_MESSAGE_MAP(CHansAdvInterfaceTestDlg, CDialog)
	ON_WM_SYSCOMMAND()
	ON_WM_PAINT()
	ON_WM_QUERYDRAGICON()
	//}}AFX_MSG_MAP
	ON_BN_CLICKED(IDC_BUTTON_INITSYSTEM, &CHansAdvInterfaceTestDlg::OnBnClickedButtonInitsystem)
	ON_CBN_SELCHANGE(IDC_COMBO_LANG, &CHansAdvInterfaceTestDlg::OnCbnSelchangeComboLang)
	ON_BN_CLICKED(IDC_BUTTON_RELEASESYSTEM, &CHansAdvInterfaceTestDlg::OnBnClickedButtonReleasesystem)
	ON_BN_CLICKED(IDC_BUTTON_OPENFILE, &CHansAdvInterfaceTestDlg::OnBnClickedButtonOpenfile)
	ON_BN_CLICKED(IDC_BUTTON_CLOSEFILE, &CHansAdvInterfaceTestDlg::OnBnClickedButtonClosefile)
	ON_BN_CLICKED(IDC_BUTTON_MARK, &CHansAdvInterfaceTestDlg::OnBnClickedButtonMark)
	ON_BN_CLICKED(IDC_BUTTON_STOPMARK, &CHansAdvInterfaceTestDlg::OnBnClickedButtonStopmark)
	ON_BN_CLICKED(IDC_BUTTON_GETTEXT, &CHansAdvInterfaceTestDlg::OnBnClickedButtonGettext)
	ON_BN_CLICKED(IDC_BUTTON_CHANGETEXT, &CHansAdvInterfaceTestDlg::OnBnClickedButtonChangetext)
	ON_BN_CLICKED(IDC_BUTTON_MOVE, &CHansAdvInterfaceTestDlg::OnBnClickedButtonMove)
	ON_BN_CLICKED(IDC_BUTTON_ROTATE, &CHansAdvInterfaceTestDlg::OnBnClickedButtonRotate)
	ON_NOTIFY(TCN_SELCHANGE, IDC_TAB_DOC, &CHansAdvInterfaceTestDlg::OnTcnSelchangeTabDoc)
	ON_EN_CHANGE(IDC_EDIT_ALIAS, &CHansAdvInterfaceTestDlg::OnEnChangeEditAlias)
	ON_BN_CLICKED(IDC_BUTTON_READINPORT, &CHansAdvInterfaceTestDlg::OnBnClickedButtonReadinport)
	ON_BN_CLICKED(IDC_BUTTON_WRITEOUTPORT, &CHansAdvInterfaceTestDlg::OnBnClickedButtonWriteoutport)
	ON_BN_CLICKED(IDC_BUTTON_ISTOUCH, &CHansAdvInterfaceTestDlg::OnBnClickedButtonIstouch)
	ON_BN_CLICKED(IDC_CHECK_CHECKTOUCH, &CHansAdvInterfaceTestDlg::OnBnClickedCheckChecktouch)
	ON_MESSAGE(WM_TOUCH_MSG, &CHansAdvInterfaceTestDlg::OnTouchreport)
	ON_WM_MOUSEWHEEL()
	ON_WM_MOUSEMOVE()
	ON_WM_MBUTTONDOWN()
	ON_WM_MBUTTONUP()
	ON_BN_CLICKED(IDC_BUTTON_RESETVIEW, &CHansAdvInterfaceTestDlg::OnBnClickedButtonResetview)
	ON_WM_TIMER()
	ON_BN_CLICKED(IDC_BUTTON_READOUTPORT, &CHansAdvInterfaceTestDlg::OnBnClickedButtonReadoutport)
	ON_BN_CLICKED(IDC_BUTTON_GETDOGIDINFO, &CHansAdvInterfaceTestDlg::OnBnClickedButtonGetdogidinfo)
	ON_WM_CLOSE()
	ON_BN_CLICKED(IDC_BUTTON_MARK_ALL, &CHansAdvInterfaceTestDlg::OnBnClickedButtonMarkAll)
	ON_BN_CLICKED(IDC_BUTTON_MARK_IO_FLY, &CHansAdvInterfaceTestDlg::OnBnClickedButtonMarkIoFly)
	ON_BN_CLICKED(IDC_BUTTON_MARKTYPE_SET, &CHansAdvInterfaceTestDlg::OnBnClickedButtonMarktypeSet)
	ON_CBN_SELCHANGE(IDC_COMBO_CARD, &CHansAdvInterfaceTestDlg::OnCbnSelchangeComboCard)
	ON_WM_LBUTTONDOWN()
	ON_WM_LBUTTONUP()
	ON_BN_CLICKED(IDC_BUTTON_TEST, &CHansAdvInterfaceTestDlg::OnBnClickedButtonTest)
	ON_CBN_SELCHANGE(IDC_COMBO_OBJECT, &CHansAdvInterfaceTestDlg::OnCbnSelchangeComboObject)
	ON_BN_CLICKED(IDC_BUTTON_SAVEFILE, &CHansAdvInterfaceTestDlg::OnBnClickedButtonSavefile)
	ON_BN_CLICKED(IDC_BUTTON_IMPORT, &CHansAdvInterfaceTestDlg::OnBnClickedButtonImport)
	ON_BN_CLICKED(IDC_BUTTON_DEL_OBJ, &CHansAdvInterfaceTestDlg::OnBnClickedButtonDelObj)
	ON_BN_CLICKED(IDC_BUTTON_PREPROCESSDATA, &CHansAdvInterfaceTestDlg::OnBnClickedButtonPreprocessdata)
	ON_BN_CLICKED(IDC_BUTTON_VECTOR2BITMAP, &CHansAdvInterfaceTestDlg::OnBnClickedButtonVector2bitmap)
	ON_BN_CLICKED(IDC_BUTTON_CHANGENAME, &CHansAdvInterfaceTestDlg::OnBnClickedButtonChangename)
	ON_BN_CLICKED(IDC_BUTTON_CHANGEBMP, &CHansAdvInterfaceTestDlg::OnBnClickedButtonChangebmp)
	ON_BN_CLICKED(IDC_CHECK_RED, &CHansAdvInterfaceTestDlg::OnBnClickedCheckRed)
	ON_BN_CLICKED(IDC_CHECK_SOFTHOME, &CHansAdvInterfaceTestDlg::OnBnClickedCheckSofthome)
	ON_BN_CLICKED(IDC_BUTTON_MOVEMOTOREX, &CHansAdvInterfaceTestDlg::OnBnClickedButtonMovemotorex)
	ON_BN_CLICKED(IDC_BUTTON_SOFTHOMEEX, &CHansAdvInterfaceTestDlg::OnBnClickedButtonSofthomeex)
	ON_BN_CLICKED(IDC_BUTTON_STOPRUNEX, &CHansAdvInterfaceTestDlg::OnBnClickedButtonStoprunex)
	ON_BN_CLICKED(IDC_BUTTON_ROTATEMARK, &CHansAdvInterfaceTestDlg::OnBnClickedButtonRotatemark)
	ON_BN_CLICKED(IDC_BUTTON_REF, &CHansAdvInterfaceTestDlg::OnBnClickedButtonRef)
END_MESSAGE_MAP()


// CHansAdvInterfaceTestDlg 消息处理程序

BOOL CHansAdvInterfaceTestDlg::OnInitDialog()
{
	CDialog::OnInitDialog();

	// 将“关于...”菜单项添加到系统菜单中。

	// IDM_ABOUTBOX 必须在系统命令范围内。
	ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
	ASSERT(IDM_ABOUTBOX < 0xF000);

	CMenu* pSysMenu = GetSystemMenu(FALSE);
	if (pSysMenu != NULL)
	{
		CString strAboutMenu;
		strAboutMenu.LoadString(IDS_ABOUTBOX);
		if (!strAboutMenu.IsEmpty())
		{
			pSysMenu->AppendMenu(MF_SEPARATOR);
			pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
		}
	}

	// 设置此对话框的图标。当应用程序主窗口不是对话框时，框架将自动
	//  执行此操作
	SetIcon(m_hIcon, TRUE);			// 设置大图标
	SetIcon(m_hIcon, FALSE);		// 设置小图标

	CenterWindow();
	ShowWindow(SW_SHOW);

	// TODO: 在此添加额外的初始化代码

// 	// 获取语言配置目录1
// 	TCHAR szExePath[MAX_PATH]={0};
// 	GetModuleFileName(NULL, szExePath, MAX_PATH);
// 	CString strExe(szExePath);
// 	int n = strExe.ReverseFind('\\');
// 	strExe = strExe.Left(n);
// 	n = strExe.ReverseFind('\\')+1;
// 	strExe = strExe.Left(n);
// 	m_strCfg1 = strExe + LANGUAGE_RELATIVE_PATH;
// 
// 	// 获取语言配置目录2
// 	strExe = CString(szExePath);
// 	n = strExe.ReverseFind('\\')+1;
// 	strExe = strExe.Left(n);
// 	m_strCfg2 = strExe + LANGUAGE_RELATIVE_PATH_2;
	

	// 刷新界面
	UpdateView();

	// 提示框字体设置
	CFont font;
	font.CreatePointFont(150, _T("System"), NULL);
	GetDlgItem(IDC_STATIC_NOTE)->SetFont(&font, TRUE);

// 	// 加载语言
// 	LoadLanguage();
// 
// 	// 加载语言列表
// 	for(int i=0; i<g_lang.GetLangCount(); i++)
// 	{
// 		m_cbLang.AddString(g_lang.GetLangName(i));
// 	}
// 	m_cbLang.SetCurSel(g_lang.GetCurLang());
// 
// 	// 对话框语言设置
// 	g_lang.TranslateDialog(this, IDD);


	CString outporttmp;
	for (int i= 0; i < 16; i++)
	{
		outporttmp.Format(_T("%d"),i);
		m_cbOutPort.AddString(outporttmp);
	}
	m_cbOutPort.SetCurSel(0);

	return TRUE;  // 除非将焦点设置到控件，否则返回 TRUE
}

void CHansAdvInterfaceTestDlg::OnSysCommand(UINT nID, LPARAM lParam)
{
	if ((nID & 0xFFF0) == IDM_ABOUTBOX)
	{
		CAboutDlg dlgAbout;
		dlgAbout.DoModal();
	}
	else
	{
		CDialog::OnSysCommand(nID, lParam);
	}
}

// 如果向对话框添加最小化按钮，则需要下面的代码
//  来绘制该图标。对于使用文档/视图模型的 MFC 应用程序，
//  这将由框架自动完成。

void CHansAdvInterfaceTestDlg::OnPaint()
{
	if (IsIconic())
	{
		CPaintDC dc(this); // 用于绘制的设备上下文

		SendMessage(WM_ICONERASEBKGND, reinterpret_cast<WPARAM>(dc.GetSafeHdc()), 0);

		// 使图标在工作区矩形中居中
		int cxIcon = GetSystemMetrics(SM_CXICON);
		int cyIcon = GetSystemMetrics(SM_CYICON);
		CRect rect;
		GetClientRect(&rect);
		int x = (rect.Width() - cxIcon + 1) / 2;
		int y = (rect.Height() - cyIcon + 1) / 2;

		// 绘制图标
		dc.DrawIcon(x, y, m_hIcon);
	}
	else
	{
		CDialog::OnPaint();
	}
}

//当用户拖动最小化窗口时系统调用此函数取得光标
//显示。
HCURSOR CHansAdvInterfaceTestDlg::OnQueryDragIcon()
{
	return static_cast<HCURSOR>(m_hIcon);
}


void CHansAdvInterfaceTestDlg::OnBnClickedButtonInitsystem()
{
	BeginWaitCursor();

	// 获取打标软件根目录
	TCHAR szPath[MAX_PATH]={0};
	GetModuleFileName(NULL, szPath, MAX_PATH);
	*(_tcsrchr(szPath, _T('\\'))+1) = NULL;

	int nRet = HS_InitialMachine(szPath);
	if( HL_ERR_SUCCESS == nRet || HL_ERR_DEMON_VER == nRet)
	{
		g_strPathName = szPath;
		m_bInitOk = TRUE; // 初始化状态标志
		UpdateView();

		// 插入默认图档tab并设为当前
		TCHAR* pszFile=new TCHAR[_tcslen(DFT_DOC_NAME)+1];
		_tcscpy(pszFile, DFT_DOC_NAME);
		m_tabDoc.InsertItem(TCIF_TEXT|TCIF_PARAM, 0, DFT_DOC_NAME, 0, (LPARAM)pszFile);
		SwitchDoc(pszFile);

		DWORD nCard = 0;
		HS_GetCardNumber(&nCard);
		m_cbCard.ResetContent();
		for(int i=0; i<nCard; i++)
		{
			CString str;
			str.Format(_T("Card %d"),i+1);
			m_cbCard.AddString(str);
		}

		if(nCard > 0)
		{
			m_cbCard.SetCurSel(0);
			m_uCard = 0;
		}
	}

	ShowLastError();
	
	EndWaitCursor();
	UpdateData(FALSE);
}


void CHansAdvInterfaceTestDlg::SwitchDoc(LPCTSTR lpszFile)
{
	int nRet1 = HS_SetCurDoc(m_uCard,(TCHAR *)lpszFile);		
	if( nRet1 == HL_ERR_SUCCESS )
	{
		RefleshObjList();
		Preview();
	}
	ShowLastError();
}


void CHansAdvInterfaceTestDlg::ShowLastError()
{
	int  nErr(0);
	TCHAR szBuff[200] = {0};
	HS_GetLastError(m_uCard, &nErr, szBuff, 200);
	CString strErrInfo(szBuff);
	CString strValue = g_lang.TranslateString(strErrInfo);
	if(strValue == _T(""))
		strValue = strErrInfo;
	SetDlgItemText(IDC_STATIC_NOTE, strValue);
}


void CHansAdvInterfaceTestDlg::OnCbnSelchangeComboLang()
{
	int nLang = m_cbLang.GetCurSel();
	CString strLang;
	strLang.Format(_T("%d"), nLang);

	if(nLang != -1)
	{
		CString strCfgPath = m_strCfg1 + CONFIG_FILE;
		if(!WritePrivateProfileString(_T("SYSTEMSET"), _T("LANG"), strLang, strCfgPath))
		{
			strCfgPath = m_strCfg2 + CONFIG_FILE;
			if(!WritePrivateProfileString(_T("SYSTEMSET"), _T("LANG"), strLang, strCfgPath))
			{
				SetNote(_T("Language switch failed, please check the configuration file!"));
			}
		}
	}

	LoadLanguage();
	g_lang.TranslateDialog(this, IDD);
}


void CHansAdvInterfaceTestDlg::LoadLanguage()
{
	g_lang.Clear();

	// 添加语言到变量
	CString strCfgPath1 = m_strCfg1 + CONFIG_FILE;
	CString strCfgPath2 = m_strCfg2 + CONFIG_FILE;
	g_lang.AddLang(LANGUAGE_NAME_EN_US);
	g_lang.AddLang(LANGUAGE_NAME_ZH_CN);
	g_lang.AddLang(LANGUAGE_NAME_ZH_TW);
	g_lang.AddLang(LANGUAGE_NAME_JA_JP);
	
	
	int nCurLang = GetPrivateProfileInt(_T("SYSTEMSET"), _T("LANG"), -1, strCfgPath1);
	CString strCfg = m_strCfg1;
	if(nCurLang == -1)
	{
		nCurLang = GetPrivateProfileInt(_T("SYSTEMSET"), _T("LANG"), -1, strCfgPath2);
		strCfg = m_strCfg2;
	}

	// 读取当前选择的语言（配置文件）,若读取失败，设为默认：英语
	if(nCurLang > g_lang.GetLangCount()-1  ||  nCurLang < 0)
	{
		CString strTip = _T("Failed to read the language configuration because ");
		strTip += strCfgPath1;
		strTip += _T(" or ");
		strTip += strCfgPath2;
		strTip += _T(" is corrupt or missing.\n\nClick OK to use default language.");
		MessageBox(strTip, _T("Load language configuration failed!"));

		g_lang.SetCurLang(0);
	}
	else
	{
		// 20220804 为了方便维护，取消语言设置，总是设为英文
		g_lang.SetCurLang(/*nCurLang*/0);
	}

	// 读取当前语言文件路径
	CString strLangPath;
	switch(g_lang.GetCurLang())
	{
	case 0: 
		strLangPath = strCfg + LANGUAGE_FILE_EN_US;
		break;
	case 1: 
		strLangPath = strCfg + LANGUAGE_FILE_ZH_CN;
		break;
	case 2:
		strLangPath = strCfg + LANGUAGE_FILE_ZH_TW;
		break;
	case 3:
		strLangPath = strCfg + LANGUAGE_FILE_JA_JP;
		break;
	}

	// 设置语言文件路径
	g_lang.SetLangFile(strLangPath);

	// 检查路径是否正确
	CString strSection = _T("DLG_102");
	CString strValue;
	GetPrivateProfileString(strSection, _T("1000"), _T("##"), strValue.GetBuffer(MAX_PATH), MAX_PATH, g_lang.GetLangFile());
	if(strValue == _T("##"))
	{
		CString strTip = _T("Failed to read the language file because ");
		strTip += g_lang.GetLangFile();
		strTip += _T(" is corrupt or missing.\n\nClick OK to use default language.");
		MessageBox(strTip, _T("Load language file failed!"));
	}
	strValue.ReleaseBuffer();
}


void CHansAdvInterfaceTestDlg::Preview()
{
	int nRet = HS_PreviewGraph(m_uCard,GetDlgItem(IDC_STATIC_PREVIEW)->m_hWnd, m_dbViewX, m_dbViewY, m_dbViewRate);
	if (HL_ERR_SUCCESS != nRet)
		ShowLastError();
}

void CHansAdvInterfaceTestDlg::UpdateView()
{
	// 遍历控件
	CWnd* pWndChild = NULL;
	pWndChild = GetWindow(GW_CHILD);
	while(pWndChild)
	{
		GetDlgItem(pWndChild->GetDlgCtrlID())->EnableWindow(m_bInitOk);
		pWndChild = pWndChild->GetNextWindow();
	}

	GetDlgItem(IDC_BUTTON_INITSYSTEM)->EnableWindow(!m_bInitOk);
	GetDlgItem(IDC_STATIC_LANG)->EnableWindow(TRUE);
	GetDlgItem(IDC_COMBO_LANG)->EnableWindow(TRUE);
	GetDlgItem(IDC_BUTTON_MARK)->EnableWindow(m_bInitOk && (!m_bMarking || m_bMarkingFly) ? TRUE : FALSE);
	GetDlgItem(IDC_CHECK_RED)->EnableWindow(m_bInitOk && (!m_bMarking || m_bMarkingFly) ? TRUE : FALSE);
	GetDlgItem(IDC_RADIO_MARKTYPE_LASER)->EnableWindow(m_bInitOk && (!m_bMarking || m_bMarkingFly) ? TRUE : FALSE);
	GetDlgItem(IDC_RADIO_MARKTYPE_REDLIGHT)->EnableWindow(m_bInitOk && (!m_bMarking || m_bMarkingFly) ? TRUE : FALSE);
	GetDlgItem(IDC_RADIO_MARKTYPE_REDFRAME)->EnableWindow(m_bInitOk && (!m_bMarking || m_bMarkingFly) ? TRUE : FALSE);
	GetDlgItem(IDC_BUTTON1)->EnableWindow(m_bInitOk && !m_bMarking && !m_bMarkingFly ? TRUE : FALSE);
	GetDlgItem(IDC_BUTTON3)->EnableWindow(m_bInitOk && m_nMarkModel>0 && m_nMarkModel<3 ? TRUE : FALSE);
	GetDlgItem(IDC_BUTTON_STOPMARK)->EnableWindow(m_bInitOk && (m_bMarking || m_bMarkingFly) ? TRUE : FALSE);
	SetDlgItemText(IDC_BUTTON_MARK, m_bMarkingFly ? _T("Send Fly Data") : _T("Mark"));
	
	BOOL* pRed = new BOOL;
	if(m_bInitOk && pRed)
	{
		HS_GetRedLight(m_uCard, pRed);
		((CButton *)GetDlgItem(IDC_CHECK_RED))->SetCheck(*pRed);
		delete pRed;
		pRed = NULL;
	}
}

void CHansAdvInterfaceTestDlg::SetNote(const CString& strNote)
{
	CString strValue = g_lang.TranslateString(strNote);
	if(strValue == _T(""))
		strValue = strNote;
	SetDlgItemText(IDC_STATIC_NOTE, strValue);
}

UINT CHansAdvInterfaceTestDlg::Card() const
{
	return m_uCard;
}

void CHansAdvInterfaceTestDlg::RefleshObjList()
{
	// 获取当前图档前500个对象
	TCHAR szObjList[500][20];
	int nObjCnt = 500;
	int nRet2 = HS_GetObjList(m_uCard, szObjList, &nObjCnt);
	if ( nRet2 == HL_ERR_SUCCESS )
	{
		m_cbObjcet.ResetContent();
		for (int i=0; i<nObjCnt; i++)
			m_cbObjcet.AddString(szObjList[i]);
		if(nObjCnt > 0)
			m_cbObjcet.SetCurSel(0);
	}
}

void CHansAdvInterfaceTestDlg::OnBnClickedButtonReleasesystem()
{
	BeginWaitCursor();
	int nRet = HS_CloseMachine();
	if( HL_ERR_SUCCESS == nRet )
	{
		m_bInitOk = FALSE;
		m_tabDoc.DeleteAllItems();
		UpdateView();
	}
	ShowLastError();
	EndWaitCursor();
}

void CHansAdvInterfaceTestDlg::OnBnClickedButtonOpenfile()
{
	CString strFormat1;
	CString strFormat2;
#if defined (_DEBUG_HBM) || defined (NDEBUG_HBM)
	{
		strFormat1 = _T("*.BS|*.BD|*.BR");
		strFormat2 = _T("HBM Files(*.bs;*.bd)|*.bs;*.bd||");
	}
#else
	{
		strFormat1 = _T("*.HS|*.HD|*.HR");
		strFormat2 = _T("HLM Files(*.hs;*.hd)|*.hs;*.hd||");
	}
#endif

	CFileDialog dlg(TRUE,strFormat1,NULL,OFN_HIDEREADONLY,strFormat2,NULL);
	if ( IDCANCEL == dlg.DoModal() ) 
		return;

	BeginWaitCursor();
	int nRet = HS_LoadMarkFile(m_uCard,(LPTSTR)(LPCTSTR)dlg.GetPathName());

	if ( HL_ERR_SUCCESS == nRet )
	{
		TCHAR* pszFile = new TCHAR[300];
		_tcscpy(pszFile, dlg.GetPathName());
		int nItem=m_tabDoc.GetItemCount();
		m_tabDoc.InsertItem(TCIF_TEXT|TCIF_PARAM, nItem, dlg.GetFileName(), 0, (LPARAM)pszFile);
		m_tabDoc.SetCurSel(nItem);

		SwitchDoc(pszFile);
		Preview();
	}

	ShowLastError();
	EndWaitCursor();
}

void CHansAdvInterfaceTestDlg::OnBnClickedButtonClosefile()
{
	TCITEM ti;
	ti.mask = TCIF_PARAM;
	m_tabDoc.GetItem(m_tabDoc.GetCurSel(), &ti);

	int nRet = HS_CloseMarkFile(m_uCard,(TCHAR *)(ti.lParam), FALSE);
	if( nRet == HL_ERR_SUCCESS )
	{
		delete (TCHAR*)ti.lParam;
		m_tabDoc.DeleteItem(m_tabDoc.GetCurSel());

		m_tabDoc.SetCurSel(0);
		SwitchDoc(DFT_DOC_NAME);
	}
	ShowLastError();
	Preview();
}


void CHansAdvInterfaceTestDlg::OnBnClickedButtonMark()
{
	BeginWaitCursor();
	UpdateData();

	// 非阻塞打标时，实时检测打标是否结束，并刷新界面
	SetTimer(1, 100, NULL);

	int nRet1 = HS_Mark(m_uCard
		, m_nMarkType	// 打标模式 0-激光 1-红光 2-红光边框模式
		, FALSE			// 是否等到脚踏信号才触发
		, FALSE			// TRUE-打标完才返回 FALSE-立即返回
		, 0				// 等待脚踏信号的超时时间
		, TRUE);		// TRUE-打标所有对象 FALSE-打标选中对象

	if( HL_ERR_SUCCESS == nRet1 )
		m_bMarking = TRUE;

	ShowLastError();
	UpdateView(); // 刷新 开始打标/停止打标 按钮的可用状态
	EndWaitCursor();
}

void CHansAdvInterfaceTestDlg::OnBnClickedButtonStopmark()
{
	BeginWaitCursor();

	int nRet = HS_MarkStop(m_uCard);
	ShowLastError();
	Preview();
	EndWaitCursor();
}

void CHansAdvInterfaceTestDlg::OnBnClickedButtonGettext()
{
	UpdateData(TRUE);

	int   nSize = 200; 
	WCHAR szText[200] = {0};
	TCHAR szModelName[200] = {0};

	_stprintf_s(szModelName, _T("%s"), m_strObjAlias);
	int nRet = HS_GetTextByName(m_uCard,szModelName, szText, &nSize);
	if( HL_ERR_SUCCESS != nRet )
	{
		ShowLastError();
		return;
	}

	ShowLastError();
	Preview();
	m_strObjContent = szText;
	UpdateData(FALSE);
}

void CHansAdvInterfaceTestDlg::OnBnClickedButtonChangetext()
{
	BeginWaitCursor();
	UpdateData(TRUE);

	TCHAR szAlias[200] = {0};
	_stprintf_s(szAlias, _T("%s"), m_strObjAlias);
	TCHAR szContent[200] = {0};
	_stprintf_s(szContent, _T("%s"), m_strObjContent);

	int nRet = HS_ChangeTextByName2(m_uCard, szAlias, szContent, 1);
	ShowLastError();
	Preview();	// 刷新对象修改后的预览图
	EndWaitCursor();
}

void CHansAdvInterfaceTestDlg::OnBnClickedButtonMove()
{
	BeginWaitCursor();
	UpdateData();

	int nRet = HS_Move(m_uCard,m_dbParam1, m_dbParam2);
	ShowLastError();
	Preview();
	EndWaitCursor();
}

void CHansAdvInterfaceTestDlg::OnBnClickedButtonRotate()
{
	BeginWaitCursor();
	UpdateData();

	int nRet = HS_Rotate(m_uCard,m_dbParam1, m_dbParam2, m_dbParam3);
	ShowLastError();
	Preview();
	EndWaitCursor();
}

void CHansAdvInterfaceTestDlg::OnTcnSelchangeTabDoc(NMHDR *pNMHDR, LRESULT *pResult)
{
	int nCurSel = m_tabDoc.GetCurSel();

	TCITEM ti;
	ti.mask = TCIF_PARAM;
	m_tabDoc.GetItem(nCurSel, &ti);

	SwitchDoc((LPCTSTR)(ti.lParam)); // 转换tab为切换的图档

	*pResult = 0;
}

void CHansAdvInterfaceTestDlg::OnEnChangeEditAlias()
{
	UpdateData(TRUE);

	OnBnClickedButtonGettext();
}

void CHansAdvInterfaceTestDlg::OnBnClickedButtonReadinport()
{
	BeginWaitCursor();
	DWORD m_dwInPort = 0;
	UINT nRet = HS_ReadPort(m_uCard,&m_dwInPort);
	char binary[32] = {0};
	itoa((unsigned short)m_dwInPort,binary,16);
	if ( HL_ERR_SUCCESS == nRet )
	{
		m_strInPort = CString(_T("0X")) + CString(CStringA(binary));
		UpdateData(FALSE);
	}
	
	ShowLastError();
	EndWaitCursor();
}

void CHansAdvInterfaceTestDlg::OnBnClickedButtonWriteoutport()
{
	BeginWaitCursor();
	UpdateData(TRUE);

	//控制单个IO输出口
	int state =  this->IsDlgButtonChecked(IDC_CHECK_WRITEOUTPORT);
	int bit = m_cbOutPort.GetCurSel();
	int nRet = HS_WriteOutPortBit(m_uCard,bit, state);
	ShowLastError();
/*
	for(int i=0;i<500;i++)
	{
      //HS_WriteOutPortBit(m_uCard,0, 1);
	  HS_WritePort(m_uCard,1,1);
	  Sleep(100);
	  //HS_WriteOutPortBit(m_uCard,0, 0);
	  HS_WritePort(m_uCard,0,1);
	  Sleep(100);
	}
	*/
	//控制多个ID输出口
	//int value = 3;//第0 ,1 号输出口
	//UINT nRet = HS_WritePort(m_uCard,value, 0xFFFF);

	EndWaitCursor();
}

void CHansAdvInterfaceTestDlg::OnBnClickedButtonIstouch()
{
	BeginWaitCursor();
	int nTouchFlag(0);
	UINT nRet = HS_IsTouch(m_uCard,&nTouchFlag);
	if ( HL_ERR_SUCCESS == nRet)
	{
		m_nIsTouch = nTouchFlag;
		UpdateData(FALSE);
	}

	ShowLastError();
	EndWaitCursor();
}

void CHansAdvInterfaceTestDlg::OnBnClickedCheckChecktouch()
{
	BeginWaitCursor();
	UpdateData(TRUE);

	int nRet = HS_CheckTouch(m_uCard,m_hWnd, m_bCheckTouch);
	if (nRet == HL_ERR_SUCCESS)
	{
		m_nCheckTouchCount = 0;
		CString str = _T("Count of touch signal detected:0");
		CString strValue = g_lang.TranslateString(str);
		if(strValue == _T(""))
			strValue = str;
		SetDlgItemText(IDC_STATIC_TOUCHCOUNT, strValue);
	}

	ShowLastError();
	EndWaitCursor();
}

LRESULT CHansAdvInterfaceTestDlg::OnTouchreport(WPARAM wParam, LPARAM lParam)
{
	CString strCount;
	strCount.Format(_T("%d"), ++m_nCheckTouchCount);

	CString str = _T("Count of touch signal detected:");
	CString strValue = g_lang.TranslateString(str);
	if(strValue == _T(""))
		strValue = str;

	strValue += strCount;
	SetNote(_T("A touch signal from the EMCC is received!"));
	SetDlgItemText(IDC_STATIC_TOUCHCOUNT, strValue);

	return 0;
}

BOOL CHansAdvInterfaceTestDlg::OnMouseWheel(UINT nFlags, short zDelta, CPoint pt)
{
	static double OPRATE = 1.1;

	if( m_bInitOk)
	{
		int i(0);
		int n = int(fabs(zDelta/WHEEL_DELTA*1.0));
		if( zDelta > 0 )
		{
			for(i=0;i<n;++i) 
			{
				m_dbViewRate*=OPRATE; 
			}
		}
		else
		{
			for( i=0; i<n; ++i )
			{
				m_dbViewRate/=OPRATE;
			}
		}
		Preview(); // 刷新缩放后的预览图
	}

	return CDialog::OnMouseWheel(nFlags, zDelta, pt);
}

void CHansAdvInterfaceTestDlg::OnMouseMove(UINT nFlags, CPoint point)
{
	if(m_bBoxSelect)
	{	
		if(m_pntBoxSelectStart != point)
		{
			m_rectBoxSelect = CRect(m_pntBoxSelectStart, point);
			Preview();
		}
	}

	if(m_bMove && m_bInitOk)
	{
		m_dbViewX += (m_pntMoveStart.x - point.x)/(3*m_dbViewRate);
		m_dbViewY += -(m_pntMoveStart.y - point.y)/(3*m_dbViewRate);
		m_pntMoveStart = point;
		Preview();
	}

	CDialog::OnMouseMove(nFlags, point);
}

void CHansAdvInterfaceTestDlg::OnMButtonDown(UINT nFlags, CPoint point)
{
	m_bMove = TRUE;
	m_pntMoveStart = point;

	CDialog::OnMButtonDown(nFlags, point);
}

void CHansAdvInterfaceTestDlg::OnMButtonUp(UINT nFlags, CPoint point)
{
	m_bMove = FALSE;

	CDialog::OnMButtonUp(nFlags, point);
}

void CHansAdvInterfaceTestDlg::OnBnClickedButtonResetview()
{
	m_dbViewRate = 0.75;
	m_dbViewX = 0.0;
	m_dbViewY = 0.0;
	Preview(); // 刷新重置视角后的预览图
}

void CHansAdvInterfaceTestDlg::OnTimer(UINT_PTR nIDEvent)
{
	if(nIDEvent == 1 && (m_bMarking || m_bMarkingFly))
	{      
		int nCount = m_cbCard.GetCount();
		int nFlag(1);
		for(int i=0; i<nCount; i++)
		{
			int nRet2 = HS_IsMarkEnd(i, &nFlag);

			SetNote(nFlag ? _T("Mark finish...!") : _T("Marking......!") );
			if(nFlag)
			{
				KillTimer(1);
				m_bMarking = FALSE;

				if(nRet2 == HL_ERR_WARNING || nFlag == 3)
				{
					ShowLastError();
				}
				else
				{
					UINT nTime;
					HS_GetMarkTime(m_uCard,&nTime);
					CString str = _T("Mark finish...! It took ");
					CString strValue = g_lang.TranslateString(str);
					if(strValue == _T(""))
						strValue = str;

					CString strTime;
					strTime.Format(_T("%d ms."), nTime);
					SetNote(strValue + strTime);
				}
				
				Preview(); // 刷新预览图：针对跳号/时间日期对象，因为HS_Mark会修改它们
			}
		}
	}

	// 刷新 开始打标/停止打标 按钮的可用状态
	UpdateView();

	CDialog::OnTimer(nIDEvent);
}

void CHansAdvInterfaceTestDlg::OnBnClickedButtonReadoutport()
{
	BeginWaitCursor();
	DWORD dwReadOutPort = 0;
	UINT nRet = HS_ReadOutPort(m_uCard,&dwReadOutPort);
	char binary[32] = {0};
	itoa((unsigned short)dwReadOutPort,binary,16);
	if ( HL_ERR_SUCCESS == nRet )
	{
		m_strReadOutPort = CString(_T("0X")) + CString( CStringA(binary));
		UpdateData(FALSE);
	}

	ShowLastError();
	EndWaitCursor();
}

void CHansAdvInterfaceTestDlg::OnBnClickedButtonGetdogidinfo()
{
	//获取狗设备ID
	char id[33] = {0};
	char compid[5] = {0};
	char devid[9] = {0};
	if (HL_ERR_SUCCESS == HS_GetTimeDogInfoID(id,compid,devid))
	{
		GetDlgItem(IDC_EDIT_SN)->SetWindowText(CString(CStringA(id)));
		GetDlgItem(IDC_EDIT_COMPID)->SetWindowText(CString(CStringA(compid)));
		GetDlgItem(IDC_EDIT_DEVID)->SetWindowText(CString(CStringA(devid)));
	}
	else
	{
		ShowLastError();
	}

//-------------  设置狗设备ID(第3个参数设置为TRUE，通过第4个参数设置设备ID) -------
	//char id[33] = {0};
	//char compid[5] = {0};
	//char devid[9] = "12388678";  // 8位字符 设置自己设备ID字符
	//if (HS_GetTimeDogInfoID(id,compid,true,devid))
	//{
	//	GetDlgItem(IDC_EDIT_SN)->SetWindowText(CString(CStringA(id)));
	//	GetDlgItem(IDC_EDIT_COMPID)->SetWindowText(CString(CStringA(compid)));
	//	GetDlgItem(IDC_EDIT_DEVID)->SetWindowText(CString(CStringA(devid)));
	//}
	//else
	//{
	//	ShowLastError();
	//}
//---------------------------------------------------------------------------

}

void CHansAdvInterfaceTestDlg::OnClose()
{
	// TODO: 在此添加消息处理程序代码和/或调用默认值
	if(m_bInitOk)
	   HS_CloseMachine();
	
	CDialog::OnClose();
}

void CHansAdvInterfaceTestDlg::OnBnClickedButtonMarkAll()
{
	BeginWaitCursor();
	UpdateData();

	// 非阻塞打标时，实时检测打标是否结束，并刷新界面
	SetTimer(1, 100, NULL);
	int nCount = m_cbCard.GetCount();
	for(int i=0; i<nCount; i++)
	{
		HS_Mark(i, 0, 0, 0, 0, 1);
	}

	if(nCount > 0)
		m_bMarking = TRUE;

	UpdateView(); // 刷新 开始打标/停止打标 按钮的可用状态
	EndWaitCursor();
}

void CHansAdvInterfaceTestDlg::OnBnClickedButtonMarkIoFly()
{
	// 软件触发等距飞行打标
	HS_MarkFlyIOStart(m_uCard);
	ShowLastError();
}

void CHansAdvInterfaceTestDlg::OnBnClickedButtonMarktypeSet()
{
	BeginWaitCursor();
	UpdateData(TRUE);

	if(HL_ERR_SUCCESS == HS_SetMarkModel(m_uCard,m_nMarkModel,m_nFlyType,!m_bFlyReveral,m_dSpeed,m_nPPR,MsgFlyMarkCall))
		m_bMarkingFly = m_nMarkModel > 0 && m_nMarkModel < 3 ? TRUE : FALSE;

	ShowLastError();
	UpdateView();
	EndWaitCursor();
}

void CHansAdvInterfaceTestDlg::OnCbnSelchangeComboCard()
{
	int n=m_cbCard.GetCurSel();
	if(n>=0)
		m_uCard=n;
}


void CHansAdvInterfaceTestDlg::OnLButtonDown(UINT nFlags, CPoint point)
{
	m_bBoxSelect = TRUE;
	m_pntBoxSelectStart = point;

	CDialog::OnLButtonDown(nFlags, point);
}

void CHansAdvInterfaceTestDlg::OnLButtonUp(UINT nFlags, CPoint point)
{
	m_bBoxSelect = FALSE;

	CRect rectPreview;
	GetDlgItem(IDC_STATIC_PREVIEW)->GetWindowRect(&rectPreview);
	ScreenToClient(&rectPreview);

	BOOL bCtrl = GetKeyState(VK_CONTROL) & 0x8000;

	if((m_pntBoxSelectStart.x - point.x == 0) && (m_pntBoxSelectStart.y - point.y == 0))
	{	// 点选
		if(!rectPreview.PtInRect(point))
			return;

		CPoint pTemp(point.x-rectPreview.left, point.y-rectPreview.top);
		if(HL_ERR_SUCCESS != HS_PickObjectByPoint(m_uCard, pTemp.x, pTemp.y, bCtrl, m_dbViewX, m_dbViewY, m_dbViewRate))
			ShowLastError();
	}
	else
	{	// 框选
		double dbTop = (m_pntBoxSelectStart.y < point.y ? m_pntBoxSelectStart.y : point.y) - rectPreview.top;
		double dbLeft = (m_pntBoxSelectStart.x < point.x ? m_pntBoxSelectStart.x : point.x) - rectPreview.left;
		double dbBottom = (m_pntBoxSelectStart.y > point.y ? m_pntBoxSelectStart.y : point.y) - rectPreview.top;
		double dbRight = (m_pntBoxSelectStart.x > point.x ? m_pntBoxSelectStart.x : point.x) - rectPreview.left;

		CPoint pTemp(point.x-rectPreview.left, point.y-rectPreview.top);
		if(HL_ERR_SUCCESS != HS_PickObjectByRect(m_uCard, dbLeft, dbRight, dbTop, dbBottom, bCtrl, m_dbViewX, m_dbViewY, m_dbViewRate))
			ShowLastError();
	}

	Preview();

	CDialog::OnLButtonUp(nFlags, point);
}


void CHansAdvInterfaceTestDlg::OnCbnSelchangeComboObject()
{
	int nIdx = m_cbObjcet.GetCurSel();
	if(nIdx < 0)
		return;

	int nRet = HS_SelectObjects(m_uCard, NULL, FALSE);
	if(nRet != HL_ERR_SUCCESS)
	{
		ShowLastError();
		return;
	}

	int nSize = 20;
	TCHAR* szObjName = new TCHAR[nSize];
	nRet = HS_GetObjNameByNumber(m_uCard, nIdx, szObjName, &nSize);
	if(nRet != HL_ERR_SUCCESS)
	{
		ShowLastError();
		return;
	}

	nRet = HS_SelectObjects(m_uCard, szObjName, TRUE);
	if(nRet != HL_ERR_SUCCESS)
	{
		ShowLastError();
		return;
	}

	m_strCurrentObjName = CString(szObjName);
	UpdateData(FALSE);
	Preview();
}


void CHansAdvInterfaceTestDlg::OnBnClickedButtonSavefile()
{
	CString strFormat1;
	CString strFormat2;
#if defined (_DEBUG_HBM) || defined (NDEBUG_HBM)
	{
		strFormat1 = _T("*.BS");
		strFormat2 = _T("BS File|*.BS|");
	}
#else
	{
		strFormat1 = _T("*.HS");
		strFormat2 = _T("HS File|*.HS|");
	}
#endif

	CFileDialog dlg(FALSE,strFormat1,NULL,OFN_HIDEREADONLY,strFormat2,NULL);
	if ( IDCANCEL == dlg.DoModal() ) 
		return;

	BeginWaitCursor();
	int nRet = HS_SaveMarkFile(m_uCard, (LPTSTR)(LPCTSTR)dlg.GetPathName());
	ShowLastError();
	EndWaitCursor();
}


void CHansAdvInterfaceTestDlg::OnBnClickedButtonImport()
{
	TCHAR szFilter[] = _T("Common File(*.plt/*.dxf/*.nc/*.ai/*.jpg/*.jpeg/*.bmp/*.gif/*.png/*.ico/*.tif)|*.plt;*.dxf;*.nc;*.ai;*.jpg;*.jepg;*.bmp;*.gif;*.png;*.ico;*.tif");
	CFileDialog fileDlg(TRUE, _T("txt"), NULL, OFN_HIDEREADONLY | OFN_READONLY | OFN_ALLOWMULTISELECT | OFN_FILEMUSTEXIST, szFilter);

	if (fileDlg.DoModal() != IDOK)
		return;

	CString strFilePath = fileDlg.GetPathName();
	CString strFileExt;

	int pos = strFilePath.ReverseFind('.');
	if ( pos >= 0 )
		strFileExt = strFilePath.Right(strFilePath.GetLength() - pos - 1);
	strFileExt.MakeUpper();

	// Vector
	BeginWaitCursor();
	int nRet = 0;
	if( 0 == strFileExt.CompareNoCase( _T("PLT") ) 
		|| 0 == strFileExt.CompareNoCase( _T("DXF")) 
		|| 0 == strFileExt.CompareNoCase( _T("NC")) 
		|| 0 == strFileExt.CompareNoCase( _T("AI")) )
	{
		nRet = HS_ImportVectorFile2(m_uCard
			, strFilePath.GetBuffer()
			, 0.0	// 中心位置X
			, 0.0	// 中心位置Y
			, 10.0	// 宽
			, 10.0	// 高
			, 0.0	// 旋转角度
			, FALSE	// 是否填充
			, 0		// 边框层号
			, _T("vector1")	// 对象名
			, 0);	// 填充层号
	}
	else
	{
		nRet = HS_ImportImageFile2(m_uCard
			, strFilePath.GetBuffer()
			, 0.0	// 中心位置X
			, 0.0	// 中心位置Y
			, 10.0	// 宽
			, 10.0	// 高
			, 0.0	// 旋转角度
			, 0		// 位图类型 0-灰度 1-二值
			, 0.05	// 点间距X
			, 0.05	// 点间距Y
			, 0		// 加速点个数
			, TRUE	// 往复扫描
			, 250	// 往复扫描点个数（100倍）
			, _T("bmp1")	// 对象名
			, 1		// 图层号
			);
	}
	EndWaitCursor();

	strFilePath.ReleaseBuffer();
	RefleshObjList();
	ShowLastError();
	Preview();
}


void CHansAdvInterfaceTestDlg::OnBnClickedButtonDelObj()
{
	if(IDYES != MessageBox(_T("Are you sure to delete the selected objects ?"), _T("Waring"), MB_YESNO | MB_ICONQUESTION))
		return;

	int nRet = HS_ClearObjects(m_uCard);
	ShowLastError();
	Preview();
	RefleshObjList();
}


void CHansAdvInterfaceTestDlg::OnBnClickedButtonPreprocessdata()
{
	if(IDYES != MessageBox(_T("Are you sure to reflash all text and barcode ?"), _T("Waring"), MB_YESNO | MB_ICONQUESTION))
		return;

	int nRet = HS_PreprocessMark(m_uCard);
	ShowLastError();
	Preview();
}


void CHansAdvInterfaceTestDlg::OnBnClickedButtonVector2bitmap()
{
	int nRet = HS_Vector2Bitmap(m_uCard
		, 0.01	// 转换间距
		, 0.01	// 线宽
		, 0		// 边界外扩
		, FALSE	// 是否绘制外形轮廓
		, TRUE	// 位图是否填充
		, TRUE	// 列再分割
		, 0.1	// 行合并差容
		, 3		// 列转换偏差值
		, 0.05	// 位图X点距
		, 0.05	// 位图Y点距
		, 0		// 位图类型 0-灰度图 1-二值图
		, 0		// （灰度图）加速点个数
		, FALSE	// （灰度图）往复扫描
		, 0		// （灰度图）补偿点个数
		, _T("C:\\Hans_Bitmap\\Test\\") // 位图导出路径
		, TRUE); // TRUE-转换选中的对象 FALSE-转换所有对象
	
	Preview();
	ShowLastError();
}


void CHansAdvInterfaceTestDlg::OnBnClickedButtonChangename()
{
	UpdateData();

	TCHAR szObjList[500][20];
	int nSize = 500;
	int nRet = HS_GetObjList(m_uCard, szObjList, &nSize);
	if(nRet != HL_ERR_SUCCESS)
	{
		ShowLastError();
		return;
	}

	if(nSize > 0)
	{
		int nParam = 0;
		nRet = HS_ChangeName(m_uCard, szObjList[0], (LPTSTR)(LPCTSTR)m_strCurrentObjName, &nParam);
		if(nRet != HL_ERR_SUCCESS)
		{
			ShowLastError();
			return;
		}
		RefleshObjList();
	}
}


void CHansAdvInterfaceTestDlg::OnBnClickedButtonChangebmp()
{
	TCHAR szFilter[] = _T("Common File(*.bmp/*.gif/*.png/*.ico/*.tif)|*.jpg;*.jepg;*.bmp;*.gif;*.png;*.ico;*.tif");
	CFileDialog fileDlg(TRUE, _T("txt"), NULL, OFN_HIDEREADONLY | OFN_READONLY | OFN_ALLOWMULTISELECT | OFN_FILEMUSTEXIST, szFilter);

	if (fileDlg.DoModal() != IDOK)
		return;

	UpdateData(TRUE);

	CString strFilePath = fileDlg.GetPathName();
	int nRet = HS_ChangeBitmap(m_uCard, (LPTSTR)(LPCTSTR)m_strBmpObjName, (LPTSTR)(LPCTSTR)strFilePath);
	ShowLastError();
	Preview();
}


void CHansAdvInterfaceTestDlg::OnBnClickedCheckRed()
{
	BOOL bFlag = IsDlgButtonChecked(IDC_CHECK_RED) ? FALSE : TRUE;
	int nRet = HS_ISetRedLight(m_uCard, bFlag);
	ShowLastError();
}


void CHansAdvInterfaceTestDlg::OnBnClickedButtonTest()
{
	int nRet = 0;

 	HS_SetDevCfgEx(m_uCard);
	ShowLastError();
 	Preview();
 	return;
}

void CHansAdvInterfaceTestDlg::OnBnClickedCheckSofthome()
{
	// TODO: 在此添加控件通知处理程序代码
	UpdateData();
}

void CHansAdvInterfaceTestDlg::OnBnClickedButtonMovemotorex()
{
	UpdateData(TRUE);
	m_pThreadMoveEx = AfxBeginThread(Thread_MotorMove, (LPVOID)this);
// 	if(m_pThreadMoveEx != NULL)
// 	{
// 		HANDLE hThread = m_pThreadMoveEx.m_hThread;
// 		DWORD dwWaitResult = WaitForSingleObject(hThread, INFINITE);
// 	}
// 	ShowError(nRtn);
	return;
}

void CHansAdvInterfaceTestDlg::OnBnClickedButtonSofthomeex()
{
	UpdateData();
	int nAxisEx = (m_bEnableAxis0) | (m_bEnableAxis1<<1) | (m_bEnableAxis2<<2) | (m_bEnableAxis3<<3);
	int nRtn = HS_HomeMoveVEx(m_uCard, nAxisEx, m_bSoftHome);
	ShowError(nRtn);

}

void CHansAdvInterfaceTestDlg::OnBnClickedButtonStoprunex()
{
	UpdateData();
	int nRtn = 0;
//	int nAxisEx = (m_bEnableAxis0) | (m_bEnableAxis1<<1) | (m_bEnableAxis2<<2) | (m_bEnableAxis3<<3);
//	nRtn = HS_StopRunEx(m_uCard, nAxisEx);
	if(m_bEnableAxis0)
		nRtn = HS_StopRunEx(m_uCard, 1);
	if(m_bEnableAxis1)
		nRtn = HS_StopRunEx(m_uCard, 2);
	if(m_bEnableAxis2)
		nRtn = HS_StopRunEx(m_uCard, 4);
	if(m_bEnableAxis3)
		nRtn = HS_StopRunEx(m_uCard, 8);
	ShowError(nRtn);

}

void CHansAdvInterfaceTestDlg::ShowError(int nErrorCode)
{
	if(nErrorCode != 0)
	{
		TCHAR szBuff[200] = {0};
		HS_GetLastError(m_uCard, &nErrorCode, szBuff, 200);
		CString strErrInfo(szBuff);
		CString strValue = g_lang.TranslateString(strErrInfo);
		if(strValue == _T(""))
			strValue = strErrInfo;
		SetDlgItemText(IDC_STATIC_NOTE, strValue);
	}
}

void CHansAdvInterfaceTestDlg::OnBnClickedButtonRotatemark()
{
	// TODO: 在此添加控件通知处理程序代码
	HS_SelectObjects(0, NULL, TRUE);
	int nRet = HS_SetMotionSysPara(0, 0, 10000, 360, 100, 1, 1, 50, 100, 0.5, 0.5, FALSE, FALSE, TRUE);
	nRet = HS_SetRotateMarkPara(0, 40, 10, 11, FALSE);
	nRet = HS_PreprocessRotateData(0, 0);
	nRet = HS_RotateMark(0, 0, FALSE, FALSE, 0);
	Sleep(1);
}

void CHansAdvInterfaceTestDlg::OnBnClickedButtonRef()
{
	// test
// 	int nRet = HS_AddCircle(0, 5.55, 4, 6, 0, 0, 0, _T("qwe1"));
// 	nRet = HS_AddRectangle(0, 3, 4, -4, -6, 0, 0, 0, _T("qwe2"));
// 	return;

	// test
// 	HS_MarkLine(m_uCard, -10, 0, 10, 0, 0, 0);
// 	HS_MarkLine(m_uCard, 0, -10, 0, 10, 0, 0);


	// test
// 	TCHAR szObjList[9999][20];
// 	int nObjCnt = 9999;
// 	int nObjType, nBarcodeType;
// 	double dbL, dbT, dbR, dbB;
// 	CString strInfo;
// 	// 获取对象名列表
// 	int nRet = HS_GetObjList(m_uCard, szObjList, &nObjCnt);
// 	if ( nRet == HL_ERR_SUCCESS )
// 	{
// 		for (int i=0; i<nObjCnt; i++)
// 		{	
// 			// 获取对象类型
// 			nRet = HS_GetObjectType(m_uCard, szObjList[i], &nObjType);
// 			if(nRet == HL_ERR_SUCCESS)
// 			{
// 				switch (nObjType)
// 				{
// 				case 1: OutputDebugString(_T("\r\n对象的类型为：曲线")); break;
// 				case 2: OutputDebugString(_T("\r\n对象的类型为：矩形")); break;
// 				case 3: OutputDebugString(_T("\r\n对象的类型为：文本")); break;
// 					// ...略，详见接口注释
// 				default:OutputDebugString(_T("\r\n对象的类型为：未知")); break;
// 				}
// 
// 				if(nObjType == 11)
// 				{	
// 					// 获取码类型
// 					nRet = HS_GetBarcodeType(m_uCard, szObjList[i], &nBarcodeType);
// 					if(nRet == HL_ERR_SUCCESS)
// 					{
// 						switch (nBarcodeType)
// 						{
// 						case 0: OutputDebugString(_T("\r\n码的类型为：EAN8")); break;
// 						case 1: OutputDebugString(_T("\r\n码的类型为：EAN13")); break;
// 						case 2: OutputDebugString(_T("\r\n码的类型为：EAN128")); break;
// 						// ...略，详见接口注释
// 						default:OutputDebugString(_T("\r\n码的类型为：未知")); break;
// 						}
// 					}
// 					else
// 					{
// 						// 获取码类型失败
// 					}
// 				}
// 				else
// 				{
// 					// 当前对象不是码
// 				}
// 
// 				// 获取对象尺寸
// 				nRet = HS_GetObjPropertyByName(m_uCard, szObjList[i], &dbL, &dbT, &dbR, &dbB);
// 				if(nRet == HL_ERR_SUCCESS)
// 				{
// 					strInfo.Format(_T("\r\n位置(%.3f, %.3f)，尺寸(x=%.3f y=%.3f)"), ((dbL+dbR)/2), ((dbB+dbT)/2), (dbR-dbL), (dbT-dbB));
// 					OutputDebugString(strInfo);
// 				}
// 			}
// 			else
// 			{
// 				// 获取对象类型失败
// 			}
// 		}
// 	}
// 	else
// 	{
// 		// 获取对象列表失败
// 	}
// 	return;


	// test
// 	FONT_PARA fontPara;
// 	strcpy(fontPara.szFontName, "Arial");
// 	HS_SetFontPara(0, LPVOID(&fontPara)); // TTF：Arial
// 	HS_AddText(0, _T("阿斯顿123QWer"), 8, 50, FALSE, _T(""), 0, 10, 0, 0, 0, 0, 0, _T("t1"));
// 	strcpy(fontPara.szFontName, "微软雅黑"); // TTF：微软雅黑
// 	HS_SetFontPara(0, LPVOID(&fontPara)); // SHX：
// 	HS_AddText(0, _T("阿斯顿123QWer"), 8, 50, FALSE, _T(""), 0, 0, 0, 0, 0, 0, 0, _T("t2"));
// 	HS_SetFontPara(0, LPVOID(&fontPara));
// 	HS_AddText(0, _T("阿斯顿123QWer"), 8, 50, FALSE, _T(""), 0, 10, 0, 0, 0, 0, 0, _T("t1"));
// 	strcpy(fontPara.szFontName, "微软雅黑");
// 	HS_SetFontPara(0, LPVOID(&fontPara));
// 	HS_AddText(0, _T("阿斯顿123QWer"), 8, 50, FALSE, _T(""), 0, 0, 0, 0, 0, 0, 0, _T("t2"));
// 	return;


	// test
// 	int nModel = 0;
// 	int nBuffer = 20;
// 	TCHAR szAlias[20] = {0};
// 	int nRet = 0;
// 
// 	nRet = HS_GetTextByOrderByObjName(0, _T("obj1"), 0, &nModel, szAlias, &nBuffer);
// 	nRet = HS_SetTextByOrderByObjName(0, _T("obj1"), 0, 1, _T("qq"));
// 
// 	nRet = HS_GetTextByOrderByObjName(0, _T("obj1"), 1, &nModel, szAlias, &nBuffer);
// 	nRet = HS_SetTextByOrderByObjName(0, _T("obj1"), 1, 1, _T("ww"));
// 
// 	nRet = HS_GetTextByOrderByObjName(0, _T("obj1"), 2, &nModel, szAlias, &nBuffer);
// 	nRet = HS_SetTextByOrderByObjName(0, _T("obj1"), 2, 0, _T("ee"));
// 
// 	nRet = HS_GetTextByOrderByObjName(0, _T("obj1"), 3, &nModel, szAlias, &nBuffer);
// 	nRet = HS_SetTextByOrderByObjName(0, _T("obj1"), 3, 0, _T("rr"));
// 
// 	nRet = HS_GetTextByOrderByObjName(0, _T("obj1"), 4, &nModel, szAlias, &nBuffer); // 不存在的文本
// 	
// 	nRet = HS_GetTextByOrderByObjName(0, _T("obj2"), 0, &nModel, szAlias, &nBuffer);
// 	nRet = HS_GetTextByOrderByObjName(0, _T("obj2"), 1, &nModel, szAlias, &nBuffer);
// 	nRet = HS_GetTextByOrderByObjName(0, _T("obj2"), 2, &nModel, szAlias, &nBuffer);
// 	nRet = HS_GetTextByOrderByObjName(0, _T("obj2"), 3, &nModel, szAlias, &nBuffer);
// 
// 	nRet = HS_GetTextByOrderByObjName(0, _T("obj5"), 0, &nModel, szAlias, &nBuffer); // 不存在的对象

	// test
// 	CString str;
// 	for (int i=0; i<1000; i++)
// 	{
// 		str.Format(_T("%d"), i);
// 		HS_ChangeTextByName2(m_uCard, str.GetBuffer(), _T("1234asdfghj"), 0);
// 	}
// 	HS_PreprocessMark(m_uCard);
// 	str.ReleaseBuffer();

	// test
//	HS_UnionGroup(m_uCard, _T("obj"));
//	HS_UnUnionGroup(m_uCard);

	// test
// 	CString strFormat1 = _T("*.box");
// 	CString strFormat2 = _T("BOX Files(*.box)|*.box||");
// 	CFileDialog dlg(TRUE,strFormat1,NULL,OFN_HIDEREADONLY,strFormat2,NULL);
// 	if ( IDCANCEL == dlg.DoModal() ) 
// 		return;
// 
// 	BeginWaitCursor();
// 	int nRet = HS_SwitchCaliBox(m_uCard, (LPTSTR)(LPCTSTR)dlg.GetPathName(), TRUE);
// 	ShowLastError();
// 	AfxMessageBox(dlg.GetPathName());
// 	return;

	// test
	// 	double* dbX = NULL;
	// 	double* dbY = NULL;
	// 	double* dbZ = NULL;
	// 	int* nLayer = NULL;
	// 	int* nCountSub = NULL;
	// 	int nCount = 0;
	// 	nRet = HS_GetStrokeList2(m_uCard, _T("1"), dbX, dbY, dbZ, nLayer, nCountSub, &nCount, 1);
	// 
	// 	if(nRet == HL_ERR_SUCCESS)
	// 	{
	// 		int nIdx = 0; // 当前已访问的dbX/dbY/dbZ索引
	// 		for(int i=0; i<nCount; i++) // 遍历所有线条
	// 		{
	// 			int nCountDot = *(nCountSub+i); // 当前线条包含的点数
	// 			for(int j=0; j<nCountDot; j++) // 遍历当前线条的所有点
	// 			{
	// 				double x = *(dbX + nIdx + j);
	// 				double y = *(dbY + nIdx + j);
	// 				double z = *(dbZ + nIdx + j);
	// 
	// 				// 自定义操作
	// 				// ...
	// 			}
	// 			nIdx += nCountDot; // 处理dbX/dbY/dbZ索引
	// 		}
	// 	}
	// 	HS_FreeStrokeList2(m_uCard, dbX, dbY, dbZ, nLayer, nCountSub);
	// 	ShowLastError();
	//  	Preview();
	//  	return;


	// test
	// 	double arr[6][2];
	// 	arr[0][0] = 0;
	// 	arr[0][1] = 0;
	// 	arr[1][0] = 0;
	// 	arr[1][1] = 10;
	// 	arr[2][0] = 0;
	// 	arr[2][1] = 20;
	// 	arr[3][0] = 0;
	// 	arr[3][1] = 30;
	// 	arr[4][0] = 0;
	// 	arr[4][1] = 40;
	// 	arr[5][0] = 0;
	// 	arr[5][1] = 50;
	// 	HS_Array(m_uCard, arr, 6);
	// 	Sleep(1);
	// 	return;


	// test
	// 	TCHAR szObjList[25][20];
	// 	int nObjCnt = 0;
	// 	HS_SplitByObjName(m_uCard, _T("1"), 1, 4, szObjList, &nObjCnt, TRUE, 2);
	// 	Sleep(1);
	// 	return;


	// test
	// 	LAYERPARA* pLay= new LAYERPARA;
	// 	HS_GetLayerPara(m_uCard, 2, (LPVOID)pLay);
	// 	Sleep(1);


	// test
	//	nRet = HS_SetBitmapDropWhite(m_uCard, _T("bmp1"), TRUE, TRUE, 240);


	// test
	// 	double dbHeight(5.1);
	// 	double dbCharSpace(0.1);
	// 	double dbWidthRatio(1.1);
	// 	double dbLineSpace(0.51);
	// 	BOOL bFixSpace(TRUE);
	// 	double dbFixSpace(5.1);
	// 	nRet = HS_GetTextObjShapeProperty(m_uCard, _T("t1"), &dbHeight, &dbCharSpace, &dbWidthRatio, &dbLineSpace, &bFixSpace, &dbFixSpace);
	// 	
	// 	dbHeight = 8.0;
	// 	dbCharSpace = 2.0;
	// 	dbWidthRatio = 1.5;
	// 	dbLineSpace = 2.0;
	// 	nRet = HS_SetTextObjShapeProperty(m_uCard, _T("t1"), dbHeight, dbCharSpace, dbWidthRatio, dbLineSpace, bFixSpace, dbFixSpace);
	// 	Preview();


	// test
	// 	const int nRow = 14;
	// 	const int nCol = 16;
	// 	const int nSize = nRow * nCol;
	// 	int pData[nSize];
	// 	for(int i=0; i<nSize; i++)
	// 		pData[i] = i;
	// 
	// 	nRet = HS_ImportBitmapData(0
	// 		, pData
	// 		, nRow
	// 		, nCol
	// 		, 0.0	// 中心位置X坐标
	// 		, 0.0	// 中心位置Y坐标
	// 		, 10.0
	// 		, 10.0
	// 		, 0.0
	// 		, 0.05	// 点间距X
	// 		, 0.05	// 点间距Y
	// 		, 0		// 加速点个数
	// 		, TRUE	// 往复扫描
	// 		, 250	// 往复扫描点个数（100倍）
	// 		, _T("bmp1")	// 对象名
	// 		, 1		// 图层号
	// 		);
	// 
	// 	pData[0] = 255;
	// 	nRet = HS_ImportBitmapData(0
	// 		, pData
	// 		, nRow
	// 		, nCol
	// 		, 30.0	// 中心位置X坐标
	// 		, 30.0	// 中心位置Y坐标
	// 		, 10.0
	// 		, 10.0
	// 		, 0.0
	// 		, 0.05	// 点间距X
	// 		, 0.05	// 点间距Y
	// 		, 0		// 加速点个数
	// 		, TRUE	// 往复扫描
	// 		, 250	// 往复扫描点个数（100倍）
	// 		, _T("bmp2")	// 对象名
	// 		, 1		// 图层号
	// 		);
	//	nRet = HS_ChangeBitmapData(m_uCard, _T("bmp2"), pData, nRow, nCol);



	// test
	// 	nRet = HS_SetObjNameByNumber(0, 0, _T("对象0"));
	// 	nRet = HS_SetObjNameByNumber(0, 1, _T("对象1"));
	// 	nRet = HS_SetObjNameByNumber(0, 2, _T(""));
	// 	nRet = HS_SetObjNameByNumber(0, 3, _T(""));
	// 	nRet = HS_SetObjNameByNumber(0, 4, _T("对象5"));



	// test
	//  	int nCount = 100;
	// 	TCHAR sz[100][20] = {0};
	// 	nRet = HS_GetDocList(0, sz, &nCount);
	// 	nCount = 100;
	// 	nRet = HS_GetObjList(0, sz, &nCount);
	// 	Sleep(1);



	// test
	// 	int nCount = 100;
	// 	TCHAR sz[100][20] = {0};
	// 	nRet = HS_GetObjListSelected(0, sz, &nCount);
	// 	nCount = 100;
	// 	nRet = HS_GetVarTextListByObjName(0, _T("啊1"), sz, &nCount);



	// test
	// 	HS_SelectObjects(0, NULL, TRUE);
	// 
	// 	nRet = HS_SetMotionSysPara(0, 0, 6500, 6.7, 100, 0, -1, 360, 720, 0.1, 0.1, 0, 0, 1);
	// 	nRet = HS_SetRotateMarkPara(0, 10, 0.1, 1, FALSE);
	// 	nRet = HS_PreprocessRotateData(0, 2);
	// 	nRet = HS_RotateMark(0, 0, FALSE, TRUE, 0);
	//	Sleep(1);



	// test
	//	LPVOID lp = NULL;
	//	AfxBeginThread(Thread_TransformMark2, lp);
	// 	AfxBeginThread(Thread_TransformMark1, lp);



	// test
	// 	int nIndex = -1;
	// 	TCHAR szObjName[200] = {0};
	// 	int n = 200;
	// 	nRet = HS_GetObjNameByNumber(m_uCard, 2, szObjName, &n);
	// 	nRet = HS_GetNumberByObjName(m_uCard, &nIndex, _T("obj1"));
	// 	return;



	// test
	// 	CString strPath = _T("C:\\Users\\liaomj130414\\Desktop\\BS1.bs");
	// 	CString strFix = _T("ABCDEFG");
	// 
	// 	for (int i=0; i<1; i++)
	// 	{
	// 		CString strText;
	// 		strText.Format(_T("%s%d"), strFix, i);
	// 
	// 		nRet = HS_LoadMarkFile(0, (LPTSTR)(LPCTSTR)strPath);
	// 		ASSERT(nRet == 0);
	// 
	// 		nRet = HS_SetCurDoc(m_uCard, (LPTSTR)(LPCTSTR)strPath);
	// 		ASSERT(nRet == 0);
	// 
	// 		nRet = HS_ChangeTextByName(0, _T("1"), (LPTSTR)(LPCTSTR)strText);
	// 		ASSERT(nRet == 0);
	// 
	// 		nRet = HS_SelectObjects(0, NULL, TRUE);
	// 		ASSERT(nRet == 0);
	// 
	// 		nRet = HS_Vector2Bitmap(m_uCard
	// 			, 0.01	// 转换间距
	// 			, 0.01	// 线宽
	// 			, 5	// 边界外扩
	// 			, FALSE	// 是否绘制外形轮廓
	// 			, TRUE	// 位图是否填充
	// 			, TRUE	// 列再分割
	// 			, 0.1	// 行合并差容
	// 			, 3		// 列转换偏差值
	// 			, 0.05	// 位图X点距
	// 			, 0.05	// 位图Y点距
	// 			, 0		// 位图类型 0-灰度图 1-二值图
	// 			, 0		// （灰度图）加速点个数
	// 			, FALSE	// （灰度图）往复扫描
	// 			, 0		// （灰度图）补偿点个数
	// 			, _T("C:\\H_Bitmap\\1\\") // 位图导出路径
	// 			, TRUE); // TRUE-转换选中的对象 FALSE-转换所有对象
	// 		ASSERT(nRet == 0);
	// 
	// 		nRet = HS_CloseMarkFile(0, (LPTSTR)(LPCTSTR)strPath, FALSE);
	// 		ASSERT(nRet == 0);
	// 	}
	// 	
	// 	Sleep(1);


	// test
	// 	nRet = HS_Cut(m_uCard, _T("1"));
	// 	nRet = HS_Paste(m_uCard, _T("2"));
	// 	nRet = HS_SaveMarkFile(m_uCard, _T("C:\\Users\\liaomj130414\\Desktop\\bs2.bs"));
	// 	Preview();



	// test
	// 	double* mx = new double[9];
	// 	double* my = new double[9];
	// 	double* rx = new double[9];
	// 	double* ry = new double[9];
	// 	double* r = new double[9];
	// 
	// 	mx[0] = 3;
	// 	my[0] = 0;
	// 	rx[0] = 3;
	// 	ry[0] = 0;
	// 	r[0] = 3;
	// 
	// 	mx[1] = 6;
	// 	my[1] = 0;
	// 	rx[1] = 6;
	// 	ry[1] = 0;
	// 	r[1] = 6;
	// 
	// 	mx[2] = 9;
	// 	my[2] = 0;
	// 	rx[2] = 9;
	// 	ry[2] = 0;
	// 	r[2] = 9;
	// 
	// 	mx[3] = 12;
	// 	my[3] = 0;
	// 	rx[3] = 12;
	// 	ry[3] = 0;
	// 	r[3] = 12;
	// 
	// 	mx[4] = 15;
	// 	my[4] = 0;
	// 	rx[4] = 15;
	// 	ry[4] = 0;
	// 	r[4] = 15;
	// 
	// 	mx[5] = 3;
	// 	my[5] = 3;
	// 	rx[5] = 3;
	// 	ry[5] = 3;
	// 	r[5] = 3;
	// 
	// 	mx[6] = 6;
	// 	my[6] = 3;
	// 	rx[6] = 6;
	// 	ry[6] = 3;
	// 	r[6] = 6;
	// 
	// 	mx[7] = 9;
	// 	my[7] = 3;
	// 	rx[7] = 9;
	// 	ry[7] = 3;
	// 	r[7] = 9;
	// 
	// 	mx[8] = 12;
	// 	my[8] = 3;
	// 	rx[8] = 12;
	// 	ry[8] = 3;
	// 	r[8] = 12;
	// 	
	// 	int nRet1 = HS_SetTransformMarkParamEx(m_uCard, mx, my, rx, ry, r, 9, TRUE);
	// 	int nRet2 = HS_Mark(m_uCard, 0, 0, 1, 0, 1);
	// 
	// 	if(mx)
	// 	{
	// 		delete[] mx;
	// 		mx = NULL;
	// 	}
	// 	if(my)
	// 	{
	// 		delete[] my;
	// 		my = NULL;
	// 	}
	// 	if(rx)
	// 	{
	// 		delete[] rx;
	// 		rx = NULL;
	// 	}
	// 	if(ry)
	// 	{
	// 		delete[] ry;
	// 		ry = NULL;
	// 	}
	// 	if(r)
	// 	{
	// 		delete[] r;
	// 		r = NULL;
	// 	}
	// 
	// 	CString strInfo;
	// 	strInfo.Format(_T("Ret: %d %d"), nRet1, nRet2);
	// 	AfxMessageBox(strInfo);
}
