⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 testdlg.cpp

📁 m68k手持机的通讯相关源码
💻 CPP
字号:
// testDlg.cpp : implementation file
//
#include "stdafx.h"
#include <time.h>
#include <string.h>
#include <stdio.h>
#include "test.h"
#include "testDlg.h"
#include "HD_DT_wl.h"
#include "pctohandset.h"
#include "guest_code.h"
#include "Shlwapi.h"

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

static HANDLE g_hComport=NULL;
extern unsigned char g_char_flag;
/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About

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

// Dialog Data
	//{{AFX_DATA(CAboutDlg)
	enum { IDD = IDD_ABOUTBOX };
	//}}AFX_DATA

	// ClassWizard generated virtual function overrides
	//{{AFX_VIRTUAL(CAboutDlg)
	protected:
	virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support
	//}}AFX_VIRTUAL

// Implementation
protected:
	//{{AFX_MSG(CAboutDlg)
	//}}AFX_MSG
	DECLARE_MESSAGE_MAP()
};

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

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

BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
	//{{AFX_MSG_MAP(CAboutDlg)
		// No message handlers
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CTestDlg dialog
CTestDlg::CTestDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CTestDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CTestDlg)
	//}}AFX_DATA_INIT
	// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}

void CTestDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CTestDlg)
	DDX_Control(pDX, IDC_COMBO1, m_cbTab);
	DDX_Control(pDX, IDC_PROGRESS1, m_proCtrl);
	DDX_Control(pDX, IDC_STATIC_RESULT, m_txtResult);
	DDX_Control(pDX, IDC_LIST_RESULT, m_listResult);
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CTestDlg, CDialog)
	//{{AFX_MSG_MAP(CTestDlg)
	ON_WM_SYSCOMMAND()
	ON_WM_PAINT()
	ON_WM_QUERYDRAGICON()
	ON_BN_CLICKED(IDC_CONNECT, OnConnect)
	ON_BN_CLICKED(IDC_DOWNLOAD, OnDownload)
	ON_BN_CLICKED(IDC_DISCONNECT, OnDisconnect)
	ON_BN_CLICKED(IDC_BTNHISREC, OnBtnhisrec)
	ON_BN_CLICKED(IDC_ST, OnSt)
	ON_WM_CLOSE()
	ON_BN_CLICKED(IDC_DEL_FSID, OnDelFsid)
	ON_BN_CLICKED(IDC_DEL_ALL_FS, OnDelAllFs)
	ON_MESSAGE(USER_MESSAGE_STEP,UpateStep)
	ON_MESSAGE(USER_MESSAGE_STATUS,UpateStatus)
	ON_BN_CLICKED(IDC_BTN_VERIFY, OnBtnVerify)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CTestDlg message handlers

BOOL CTestDlg::OnInitDialog()
{
	CDialog::OnInitDialog();
	// Add "About..." menu item to system menu.

	// IDM_ABOUTBOX must be in the system command range.
	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);
		}
	}

	// 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
	
	// TODO: Add extra initialization here
    /*hRevBuffMap = CreateFileMapping((HANDLE)0XFFFFFFFFF,NULL,PAGE_READWRITE,0,700000,"BuffMapFile");
    if(hRevBuffMap == INVALID_HANDLE_VALUE)
	{
		CloseHandle(hRevBuffMap);
        AfxMessageBox("Create file map error.");
	}
	
	lpvRevBuffFile = MapViewOfFile(hRevBuffMap,FILE_MAP_READ|FILE_MAP_WRITE,0,0,700000);
	if(lpvRevBuffFile==NULL)
	{
		CloseHandle(hRevBuffMap);
        AfxMessageBox("Map View of file error");
	}*/
	m_proCtrl.SetRange(0,10);
	m_proCtrl.SetPos(0);
    m_proCtrl.SetStep(1);
	DWORD dwExStyle = LVS_EX_FULLROWSELECT | LVS_EX_GRIDLINES;
	m_listResult.SendMessage(LVM_SETEXTENDEDLISTVIEWSTYLE, 0, LPARAM(dwExStyle));
	m_fsid = 0;
    UpdateData(FALSE);

	int i,ids[7] = {IDC_DISCONNECT,IDC_BTNHISREC,IDC_DOWNLOAD,IDC_ST,IDC_DEL_FSID,IDC_DEL_ALL_FS,
		IDC_BTN_VERIFY};

    for(i=0;i<7;i++)
		   GetDlgItem(ids[i])->EnableWindow(FALSE);

	GetDlgItem(IDC_CONNECT)->EnableWindow(TRUE);

	set_disp_window(this);
	for(i=0;i<g_num_tables;i++)
	{
		m_cbTab.AddString(g_TableName[i]);
	}
	m_cbTab.SetCurSel(0);
	return TRUE;  // return TRUE  unless you set the focus to a control
}

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

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

		SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.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
		dc.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 CTestDlg::OnQueryDragIcon()
{
	return (HCURSOR) m_hIcon;
}

void CTestDlg::OnBtnhisrec() 
{
	// TODO: Add your control notification handler code here
	UpdateData(TRUE);
	m_fsid = m_cbTab.GetCurSel();
	AfxBeginThread((AFX_THREADPROC)GetData,&m_fsid,THREAD_PRIORITY_NORMAL,0,0);
}

void CTestDlg::OnConnect() 
{
	// TODO: Add your control notification handler code here
	int i,ids[7] = {IDC_DISCONNECT,IDC_BTNHISREC,IDC_DOWNLOAD,IDC_ST,IDC_DEL_FSID,IDC_DEL_ALL_FS,
		         IDC_BTN_VERIFY};
	unsigned char str_dsp[100];
    DWORD start;
	UpdateData(TRUE);
	start=GetTickCount();
	if(connect_hd(&g_hComport,0,1,0,g_id_server)==SUCCESSFUL)
	{
		TRACE("Total time:%d\r\n",GetTickCount()-start);
		sprintf((char *)str_dsp,"同%d号连接成功.",0);
		m_txtResult.SetWindowText((char*)str_dsp);
		GetDlgItem(IDC_CONNECT)->EnableWindow(FALSE);
		for(i=0;i<7;i++)
		  GetDlgItem(ids[i])->EnableWindow();
		return ;
	}
	m_txtResult.SetWindowText("连接失败.");
	TRACE("Total time:%d\r\n",GetTickCount()-start);
}

void CTestDlg::OnDownload() 
{
	// TODO: Add your control notification handler code here
	CString filename,strTmp;
    char str_curr_path[300];

	UpdateData(TRUE);
	m_fsid = m_cbTab.GetCurSel();

	GetCurrentDirectory(300,str_curr_path);

    CFileDialog filedlg(TRUE,"*.txt",".\\*.txt");
	if(filedlg.DoModal()==IDOK) {
		filename = filedlg.GetPathName();
		if(filename.IsEmpty()) return;
		set_download_fn((LPSTR)(LPCTSTR)filename,m_fsid);
		m_fsid = m_cbTab.GetCurSel();
		AfxBeginThread((AFX_THREADPROC)SendData,&m_fsid,THREAD_PRIORITY_NORMAL,0,0);
	}
	SetCurrentDirectory(str_curr_path);
    return;
}
void CTestDlg::OnDisconnect() 
{
	// TODO: Add your control notification handler code here
	int i,ids[7] = {IDC_DISCONNECT,IDC_BTNHISREC,IDC_DOWNLOAD,IDC_ST,IDC_DEL_FSID,IDC_DEL_ALL_FS,
		         IDC_BTN_VERIFY}; 

	if(disconnect_hd(g_hComport)==SUCCESSFUL) 
	{
	  m_txtResult.SetWindowText("断开成功。");
	  for(i=0;i<7;i++)
			   GetDlgItem(ids[i])->EnableWindow(FALSE);
	  GetDlgItem(IDC_CONNECT)->EnableWindow(TRUE);
      g_hComport = 0;
	}
}

void CTestDlg::OnCancel() 
{
	// TODO: Add extra cleanup here
	if(g_hComport)
	{
		disconnect_hd(g_hComport);
	}
	CDialog::OnCancel();
}


void CTestDlg::OnSt() 
{
	// TODO: Add your control notification handler code here
    set_time_pc(g_hComport);
}

BOOL CTestDlg::OnCommand(WPARAM wParam, LPARAM lParam) 
{
	// TODO: Add your specialized code here and/or call the base class
	
	return CDialog::OnCommand(wParam, lParam);
}

LRESULT CTestDlg::UpateStatus(WPARAM wParam, LPARAM lParam)
{
	int count,i ;

	m_txtResult.SetWindowText((char*)lParam);
    switch(wParam)
	{
	case ID_MESSAGE_NORECORDRETURN:
		 Beep(1000,1000);
		 break;
	case ID_MESSAGE_ASKDBCOUNT_ERROR:
		 Beep(1000,1000);
         break;
	case ID_PROGRESS_REVDATA_START:
		 count = m_listResult.GetHeaderCtrl()->GetItemCount();
		 m_listResult.DeleteAllItems();
		 for(i=count-1;i>=0;i--) m_listResult.DeleteColumn(i);
		 break;
	case ID_PROGRESS_DATASAVE_END:
		 break;
    case ID_MESSAGE_DISP_FILE_NAME:
		 DispResult((char*)lParam);
		 break;
	default:
		 break;
	}
	return 0;
}

LRESULT CTestDlg::UpateStep(WPARAM wParam, LPARAM lParam)
{
	int i,ids[7] = {IDC_BTNHISREC,IDC_DOWNLOAD,IDC_ST,IDC_DEL_FSID,IDC_DEL_ALL_FS,
		         IDC_BTN_VERIFY};
	             
	int iMax;
    iMax = 6;
	switch(wParam)
	{
		case ID_PROGRESS_START:
			 m_proCtrl.SetRange(0,10);
			 m_proCtrl.SetPos(0);
			 m_proCtrl.SetStep(1);
			 for(i=0;i<iMax;i++)
			   GetDlgItem(ids[i])->EnableWindow(FALSE);
			 break;
		case ID_PROGRESS_END:
			 m_proCtrl.SetPos(10);
			 for(i=0;i<iMax;i++)
			   GetDlgItem(ids[i])->EnableWindow();
			 break;
		case ID_PROGRESS_STEPONE:
			 m_proCtrl.StepIt();
			 break;
		default:
			 break;
	}

	return 0;
}

void CTestDlg::DispResult(char *fn)
{
	CString strTmp;
	CString strTmp1,strTmp2;
	char arrTmp[80];
	CStdioFile file;
	char strRead[80];
	char *pStrTmp;

    int i,j;
	LVCOLUMN lvc;
    int numOfPage = 18;
	lvc.mask = LVCF_FMT|LVCF_SUBITEM|LVCF_TEXT|LVCF_WIDTH;
	lvc.iSubItem = 0;
	lvc.cx = 80;
	lvc.fmt = LVCFMT_CENTER;
	lvc.cchTextMax = 8;
	LVITEM lvi;
	lvi.mask = LVIF_TEXT;
    
//FSID_TOLLER FSID_PLAZA FSID_EXITTRAFFIC
//remove all item from list control    
	int count = m_listResult.GetHeaderCtrl()->GetItemCount();
	m_listResult.DeleteAllItems();
	for(i=count-1;i>=0;i--) m_listResult.DeleteColumn(i);
    if(!file.Open((char*)fn,CFile::modeRead))
	{
		AfxMessageBox("File open error,display fail.");
		return;
	}
    
	file.ReadString(strTmp);

	lvc.pszText = "序号";
	m_listResult.InsertColumn(0,&lvc);
	pStrTmp = (LPSTR)(LPCTSTR)strTmp;
	strTmp.Replace(g_char_flag,' ');
	for(j=0;1;j++)
	{
			if(sscanf(pStrTmp,"%s",strRead)==EOF) break;
			pStrTmp = strstr(pStrTmp,(const char*)strRead) + strlen(strRead);
			lvc.pszText = strRead;
			m_listResult.InsertColumn(j+1,&lvc);
	}

	i=0;
	while(file.ReadString(strTmp))
	{
				lvi.iItem = i;
				lvi.iSubItem = 0;
				lvi.pszText = itoa(i+1,arrTmp,10);
				m_listResult.InsertItem(&lvi);
				strTmp = remove_space(strTmp);
				strTmp1.Format("%c%c",g_char_flag,g_char_flag);
				strTmp2.Format("%c0%c",g_char_flag,g_char_flag);
			    while(strTmp.Find(strTmp1,0)!=-1) 
				    strTmp.Replace(strTmp1,strTmp2);
				strTmp.Replace(g_char_flag,' ');
				pStrTmp = (LPSTR)(LPCTSTR)strTmp;
			    for(j=0;1;j++)
				{
					if(sscanf(pStrTmp,"%s",strRead)==EOF) break;
					pStrTmp = strstr(pStrTmp,(const char*)strRead) + strlen(strRead);
					lvi.iItem = i;
					lvi.iSubItem = j+1;
					lvi.pszText = strRead;
					m_listResult.SetItem(&lvi);
				}
				i++;
				strTmp.Empty();
		}
    file.Close();
}

void CTestDlg::OnClose() 
{
	// TODO: Add your message handler code here and/or call default
	if(g_hComport)
	{
		disconnect_hd(g_hComport);
	}
	CDialog::OnClose();
}

void CTestDlg::OnDelFsid() 
{
	// TODO: Add your control notification handler code here
	UpdateData(TRUE);
	m_fsid = m_cbTab.GetCurSel();

	int ret = AfxMessageBox("该操作将删除手持机上该表所有数据,确认吗?",MB_YESNO);
	if(ret == IDYES) 
	{
		 UpdateData(TRUE);
	     del_tab(g_hComport,m_fsid);
	}
}

void CTestDlg::OnDelAllFs() 
{
	// TODO: Add your control notification handler code here
	int ret = AfxMessageBox("该操作将删除手持机上所有表的数据,确认吗?",MB_YESNO);
	if(ret == IDYES) 
	{
		 init_db(g_hComport);
	}
}

void CTestDlg::OnBtnVerify() 
{
	// TODO: Add your control notification handler code here
	UpdateData(TRUE);
	m_fsid = m_cbTab.GetCurSel();
	verify_tab(g_hComport,m_fsid);	
}





⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -