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

📄 mypagerdlg.cpp

📁 一个VC编写的寻呼编码测试软件代码
💻 CPP
字号:
// myPagerDlg.cpp : implementation file
//

#include "stdafx.h"
#include "myPager.h"
#include "myPagerDlg.h"
#include "ComSet.h"


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

extern CMyPagerApp theApp;
/////////////////////////////////////////////////////////////////////////////
// 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()

/////////////////////////////////////////////////////////////////////////////
// CMyPagerDlg dialog

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

void CMyPagerDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CMyPagerDlg)
	DDX_Control(pDX, IDC_COMSET, m_cComSet);
	DDX_Control(pDX, IDC_CLEAR, m_cClear);
	DDX_Control(pDX, IDC_TEXT, m_cText);
	DDX_Control(pDX, IDC_COMBO_VOICE, m_cVoice);
	DDX_Control(pDX, IDC_COMBO_CATE, m_cCate);
	DDX_Control(pDX, IDC_SEND, m_cSend);
	DDX_Control(pDX, IDOK, m_cIDOK);
	DDX_Control(pDX, IDC_LIST1, m_cList);
	DDX_Control(pDX, IDC_YHH, m_cYhh);
	DDX_Text(pDX, IDC_YHH, m_sYhh);
	DDV_MaxChars(pDX, m_sYhh, 7);
	DDX_Text(pDX, IDC_TEXT, m_sText);
	DDX_Control(pDX, IDC_MSCOMM1, m_cComm);
	DDX_Control(pDX, IDC_WINSOCK1, m_cWinsock);
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CMyPagerDlg, CDialog)
	//{{AFX_MSG_MAP(CMyPagerDlg)
	ON_WM_SYSCOMMAND()
	ON_WM_PAINT()
	ON_WM_QUERYDRAGICON()
	ON_NOTIFY(NM_CLICK, IDC_LIST1, OnClickList1)
	ON_BN_CLICKED(IDC_SEND, OnSend)
	ON_BN_CLICKED(IDC_CLEAR, OnClear)
	ON_BN_CLICKED(IDC_COMSET, OnComset)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CMyPagerDlg message handlers

BOOL CMyPagerDlg::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

	v_iComm=0;
	v_iSpeed=2;

	if(v_iSpeed==0?v_sSpeed="1200":(v_iSpeed==1?v_sSpeed="2400":
    	(v_iSpeed==2?v_sSpeed="4800":(v_iSpeed==3?v_sSpeed="9600":v_sSpeed="0"))))


	m_cComm.SetCommPort(v_iComm+1);	//COM1
	m_cComm.SetSettings(v_sSpeed+",n,8,1");

	if( !m_cComm.GetPortOpen())
	{
		m_cComm.SetPortOpen(TRUE);						//打开串口
		m_cComm.SetDTREnable(TRUE);						//DTR有效
	}
	::SendMessage(m_cList.m_hWnd, LVM_SETEXTENDEDLISTVIEWSTYLE,LVS_EX_FULLROWSELECT, LVS_EX_FULLROWSELECT);
	//////////为列表控件添加列//////////
  	m_cList.InsertColumn(0," 发射号",LVCFMT_CENTER,70);
   	m_cList.InsertColumn(1,"        寻    呼    内    容",LVCFMT_LEFT,290);
   	m_cList.InsertColumn(2,"时  间",LVCFMT_CENTER,74);
	m_cList.SetExtendedStyle(m_cList.GetExtendedStyle()|LVS_EX_GRIDLINES);

	UpdateData(false);

	m_cCate.SetCurSel(2);
	m_cVoice.SetCurSel(2);
	m_sText="寻呼台欢迎您!";
	m_cText.SetWindowText(m_sText);

	CString v_strCom;
	if(v_iComm==0?v_strCom="COM1":(v_iComm==1?v_strCom="COM2":v_strCom="无效"))
	GetDlgItem(IDC_COMNUM)->SetWindowText(v_strCom);
	GetDlgItem(IDC_COMSPEED)->SetWindowText(v_sSpeed+"bps");
	
	return TRUE;  // return TRUE  unless you set the focus to a control
}

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

// 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 CMyPagerDlg::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 CMyPagerDlg::OnQueryDragIcon()
{
	return (HCURSOR) m_hIcon;
}

void CMyPagerDlg::OnClickList1(NMHDR* pNMHDR, LRESULT* pResult) 
{
	// TODO: Add your control notification handler code here
	
	*pResult = 0;
}

BEGIN_EVENTSINK_MAP(CMyPagerDlg, CDialog)
    //{{AFX_EVENTSINK_MAP(CMyPagerDlg)
	ON_EVENT(CMyPagerDlg, IDC_MSCOMM1, 1 /* OnComm */, OnOnCommMscomm1, VTS_NONE)
	//}}AFX_EVENTSINK_MAP
END_EVENTSINK_MAP()

void CMyPagerDlg::OnOnCommMscomm1() 
{
	// TODO: Add your control notification handler code here
	
}
BOOL CMyPagerDlg::PreTranslateMessage(MSG* pMsg) 
{
	// TODO: Add your specialized code here and/or call the base class

	if (pMsg->message==WM_KEYDOWN && pMsg->wParam==VK_RETURN)
	{
		CWnd* v_wCtrl=GetFocus();					//获得焦点
		if (v_wCtrl==&m_cIDOK)						//列表窗回车
		{
			OnOK();									
			return true;
		}
		if (v_wCtrl==&m_cSend)
		{
			OnSend();
			return true;
		}

		if (v_wCtrl==&m_cClear)
		{
			OnClear();
			return true;
		}
		if (v_wCtrl==&m_cComSet)
		{
			OnComset();
			return true;
		}


		CDialog* Pwnd=(CDialog*)GetActiveWindow();	//取得对话框指针 
		Pwnd->NextDlgCtrl();						//切换到下一个输入焦点 
		return true;
	}
	
	
	return CDialog::PreTranslateMessage(pMsg);
}


bool CMyPagerDlg::We_yhh()
{
	CString v_sNum,v_sNam;
	bool v_bReturn=true;
/*	CString v_sVi="SELECT * FROM set_user where zfsh='"+m_sYhh+"'";
	v_bSuccess=false;
	try
	{
		v_pRecordset.CreateInstance("ADODB.Recordset");
		v_pRecordset->Open((_bstr_t)v_sVi,_variant_t((IDispatch*)theApp.m_pConnection,true),adOpenStatic,adLockOptimistic,adCmdText);
	    v_bSuccess=true;
		if (v_pRecordset->adoEOF)
		{
			::MessageBox(NULL,"  该用户不存在!!!  ","信息提示!",MB_OK);
			v_bReturn = false;
		}
		else
		{
			v_sJz = v_pRecordset->GetCollect("zjz").bstrVal;
			v_sFsh = v_pRecordset->GetCollect("zfsh").bstrVal;
		}
	}
	catch(_com_error e)///捕捉异常
	{
		::MessageBox(NULL,"  读取数据库失败 !!!  ","信息提示!",MB_OK);
		v_bReturn = false;
	}
	if(v_bSuccess)
		v_pRecordset->Close();
*/	return v_bReturn;

}

void CMyPagerDlg::We_Send()
{
	CString v_sNum,v_sNam;// 字符类型
	CString v_sCate,v_sVoice;v_sJz;
	CString v_sFsh;

	m_cYhh.GetWindowText(v_sFsh);         //取发射号
	m_cCate.GetWindowText(v_sCate);		  //取寻呼机类型
	m_cVoice.GetWindowText(v_sVoice);     //取寻呼机音响

	unsigned long v_lSelect;
	bool v_bReturn=true;
	CTime v_Time=CTime::GetCurrentTime();
	CString v_sTemp;
	v_sTemp=v_Time.Format("%y-%m-%d");
	v_sTemp+=" "+v_Time.Format("%H:%M:%S");
	
	int v_nCate=m_cCate.GetCurSel();    //得到当前组合框序号
	//把对应组合框序号的值换成寻呼机类型代码

	CString v_sVi;
	if(v_nCate==0?v_sJz="V":(v_nCate==1?v_sJz="B":v_nCate==2?v_sJz="W":(v_nCate==3?v_sJz="Q":v_sJz="A")))

//	if(v_sCate=="1200 汉字"?v_sJz="W":(v_sCate=="1200 数字"?v_sJz="Q":v_sCate==" 512 汉字"?v_sJz="V":(v_sCate==" 512 数字"?v_sJz="B":v_sJz="A")));
	v_sVi="INSERT INTO xhda (zfsh,zjz,znr,ztime) VALUES ('"+v_sFsh+"','"+v_sJz+"','"+m_sText+"','"+v_sTemp+"')";

	v_bSuccess=false;
	try
	{
		v_pRecordset.CreateInstance("ADODB.Recordset");
		v_pRecordset->Open((_bstr_t)v_sVi,_variant_t((IDispatch*)theApp.m_pConnection,true),adOpenStatic,adLockOptimistic,adCmdText);
	    v_bSuccess=true;
	}
	catch(_com_error e)///捕捉异常
	{
		::MessageBox(NULL,"  读取寻呼档案库失败 !!!  ","信息提示!",MB_OK);
		v_bReturn = false;
	}
	if(v_bSuccess)
	{
		v_sNam=v_sJz+m_sYhh+v_sVoice;
		v_sNam+=m_sText;
		v_sNam+=0x0d;//回车  0x0a换行
		m_cComm.SetOutput(COleVariant(v_sNam));	

		v_lSelect=m_cList.InsertItem(0xff,m_sYhh);
		m_cList.SetItem(v_lSelect,1,1,v_sNam,NULL,0,0,0);

		CTime v_CurTime;
	    v_CurTime=CTime::GetCurrentTime() ;		
		m_cList.SetItem(v_lSelect,2,1,v_CurTime.Format("%H:%M:%S"),NULL,0,0,0);
		if (m_cList.GetItemCount()>100)
			m_cList.DeleteItem(0);
		m_cList.EnsureVisible(m_cList.GetItemCount()-1,false);
		UpdateData(false);

		m_sText=_T("");
	}
	return;

}


void CMyPagerDlg::OnSend() 
{
	// TODO: Add your control notification handler code here
	UpdateData(true);
	m_sYhh.TrimLeft(" ");
	m_sText.TrimLeft(" "); 
	if(m_sYhh.IsEmpty()||m_sText.IsEmpty())
	{
		::MessageBox(NULL," 请输入用户号及寻呼信息!!!","信息提示",MB_OK);
		return;
	}	

	if(We_yhh())
	{
		We_Send();
		m_cYhh.SetFocus();
		UpdateData(false);
	}
}




void CMyPagerDlg::OnClear() 
{
	// TODO: Add your control notification handler code here
	m_sText=_T("");
	m_cText.SetWindowText(m_sText);
	m_cText.SetFocus();
}

void CMyPagerDlg::OnComset() 
{

	// TODO: Add your control notification handler code here

	CComSet ComDlg;
	ComDlg.v_iComm=v_iComm;
	ComDlg.v_iSpeed=v_iSpeed;

	if (ComDlg.DoModal()==IDOK)
	{
		
		m_cComm.SetPortOpen(false);						//关闭串口
		m_cComm.SetDTREnable(false);					//DTR无效
		

		v_iComm=ComDlg.v_iComm;
		v_iSpeed=ComDlg.v_iSpeed;

   	if(v_iSpeed==0?v_sSpeed="1200":(v_iSpeed==1?v_sSpeed="2400":
    	(v_iSpeed==2?v_sSpeed="4800":(v_iSpeed==3?v_sSpeed="9600":v_sSpeed="0"))))

		m_cComm.SetCommPort(v_iComm+1);				//设置串口号
		m_cComm.SetSettings(v_sSpeed+",n,8,1");    //设置速率等参数

	
		m_cComm.SetPortOpen(TRUE);						//打开串口
		m_cComm.SetDTREnable(TRUE);						//DTR有效
		

		CString v_strCom;
		if(v_iComm==0?v_strCom="COM1":(v_iComm==1?v_strCom="COM2":v_strCom="无效"))
		GetDlgItem(IDC_COMNUM)->SetWindowText(v_strCom);   //更新对话框串口显示状态
		GetDlgItem(IDC_COMSPEED)->SetWindowText(v_sSpeed+"bps");
	}
	
	m_cYhh.SetFocus();  //设焦点
}

⌨️ 快捷键说明

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