#include "stdafx.h"
#include "MyStatic.h"
#include "MyStaticDlg.h"
#include <String>

struct defMsg{
  unsigned short name[15];
  unsigned short sex[1];
  unsigned short nation[2];
  unsigned short bY[4],bM[2],bD[2];
  unsigned short address[35];
  unsigned short id[18];
  unsigned short depart[15];
  unsigned short sadmid[31];
  unsigned short tsY[4],tsM[2],tsD[2];
  unsigned short tpY[4],tpM[2],tpD[2];
};

#define MSG ((struct defMsg *)&Buffer[0])

typedef int(PASCAL *lpInitComm)(int port);
typedef int(PASCAL *lpCloseComm)();
typedef int(PASCAL *lpAuthenticate)();
typedef int(PASCAL *lpRead_Content)(int active);
typedef int(PASCAL *lpRead_Content_Path)(char* cPath, int active);
typedef bool(PASCAL *lpMakeIDCardImage)(LPCSTR sHead, LPCSTR sIDCardImage);
typedef bool(PASCAL *lpMakeIDCardImages)(LPSTR sHead, LPSTR sIDCardImageFace, LPSTR sIDCardImageBack);

typedef boolean(PASCAL *lpGetName2)(byte *sBuf, int *nLen);
typedef boolean(PASCAL *lpGetSex2)(byte *sBuf, int *nLen);
typedef boolean(PASCAL *lpGetNation2)(byte *sBuf, int *nLen);
typedef boolean(PASCAL *lpGetBornDate2)(byte *sBuf, int *nLen);
typedef boolean(PASCAL *lpGetAddress2)(byte *sBuf, int *nLen);
typedef boolean(PASCAL *lpGetSignGov2)(byte *sBuf, int *nLen);
typedef boolean(PASCAL *lpGetStartDate2)(byte *sBuf, int *nLen);
typedef boolean(PASCAL *lpGetEndDate2)(byte *sBuf, int *nLen);
typedef boolean(PASCAL *lpGetSAMID)(char *sBuf);
typedef boolean(PASCAL *lpGetNewAddress2)(byte *sBuf, int *nLen);
typedef boolean(PASCAL *lpGetIDNo2)(byte *sBuf, int *nLen);
typedef boolean(PASCAL *lpGetFingerPrint)(byte *sBuf, int *nLen);

typedef int(PASCAL *lpIsFPRIDCard)();
typedef boolean(PASCAL *lpGetFPR_ENName2)(byte *sBuf, int *nLen);
typedef boolean(PASCAL *lpGetFPR_SEX2)(byte *sBuf, int *nLen);
typedef boolean(PASCAL *lpGetFPR_IDNo2)(byte *sBuf, int *nLen);
typedef boolean(PASCAL *lpGetFPR_NationCode2)(byte *sBuf, int *nLen);
typedef boolean(PASCAL *lpGetFPR_Nation2)(byte *sBuf, int *nLen);
typedef boolean(PASCAL *lpGetFPR_CHNName2)(byte *sBuf, int *nLen);
typedef boolean(PASCAL *lpGetFPR_ValidStartDate2)(byte *sBuf, int *nLen);
typedef boolean(PASCAL *lpGetFPR_ValidEndDate2)(byte *sBuf, int *nLen);
typedef boolean(PASCAL *lpGetFPR_Birthday2)(byte *sBuf, int *nLen);
typedef boolean(PASCAL *lpGetFPR_IDVersion2)(byte *sBuf, int *nLen);
typedef boolean(PASCAL *lpGetFPR_IssuingAuthorityCode2)(byte *sBuf, int *nLen);
typedef boolean(PASCAL *lpGetFPR_IDType2)(byte *sBuf, int *nLen);

lpInitComm InitComm;
lpCloseComm CloseComm;
lpAuthenticate Authenticate;
lpRead_Content Read_Content;
lpRead_Content_Path Read_Content_Path;
lpMakeIDCardImage MakeIDCardImage;
lpMakeIDCardImages MakeIDCardImages;

lpGetName2  GetName2;
lpGetSex2 GetSex2;
lpGetNation2 GetNation2;
lpGetBornDate2 GetBornDate2;
lpGetAddress2 GetAddress2;
lpGetSignGov2 GetSignGov2;
lpGetStartDate2 GetStartDate2;
lpGetEndDate2 GetEndDate2;
lpGetSAMID GetSAMID;
lpGetNewAddress2 GetNewAddress2;
lpGetIDNo2 GetIDNo2;
lpGetFingerPrint GetFingerPrint;

lpIsFPRIDCard IsFPRIDCard;
lpGetFPR_ENName2 GetFPR_ENName2;
lpGetFPR_SEX2 GetFPR_SEX2;
lpGetFPR_IDNo2 GetFPR_IDNo2;
lpGetFPR_NationCode2 GetFPR_NationCode2;
lpGetFPR_Nation2 GetFPR_Nation2;
lpGetFPR_CHNName2 GetFPR_CHNName2;
lpGetFPR_ValidStartDate2 GetFPR_ValidStartDate2;
lpGetFPR_ValidEndDate2 GetFPR_ValidEndDate2;
lpGetFPR_Birthday2 GetFPR_Birthday2;
lpGetFPR_IDVersion2 GetFPR_IDVersion2;
lpGetFPR_IssuingAuthorityCode2 GetFPR_IssuingAuthorityCode2;
lpGetFPR_IDType2 GetFPR_IDType2;

HINSTANCE dllHandle;

TCHAR	szExePath[MAX_PATH];
TCHAR	*m_lpMove;



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

/////////////////////////////////////////////////////////////////////////////
// CMyStaticDlg dialog

CMyStaticDlg::CMyStaticDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CMyStaticDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CMyStaticDlg)
		// NOTE: the ClassWizard will add member initialization here
	//}}AFX_DATA_INIT
	// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME); //
}

void CMyStaticDlg::DoDataExchange(CDataExchange* pDX)
{	
	CDialog::DoDataExchange(pDX);
	DDX_Control(pDX, IDC_NAME, m_name);
    DDX_Control(pDX, IDC_SEX, m_sex);
	DDX_Control(pDX, IDC_NATION, m_nation);
	DDX_Control(pDX, IDC_BIRTH, m_birth);
	DDX_Control(pDX, IDC_IDCODE, m_idcode);
	DDX_Control(pDX, IDC_ADDR, m_addr);
	DDX_Control(pDX, IDC_DEPART, m_depart);
	DDX_Control(pDX, IDC_VALID, m_valid);
	DDX_Control(pDX, IDC_SAMID, m_samid);
	DDX_Control(pDX, IDC_FINGER, m_finger);
	
	//DDX_Control(pDX, IDC_COMBO1, m_combo);
	DDX_Control(pDX, IDC_LIST5, m_list);
	DDX_Control(pDX, IDC_LIST2, m_list2);
}

BEGIN_MESSAGE_MAP(CMyStaticDlg, CDialog)
	//{{AFX_MSG_MAP(CMyStaticDlg)
	ON_WM_PAINT()
	ON_WM_QUERYDRAGICON()		
	ON_BN_CLICKED(IDC_CLOSE, OnClose)
	ON_LBN_SELCHANGE(IDC_LIST5, OnSelchangeList5)
	ON_COMMAND(IDC_BUTTON1, OnLoadddbpic)
	ON_BN_CLICKED(IDC_CHKREADTYPE, OnChkreadtype)
	//}}AFX_MSG_MAP
	//ON_STN_CLICKED(IDC_SAMID, &CMyStaticDlg::OnStnClickedSamid)
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CMyStaticDlg message handlers

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

	// Set the icon for this dialog.  The framework does this automatically
	//  when the application's main window is not a dialog
	SetIcon(m_hIcon, TRUE);			// Set big icon
	SetIcon(m_hIcon, FALSE);		// Set small icon
	SetWindowText("MKReader Demo");
	GetModuleFileName(AfxGetApp()->m_hInstance, szExePath, sizeof(szExePath));
	for (m_lpMove = szExePath + lstrlen(szExePath); *(m_lpMove - 1) != '\\'; m_lpMove--);
	lstrcpy (m_lpMove, "");
   
	CString szDLLPath;
#ifdef _M_IX86  
    szDLLPath.Format(_T("%s\\3rd_lib\\%s"), szExePath, "termb.dll");
#else
	szDLLPath.Format(_T("%s\\3rd_lib\\%s"), szExePath, "termb64.dll");
#endif
	 dllHandle=LoadLibrary(szDLLPath);
     if (dllHandle!=NULL){
			InitComm=(lpInitComm)GetProcAddress(dllHandle,"InitComm");			
			CloseComm=(lpCloseComm)GetProcAddress(dllHandle,"CloseComm");
			Authenticate=(lpAuthenticate)GetProcAddress(dllHandle,"Authenticate");
			Read_Content=(lpRead_Content)GetProcAddress(dllHandle,"Read_Content");
			Read_Content_Path=(lpRead_Content_Path)GetProcAddress(dllHandle,"Read_Content_Path");
			MakeIDCardImage =(lpMakeIDCardImage)GetProcAddress(dllHandle,"MakeIDCardImage");
			MakeIDCardImages =(lpMakeIDCardImages)GetProcAddress(dllHandle,"MakeIDCardImages");

			GetName2 = (lpGetName2)GetProcAddress(dllHandle, "GetName2");
			GetSex2 = (lpGetSex2)GetProcAddress(dllHandle, "GetSex2");
			GetNation2 = (lpGetNation2)GetProcAddress(dllHandle, "GetNation2");
			GetBornDate2 = (lpGetBornDate2)GetProcAddress(dllHandle, "GetBornDate2");
			GetAddress2 = (lpGetAddress2)GetProcAddress(dllHandle, "GetAddress2");
			GetSignGov2 = (lpGetSignGov2)GetProcAddress(dllHandle, "GetSignGov2");
			GetStartDate2 = (lpGetStartDate2)GetProcAddress(dllHandle, "GetStartDate2");
			GetEndDate2 = (lpGetEndDate2)GetProcAddress(dllHandle, "GetEndDate2");
			GetSAMID = (lpGetSAMID)GetProcAddress(dllHandle, "GetSAMID");
			GetNewAddress2 = (lpGetNewAddress2)GetProcAddress(dllHandle, "GetNewAddress2");
			GetIDNo2 = (lpGetIDNo2)GetProcAddress(dllHandle, "GetIDNo2");
			GetFingerPrint = (lpGetFingerPrint)GetProcAddress(dllHandle, "GetFingerPrint");


			 IsFPRIDCard=(lpIsFPRIDCard)GetProcAddress(dllHandle, "IsFPRIDCard");
			 GetFPR_ENName2=(lpGetFPR_ENName2)GetProcAddress(dllHandle, "GetFPR_ENName2");
			 GetFPR_SEX2=(lpGetFPR_SEX2)GetProcAddress(dllHandle, "GetFPR_SEX2");
			 GetFPR_IDNo2=(lpGetFPR_IDNo2)GetProcAddress(dllHandle, "GetFPR_IDNo2");
			 GetFPR_NationCode2=(lpGetFPR_NationCode2)GetProcAddress(dllHandle, "GetFPR_NationCode2");
			 GetFPR_Nation2=(lpGetFPR_Nation2)GetProcAddress(dllHandle, "GetFPR_Nation2");
			 GetFPR_CHNName2=(lpGetFPR_CHNName2)GetProcAddress(dllHandle, "GetFPR_CHNName2");
			 GetFPR_ValidStartDate2=(lpGetFPR_ValidStartDate2)GetProcAddress(dllHandle, "GetFPR_ValidStartDate2");
			 GetFPR_ValidEndDate2=(lpGetFPR_ValidEndDate2)GetProcAddress(dllHandle, "GetFPR_ValidEndDate2");
			 GetFPR_Birthday2=(lpGetFPR_Birthday2)GetProcAddress(dllHandle, "GetFPR_Birthday2");
			 GetFPR_IDVersion2=(lpGetFPR_IDVersion2)GetProcAddress(dllHandle, "GetFPR_IDVersion2");
			 GetFPR_IssuingAuthorityCode2=(lpGetFPR_IssuingAuthorityCode2)GetProcAddress(dllHandle, "GetFPR_IssuingAuthorityCode2");
			 GetFPR_IDType2=(lpGetFPR_IDType2)GetProcAddress(dllHandle, "GetFPR_IDType2");
	 } else {
		 ::MessageBox(NULL,"加载termb.dll出错，请检查程序运行目录下是否存在","错误",IDOK);
		 exit(1);
	 }
	m_list.InsertString(0,"COM");
	m_list.InsertString(1,"USB");
	m_list.InsertString(2,"USB-HID");

	m_list2.InsertString(0,"COM-1");
	m_list2.InsertString(1,"COM-2");
	m_list2.InsertString(2,"COM-3");
	m_list2.InsertString(3,"COM-4");
	m_list2.InsertString(4,"COM-5");
	// TODO: Add extra initialization here	

	return TRUE;  // return TRUE  unless you set the focus to a control
}

// If you add a minimize button to your dialog, you will need the code below
//  to draw the icon.  For MFC applications using the document/view model,
//  this is automatically done for you by the framework.
void CMyStaticDlg::settext()
{
  m_name.SetWindowText("MKReader's Demo");
  
}

/*void CMyStaticDlg::ProcessMessages() 
{   
	CWinApp* pApp=AfxGetApp();   
	MSG msg;   
	while ( PeekMessage(&msg, NULL, 0, 0, PM_NOREMOVE ))   
		pApp->PumpMessage();   
}   
*/

void CMyStaticDlg::OnOK()  
{
	int index=0;
	index = m_list.GetCurSel();
	
	switch(index)
	{	
	case 0:
		index = m_list2.GetCurSel();
			switch(index)
			{
			case 0:
				index=1;
				break;
			case 1:
				index=2;
				break;
			case 2:
				index=3;
				break;
			case 3:
				index=4;
				break;
			case 4:
				index=5;
				break;
			default :
				break;
			}
		break;
	case 1:
		index=1001;
		break;
	case 2:
		index=2401;
		break;
	default :
		break;
	}
	int iRet=InitComm(index);
	if  (iRet==0)
    {		
		m_finger.SetWindowText("开始读卡...");
		for (int i=0; i<3; i++)
		{
				//模块号
				char arrrTmp[100];
				int readType = 1;
				bool bRet = false;
				bRet = (bool)GetSAMID(arrrTmp);
				if(bRet)
				{
					if(arrrTmp[2] == 0x32 || arrrTmp[2] == 0x31)
						readType = 1;
					else readType = 6;
				}
				m_samid.SetWindowText((LPCTSTR)arrrTmp);
				int state =((CButton *)GetDlgItem(IDC_CHKREADTYPE))->GetCheck();
				int ret = Authenticate();

				//char msg[100]={0};
				//sprintf(msg, "%d-%d", ret, state);
				//::MessageBoxA(NULL,msg, msg,0);

				if (0 != ret && 1 != state)	
				{
					int sel = ::MessageBoxA(NULL, "请重新放置身份证，并点击确定。", "提示", MB_YESNO|MB_ICONQUESTION);
					if(sel == IDYES)
						continue;
					else
						break;
				}
				//if (0==Read_Content(readType) )
				if (0==Read_Content_Path(szExePath, readType) )
				{
						OnLoadddbpic();
						CloseComm(); 
						m_finger.SetWindowText("读卡成功！");
						DeleteFile("wz.txt");
						DeleteFile("xp.wlt");
						DeleteFile("zp.bmp");
						return;
				}
				else
				{
						m_finger.SetWindowText("正在读卡中");
				}								
				Sleep(100);
		}         
		m_finger.SetWindowText("读卡结束！");
	}
	else
    {
		m_finger.SetWindowText("读卡器打开失败！");
	}    	
    CloseComm(); 
}





void CMyStaticDlg::OnLoadddbpic()
{	
	CString nameType="英文名字：";
	int state=IsFPRIDCard();
	if(state==1)
	{
		byte arrTmp[100];
		int nLen = 100;
		//姓名
		GetFPR_ENName2(arrTmp, &nLen);
		m_name.SetWindowText(nameType+(LPCTSTR)arrTmp);
		//性别
		GetFPR_SEX2(arrTmp, &nLen);
		m_sex.SetWindowText((LPCTSTR)arrTmp);
		//国籍
		GetFPR_Nation2(arrTmp, &nLen);
		CString nationStr1=(LPCTSTR)arrTmp;
		GetFPR_NationCode2(arrTmp, &nLen);
		m_nation.SetWindowText(nationStr1+"/"+(LPCTSTR)arrTmp);
		//出生日期
		GetFPR_Birthday2(arrTmp, &nLen);
		CString str1 = arrTmp;
		CString str2 = arrTmp;
		CString str3 = arrTmp;
		//字符串截取
		str1 = str1.Mid(0, 4)+"年";
		str2 = str2.Mid(4,2) + "月";
		str3 = str3.Mid(6,2) + "日";
		str1 = str1 + str2 + str3;
		m_birth.SetWindowText(str1);

		//中文姓名
		nameType="中文名字：";
		GetFPR_CHNName2(arrTmp, &nLen);
		m_addr.SetWindowText(nameType+(LPCTSTR)arrTmp);
		//号码
		GetFPR_IDNo2(arrTmp, &nLen);
		m_idcode.SetWindowText((LPCTSTR)arrTmp);
		//签发机关
		GetSignGov2(arrTmp, &nLen);
		m_depart.SetWindowText("");
		//有效期限
		GetFPR_ValidStartDate2(arrTmp, &nLen);
		str1 = arrTmp;
		str2 = arrTmp;
		str3 = arrTmp;
		str1 = str1.Mid(0, 4) + "年";
		str2 = str2.Mid(4, 2) + "月";
		str3 = str3.Mid(6, 2) + "日";
		GetFPR_ValidEndDate2(arrTmp, &nLen);
		CString str4 = arrTmp;
		CString str5 = arrTmp;
		CString str6 = arrTmp;
		str4 = str4.Mid(0, 4) + "年";
		str5 = str5.Mid(4, 2) + "月";
		str6 = str6.Mid(6, 2) + "日";
		str1 = str1 + str2 + str3 +" - "+ str4 + str5 + str6;
		m_valid.SetWindowText(str1);
		//指纹信息
		
		byte arrFinger[1024];
		int fingerLen = 100;
		boolean flag=false;
		flag=GetFingerPrint(arrFinger, &fingerLen);
		if(flag)
		{
			m_finger.SetWindowText("已获取指纹");	
		}
		else
		{
			m_finger.SetWindowText("无指纹信息");
		}

		CString szXPPath, szImagesPath;
		szXPPath.Format(_T("%s%s"), szExePath, "zp.bmp");		

		////////////////////////////////////////////显示照片
		//载入图片

		if (m_bmp.m_hObject != NULL)//判断
			m_bmp.DeleteObject();

		
		HBITMAP hbmp = (HBITMAP)::LoadImage(AfxGetInstanceHandle(),
			szXPPath, IMAGE_BITMAP, 0, 0, LR_CREATEDIBSECTION | LR_LOADFROMFILE);

		//if( hbmp == NULL ) 
		//return FALSE;

		//该断程序用来取得加载的BMP的信息

		m_bmp.Attach(hbmp);

		//BITMAP bmpInfo;
		//m_bmp.GetBitmap(&bmpInfo);

		DIBSECTION ds;

		BITMAPINFOHEADER &bminfo = ds.dsBmih;

		m_bmp.GetObject(sizeof(ds), &ds);

		int cx = bminfo.biWidth;  //得到图像宽度

		int cy = bminfo.biHeight; //得到图像高度

								  //得到了图像的宽度和高度后,我们就可以对图像大小进行适应,即调整控件的大小,让它正好显示一张图片

		CRect rect;

		GetDlgItem(IDC_STATIC1)->GetWindowRect(&rect);

		ScreenToClient(&rect);

		GetDlgItem(IDC_STATIC1)->MoveWindow(rect.left, rect.top, cx, cy, true);//调整大小	


																			   //（客户区设备上下文）用于客户区的输出，
		CClientDC dc(GetDlgItem(IDC_STATIC1));

		CRect rcclient;
		GetDlgItem(IDC_STATIC1)->GetClientRect(&rcclient);

		CDC dcMemory;
		dcMemory.CreateCompatibleDC(&dc);
	
		// Select the bitmap into the in-memory DC
		CBitmap* pOldBitmap = dcMemory.SelectObject(&m_bmp);

		dc.BitBlt(rcclient.left, rcclient.top, rcclient.Width(), rcclient.Height(),
			&dcMemory, rcclient.left, rcclient.top, SRCCOPY);

		dcMemory.SelectObject(pOldBitmap);
		dcMemory.DeleteDC();
	}
	else if(state==0)
	{
		byte arrTmp[100];
		int nLen = 100;
		//姓名
		GetName2(arrTmp, &nLen);
		m_name.SetWindowText((LPCTSTR)arrTmp);
		//性别
		GetSex2(arrTmp, &nLen);
		m_sex.SetWindowText((LPCTSTR)arrTmp);
		//民族
		GetNation2(arrTmp, &nLen);
		m_nation.SetWindowText((LPCTSTR)arrTmp);
		//出生日期
		GetBornDate2(arrTmp, &nLen);
		CString str1 = arrTmp;
		CString str2 = arrTmp;
		CString str3 = arrTmp;
		//字符串截取
		str1 = str1.Mid(0, 4)+"年";
		str2 = str2.Mid(4,2) + "月";
		str3 = str3.Mid(6,2) + "日";
		str1 = str1 + str2 + str3;
		m_birth.SetWindowText(str1);
		//地址
		GetAddress2(arrTmp, &nLen);
		m_addr.SetWindowText((LPCTSTR)arrTmp);
		//号码
		GetIDNo2(arrTmp, &nLen);
		m_idcode.SetWindowText((LPCTSTR)arrTmp);
		//签发机关
		GetSignGov2(arrTmp, &nLen);
		m_depart.SetWindowText((LPCTSTR)arrTmp);
		//有效期限
		GetStartDate2(arrTmp, &nLen);
		str1 = arrTmp;
		str2 = arrTmp;
		str3 = arrTmp;
		str1 = str1.Mid(0, 4) + "年";
		str2 = str2.Mid(4, 2) + "月";
		str3 = str3.Mid(6, 2) + "日";
		GetEndDate2(arrTmp, &nLen);
		CString str4 = arrTmp;
		CString str5 = arrTmp;
		CString str6 = arrTmp;
		str4 = str4.Mid(0, 4) + "年";
		str5 = str5.Mid(4, 2) + "月";
		str6 = str6.Mid(6, 2) + "日";
		str1 = str1 + str2 + str3 +" - "+ str4 + str5 + str6;
		m_valid.SetWindowText(str1);
		//指纹信息
		
		byte arrFinger[1024];
		int fingerLen = 100;
		boolean flag=false;
		flag=GetFingerPrint(arrFinger, &fingerLen);
		if(flag)
		{
			m_finger.SetWindowText("已获取指纹");	
		}
		else
		{
			m_finger.SetWindowText("无指纹信息");
		}
		

		////////////////////////////////////////////显示照片
		//载入图片
		if (m_bmp.m_hObject != NULL)//判断
			m_bmp.DeleteObject();

		CString szXPPath;
		szXPPath.Format(_T("%s%s"), szExePath, "zp.bmp");
		HBITMAP hbmp = (HBITMAP)::LoadImage(AfxGetInstanceHandle(),
			szXPPath, IMAGE_BITMAP, 0, 0, LR_CREATEDIBSECTION | LR_LOADFROMFILE);

		if( hbmp == NULL ) 
			return;

		//该断程序用来取得加载的BMP的信息

		m_bmp.Attach(hbmp);

		//BITMAP bmpInfo;
		//m_bmp.GetBitmap(&bmpInfo);

		DIBSECTION ds;

		BITMAPINFOHEADER &bminfo = ds.dsBmih;

		m_bmp.GetObject(sizeof(ds), &ds);

		int cx = bminfo.biWidth;  //得到图像宽度

		int cy = bminfo.biHeight; //得到图像高度

								  //得到了图像的宽度和高度后,我们就可以对图像大小进行适应,即调整控件的大小,让它正好显示一张图片

		CRect rect;

		GetDlgItem(IDC_STATIC1)->GetWindowRect(&rect);

		ScreenToClient(&rect);

		GetDlgItem(IDC_STATIC1)->MoveWindow(rect.left, rect.top, cx, cy, true);//调整大小	


																			   //（客户区设备上下文）用于客户区的输出，
		CClientDC dc(GetDlgItem(IDC_STATIC1));

		CRect rcclient;
		GetDlgItem(IDC_STATIC1)->GetClientRect(&rcclient);

		CDC dcMemory;
		dcMemory.CreateCompatibleDC(&dc);
	
		// Select the bitmap into the in-memory DC
		CBitmap* pOldBitmap = dcMemory.SelectObject(&m_bmp);

		dc.BitBlt(rcclient.left, rcclient.top, rcclient.Width(), rcclient.Height(),
			&dcMemory, rcclient.left, rcclient.top, SRCCOPY);

		dcMemory.SelectObject(pOldBitmap);
		dcMemory.DeleteDC();
	}
	CString szXPPath, szImagesPath;
	szXPPath.Format(_T("%s%s"), szExePath, "zp.bmp");
	szImagesPath.Format(_T("%s%s"), szExePath, "idcard.bmp");
	//
	MakeIDCardImage((char *)szXPPath.GetBuffer(), (char *)szImagesPath.GetBuffer());
}

void CMyStaticDlg::OnPaint()
{
	if (IsIconic())
	{
		CPaintDC dc1(this); // device context for painting

		SendMessage(WM_ICONERASEBKGND, (WPARAM)dc1.GetSafeHdc(), 0);

		// Center icon in client rectangle
		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;

		// Draw the icon
		dc1.DrawIcon(x, y, m_hIcon);
	}
	else
	{
		CDialog::OnPaint();
	}

}

// The system calls this to obtain the cursor to display while the user drags
//  the minimized window.
HCURSOR CMyStaticDlg::OnQueryDragIcon()
{
	return (HCURSOR)m_hIcon;
}


void CMyStaticDlg::OnClose()
{
	PostQuitMessage(0);//最常用
}


void CMyStaticDlg::OnSelchangeList5() 
{
	//当左侧选择框 发生改变时
	int index=0;
	index = m_list.GetCurSel();
	
	switch(index)
	{
	case 0:
		m_list2.ShowWindow( SW_SHOW ); 
		break;
	case 1:
		m_list2.ShowWindow( SW_HIDE ); 
		break;
	case 2:
		m_list2.ShowWindow( SW_HIDE ); 
		break;	
	case 5:
		m_list2.ShowWindow( SW_HIDE ); 
		break;
	
	}
	
}

void CMyStaticDlg::OnChkreadtype() 
{
	// TODO: Add your control notification handler code here
	
}
