【VC开源代码栏目提醒】:网学会员,鉴于大家对VC开源代码十分关注,论文会员在此为大家搜集整理了“CloudMsgDlg.cpp”一文,供大家参考学习!
// CloudMsgDlg.cpp : implementation file
//
#include "stdafx.h"
#include "CloudMsg.h"
#include "CloudMsgDlg.h"
#include "ControlForm.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
}
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()
/////////////////////////////////////////////////////////////////////////////
// CCloudMsgDlg dialog
CCloudMsgDlg::CCloudMsgDlg(CWnd* pParent /*=NULL*/)
: CDialog(CCloudMsgDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CCloudMsgDlg)
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDI_ICON1);
}
void CCloudMsgDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CCloudMsgDlg)
DDX_Control(pDX, IDC_ReBrush, m_ReBrush);
DDX_Control(pDX, IDC_InBrush, m_InBrush);
DDX_Control(pDX, IDC_InAperture, m_InAperture);
DDX_Control(pDX, IDC_ReAperture, m_ReAperture);
DDX_Control(pDX, IDC_ReLen, m_ReLen);
DDX_Control(pDX, IDC_InLen, m_InLen);
DDX_Control(pDX, IDC_ReFoci, m_ReFoci);
DDX_Control(pDX, IDC_InFoci, m_InFoci);
DDX_Control(pDX, IDC_BUTTONRIGHT, m_ButtonRight);
DDX_Control(pDX, IDC_BUTTONLEFT, m_ButtonLeft);
DDX_Control(pDX, IDC_BUTTONUP, m_ButtonUp);
DDX_Control(pDX, IDC_BUTTONDOWN, m_ButtonDown);
DDX_Control(pDX, IDC_MSCOMM, m_Com);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CCloudMsgDlg, CDialog)
//{{AFX_MSG_MAP(CCloudMsgDlg)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_BN_CLICKED(IDC_CONTROL, OnControl)
ON_BN_CLICKED(IDC_EXIT, OnExit)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CCloudMsgDlg message handlers
BOOL CCloudMsgDlg::OnInitDialog()
{
CDialog::OnInitDialog();
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);
m_ButtonUp.m_Type = ctUp;
m_ButtonDown.m_Type = ctDown;
m_ButtonLeft.m_Type = ctLeft;
m_ButtonRight.m_Type = ctRight;
m_InFoci.m_Type = ctInFoci;
m_ReFoci.m_Type = ctReFoci;
m_InLen.m_Type = ctInLen;
m_ReLen.m_Type = ctReLen;
m_InAperture.m_Type = ctInAperture;
m_ReAperture.m_Type = ctReAperture;
m_InBrush.m_Type = ctInBrush;
m_ReBrush.m_Type = ctReBrush;
m_Len = GetPrivateProfileInt("使用字节数","字节数",8,"./stage.ini");
m_ActoinCount = GetPrivateProfileInt("控制项","控制数",13,"./stage.ini");
m_pData = new unsigned char[m_ActoinCount][MAXNUM];
m_Port = GetPrivateProfileInt("端口设置","端口号",1,"./stage.ini");
GetPrivateProfileString("端口设置","环境设置","9600,n,8,1",m_Setting.GetBuffer(0),MAX_PATH,"./stage.ini");
int data;
char buff[20] = {0};
char var[20] = {0};
for (int i = 0 ; i<m_ActoinCount ; i++)
for (int j = 0 ; j <m_Len; j++)
{
char section[20] = "字节";
itoa(i+1,var,10);
itoa(j+1,buff,10);
strcat(section,buff);
data = GetPrivateProfileInt(var,section,0,"./stage.ini");
m_pData[i][j] = data;
}
//设置端口信息,并打开端口
m_Com.SetSettings(m_Setting);
m_Com.SetOutBufferSize(512);
m_Com.SetCommPort(m_Port);
m_Com.SetSThreshold(0);
m_Com.SetPortOpen(TRUE);
return TRUE;
}
void CCloudMsgDlg::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 CCloudMsgDlg::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 CCloudMsgDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
void CCloudMsgDlg::OnOK()
{
}
//向上移动
void CCloudMsgDlg::OnUp()
{
// unsigned char data[8]= {0xff,0x02,0x00,0x08,0x00,0xff,0x10};
VARIANT vt;
SAFEARRAY* pSafe;
SAFEARRAYBOUND band;
band.cElements =m_Len;
band.lLbound = 0;
pSafe = SafeArrayCreate(VT_UI1,1,&band);
for (long i = 0; i<m_Len; i++)
{
SafeArrayPutElement(pSafe,&i,(void*)&m_pData[0][i]);
}
vt.vt= VT_ARRAY |VT_UI1;
vt.parray = pSafe;
m_Com.SetOutput((COleVariant)vt);
}
//停止移动
void CCloudMsgDlg::OnReset()
{
VARIANT vt;
SAFEARRAY* pSafe;
SAFEARRAYBOUND band;
band.cElements =m_Len;
band.lLbound = 0;
pSafe = SafeArrayCreate(VT_UI1,1,&band);
//unsigned char stopdata[7]= {0xff,0x02,0x00,0x00,0x00,0x00,0x02};
for (long i = 0; i<m_Len; i++)
{
SafeArrayPutElement(pSafe,&i,(void*)&m_pData[12][i]);
}
vt.vt= VT_ARRAY |VT_UI1;
vt.parray = pSafe;
m_Com.SetOutput((COleVariant)vt);
}
//向下移动
void CCloudMsgDlg::OnDown()
{
// unsigned char data[7]= {0xff,0x02,0x00,0x10,0x00,0xff,0x12};
VARIANT vt;
SAFEARRA
上一篇:
CloudMsg.cpp
下一篇:
一个人晕着也能去看病打针