📄 htkjdlg.cpp
字号:
// HTKJDlg.cpp : implementation file
//
#include "stdafx.h"
#include "HTKJ.h"
#include "HTKJDlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// 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
//}}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()
/////////////////////////////////////////////////////////////////////////////
// CHTKJDlg dialog
CHTKJDlg::CHTKJDlg(CWnd* pParent /*=NULL*/)
: CDialog(CHTKJDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CHTKJDlg)
m_ShowTitle = TRUE;
m_ReSizeFlag = FALSE;
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
// 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 CHTKJDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CHTKJDlg)
// NOTE: the ClassWizard will add DDX and DDV calls here
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CHTKJDlg, CDialog)
//{{AFX_MSG_MAP(CHTKJDlg)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_WM_NCLBUTTONDOWN()
ON_WM_NCMOUSEMOVE()
ON_WM_SIZE()
ON_WM_MOUSEMOVE()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CHTKJDlg message handlers
BOOL CHTKJDlg::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
DWORD style=WS_VISIBLE|WS_CHILD;
if(!m_Comm.Create(NULL,style,CRect(0,0,0,0),this,IDC_MSCOMM))
{
TRACE0("Failed to create OLE Communication Control!\n");
return -1;
}
m_Comm.SetCommPort(1);//设置串口编号
m_Comm.SetInputMode(1);//二进制方式读取
m_Comm.SetInBufferCount(0);//清空
m_Comm.SetInBufferSize(1024); //大少
m_Comm.SetOutBufferCount(0);
m_Comm.SetOutBufferSize(1024);
m_Comm.SetSettings("9600,n,8,1");//无校验N
m_Comm.SetRThreshold(3);//阀值
m_Comm.SetInputLen(0);//读取整个缓冲区内容
if(!m_Comm.GetPortOpen())
{
m_Comm.SetPortOpen(TRUE);
}
return TRUE; // return TRUE unless you set the focus to a control
}
/*void CHTKJDlg::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 CHTKJDlg::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 CHTKJDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
BEGIN_EVENTSINK_MAP(CHTKJDlg, CDialog)
//{{AFX_EVENTSINK_MAP(CHTKJDlg)
ON_EVENT(CHTKJDlg, IDC_MSCOMM, 1 /* OnComm */, OnOnCommMscomm, VTS_NONE)
//}}AFX_EVENTSINK_MAP
END_EVENTSINK_MAP()
void CHTKJDlg::OnOnCommMscomm()
{
// TODO: Add your control notification handler code here
VARIANT input1;
BYTE rxdata[2048];
long len1,k;
COleSafeArray safearray1;
CString sql,st,st1,st2,st3,st4,st5,st6,st7,str,m_ReceiveData;
input1=m_Comm.GetInput();
safearray1=input1;
len1=safearray1.GetOneDimSize();
for(k=0;k<len1;k++)
safearray1.GetElement(&k,rxdata+k);
extern CHTKJApp theApp;
st="满意";
st1="一般";
st2="服务态度";
st3="服务质量";
st4="服务速度";
st5="没有评价";
st6="不满意";
switch(rxdata[2])
{
case 0x2a: { COleDateTime time;
time=COleDateTime::GetCurrentTime();
m_time=time.Format("%Y-%m-%d %H:%M:%S");}
break;
case 0xa1: { COleDateTime time=COleDateTime::GetCurrentTime();
CString p_time=time.Format("%Y-%m-%d %H:%M:%S");
sql.Format("insert into pfmark(M_serverno,M_pingjia,M_yetime,M_ptime) values('%s','%s','%s','%s')",(theApp.IDstr),st,m_time,p_time);
theApp.AdoConnection->Execute(_bstr_t(sql),NULL,adCmdText);}
break;
case 0xa2: { COleDateTime time=COleDateTime::GetCurrentTime();
CString p_time=time.Format("%Y-%m-%d %H:%M:%S");
sql.Format("insert into pfmark(M_serverno,M_pingjia,M_yetime,M_ptime) values('%s','%s','%s','%s')",(theApp.IDstr),st1,m_time,p_time);
theApp.AdoConnection->Execute(_bstr_t(sql),NULL,adCmdText);
}
break;
case 0xa4: { COleDateTime time=COleDateTime::GetCurrentTime();
CString p_time=time.Format("%Y-%m-%d %H:%M:%S");
sql.Format("insert into pfmark(M_serverno,M_pingjia,M_yetime,M_ptime) values('%s','%s','%s','%s')",(theApp.IDstr),st5,m_time,p_time);
theApp.AdoConnection->Execute(_bstr_t(sql),NULL,adCmdText);
}
break;
case 0xa5: { COleDateTime time=COleDateTime::GetCurrentTime();
CString p_time=time.Format("%Y-%m-%d %H:%M:%S");
sql.Format("insert into pfmark(M_serverno,M_pingjia,M_yetime,M_ptime) values('%s','%s','%s','%s')",(theApp.IDstr),st2,m_time,p_time);
theApp.AdoConnection->Execute(_bstr_t(sql),NULL,adCmdText);}
break;
case 0xa6: { COleDateTime time=COleDateTime::GetCurrentTime();
CString p_time=time.Format("%Y-%m-%d %H:%M:%S");
sql.Format("insert into pfmark(M_serverno,M_pingjia,M_yetime,M_ptime) values('%s','%s','%s','%s')",(theApp.IDstr),st3,m_time,p_time);
theApp.AdoConnection->Execute(_bstr_t(sql),NULL,adCmdText);}
break;
case 0xa7: { COleDateTime time=COleDateTime::GetCurrentTime();
CString p_time=time.Format("%Y-%m-%d %H:%M:%S");
sql.Format("insert into pfmark(M_serverno,M_pingjia,M_yetime,M_ptime) values('%s','%s','%s','%s')",(theApp.IDstr),st4,m_time,p_time);
theApp.AdoConnection->Execute(_bstr_t(sql),NULL,adCmdText);}
break;
case 0xa8: { COleDateTime time=COleDateTime::GetCurrentTime();
CString p_time=time.Format("%Y-%m-%d %H:%M:%S");
sql.Format("insert into pfmark(M_serverno,M_pingjia,M_yetime,M_ptime) values('%s','%s','%s','%s')",(theApp.IDstr),st6,m_time,p_time);
theApp.AdoConnection->Execute(_bstr_t(sql),NULL,adCmdText);}
break;
default:;
}
}
void CHTKJDlg::OnOK()
{
// TODO: Add extra validation here
CCuoWUDlg CWDlg;
CWDlg.DoModal();
//CDialog::OnOK();
}
void CHTKJDlg::OnCancel()
{
// TODO: Add extra cleanup here
extern CHTKJApp theApp;
theApp.m_BaseFlag=4;
CuoWUDlg CWDlg;
int i=CWDlg.DoModal();
if(i==1)
{CDialog::OnCancel();}
// CDialog::OnCancel();
}
/*HCURSOR CHTKJDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}*/
LRESULT CHTKJDlg::DefWindowProc(UINT message, WPARAM wParam, LPARAM lParam)
{
LRESULT lrst=CDialog::DefWindowProc(message, wParam, lParam);
if (!::IsWindow(m_hWnd))
return lrst;
if (message==WM_MOVE||message==WM_PAINT||message==WM_NCPAINT||message==WM_NCACTIVATE ||message == WM_NOTIFY)
{
CDC* pWinDC = GetWindowDC();
if (pWinDC)
DrawTitleBar(pWinDC);
ReleaseDC(pWinDC);
}
return lrst;
}
void CHTKJDlg::OnNcLButtonDown(UINT nHitTest, CPoint point)
{
CRect rtWnd;
GetWindowRect(&rtWnd);
//mouse坐标转化为本窗口坐标 重要
point.x = point.x - rtWnd.left;
point.y = point.y - rtWnd.top;
//检测各按钮是否按到
if (m_rtIcon.PtInRect(point))
AfxMessageBox("检测各按钮是否按到");
else
{
if (m_rtButtHelp.PtInRect(point))
{
SendMessage(WM_HELP);
}
else
{
if (m_rtButtExit.PtInRect(point))
{
SendMessage(WM_CLOSE);
}
else
{
if (m_rtButtMin.PtInRect(point))
{
m_ShowTitle = FALSE;
SendMessage(WM_SYSCOMMAND, SC_MINIMIZE, MAKELPARAM(point.x, point.y));
}
else
{
if (m_rtButtMax.PtInRect(point))
{
m_ShowTitle = TRUE;
if (IsZoomed())
SendMessage(WM_SYSCOMMAND, SC_RESTORE, MAKELPARAM(point.x, point.y));
else
{
// SendMessage(WM_SYSCOMMAND, SC_MAXIMIZE, MAKELPARAM(point.x, point.y));
Invalidate();
}
}
else
{
if (!IsZoomed())
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -