求大神解决下问题,项目最后阶段,急求
mfc吧
全部回复
仅看楼主
level 1
这是点击X按钮,读取编辑框内容后出现的错误,不知道怎么修改。求各位大神赐教,时间紧迫,请帮帮忙。
下面试CPP源代码:
#include "stdafx.h"
#include "laserscan.h"
#include <stdlib.h>
#include "dmcwin.h"
#include "laserscanDoc.h"
#include "laserscanView.h"
#include "stdlib.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CLaserscanView
IMPLEMENT_DYNCREATE(CLaserscanView, CFormView)
BEGIN_MESSAGE_MAP(CLaserscanView, CView)
//{{AFX_MSG_MAP(CLaserscanView)
ON_BN_CLICKED(IDC_EXIT, OnExit)
ON_BN_CLICKED(IDC_MOVEWIDTH, OnMovewidth)
ON_BN_CLICKED(IDC_MOTIONRESET, OnMotionreset)
ON_BN_CLICKED(IDC_MOTION3NOTEN, OnMotion3noten)
ON_BN_CLICKED(IDC_MOTION3EN, OnMotion3en)
ON_WM_VSCROLL()
//}}AFX_MSG_MAP
// Standard printing commands
ON_COMMAND(ID_FILE_PRINT, CView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_DIRECT, CView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_PREVIEW, CView::OnFilePrintPreview)
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CLaserscanView construction/destruction
CLaserscanView::CLaserscanView()
: CFormView(CLaserscanView::IDD)
{
}
CLaserscanView::~CLaserscanView()
{
}
BOOL CLaserscanView::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
return CView::PreCreateWindow(cs);
}
/////////////////////////////////////////////////////////////////////////////
// CLaserscanView
/////////////////////////////////////////////////////////////////////////////
// CLaserscanView printing
void CLaserscanView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add extra initialization before printing
}
void CLaserscanView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add cleanup after printing
}
void CLaserscanView::OnPrint(CDC* pDC, CPrintInfo* /*pInfo*/)
{
// TODO: add customized printing code here
}
/////////////////////////////////////////////////////////////////////////////
// CLaserscanView diagnostics
#ifdef _DEBUG
void CLaserscanView::AssertValid() const
{
CView::AssertValid();
}
void CLaserscanView::Dump(CDumpContext& dc) const
{
CView::Dump(dc);
}
CLaserscanDoc* CLaserscanView::GetDocument() // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CLaserscanDoc)));
return (CLaserscanDoc*)m_pDocument;
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CLaserscanView message handlers
void CLaserscanView::OnExit()
{
// TODO: Add your control notification handler code here
AfxGetMainWnd()->GetMenu()->EnableMenuItem(3,MF_BYPOSITION|MF_ENABLED);
char szResponse[4096];
CString TempString;
TempString="MO;";
m_DMCWin.Command((char*)((const char*)TempString), szResponse, sizeof(szResponse));
m_DMCWin.Close();
exit(0);
GetDlgItem(IDC_EXIT)->EnableWindow(TRUE);
}
void CLaserscanView::OnMovewidth()
{
// TODO: Add your control notification handler code here
GetDlgItem(IDC_MOVEWIDTH)->EnableWindow(FALSE);
GetDlgItem(IDC_MOTIONRESET)->EnableWindow(FALSE);
GetDlgItem(IDC_MOTION3EN)->EnableWindow(FALSE);
GetDlgItem(IDC_MOTION3NOTEN)->EnableWindow(FALSE);
GetDlgItem(IDC_EXIT)->EnableWindow(FALSE);
UpdateData(1);
double wid;
wid=atof(m_xmove)*1638.4;
CString wid1,plu;
plu="PR";
wid1.Format("%f",wid);
plu+=wid1+";MTX=2;BGX;EN;";
char szResponse[4096];
m_DMCWin.Command((char*)((const char*)plu), szResponse, sizeof(szResponse));
if(szResponse[0]!=*:*)
{
AfxMessageBox("请确认是否已上电");
GetDlgItem(IDC_MOVEWIDTH)->EnableWindow(TRUE);
return;
}
GetDlgItem(IDC_MOVEWIDTH)->EnableWindow(TRUE);
GetDlgItem(IDC_MOTIONRESET)->EnableWindow(TRUE);
GetDlgItem(IDC_MOTION3EN)->EnableWindow(TRUE);
GetDlgItem(IDC_MOTION3NOTEN)->EnableWindow(TRUE);
GetDlgItem(IDC_EXIT)->EnableWindow(TRUE);
}
void CLaserscanView::OnMotionreset()
{
// TODO: Add your control notification handler code here
GetDlgItem(IDC_MOTIONRESET)->EnableWindow(FALSE);
GetDlgItem(IDC_MOVEWIDTH)->EnableWindow(FALSE);
GetDlgItem(IDC_MOTION3EN)->EnableWindow(FALSE);
GetDlgItem(IDC_MOTION3NOTEN)->EnableWindow(FALSE);
GetDlgItem(IDC_EXIT)->EnableWindow(FALSE);
CString pos;
pos="V1=_TPA;PR-V1,BGA;EN";
char szResponse[40];
m_DMCWin.Command((char*)((const char*)pos), szResponse, sizeof(szResponse));
if(szResponse[0]!=*:*)
{
AfxMessageBox("请确认是否已上电");
GetDlgItem(IDC_MOTIONRESET)->EnableWindow(TRUE);
return;
}
GetDlgItem(IDC_MOTIONRESET)->EnableWindow(TRUE);
GetDlgItem(IDC_MOVEWIDTH)->EnableWindow(TRUE);
GetDlgItem(IDC_MOTION3EN)->EnableWindow(TRUE);
GetDlgItem(IDC_MOTION3NOTEN)->EnableWindow(TRUE);
GetDlgItem(IDC_EXIT)->EnableWindow(TRUE);
}
void CLaserscanView::OnMotion3noten()
{
// TODO: Add your control notification handler code here
AfxGetMainWnd()->GetMenu()->EnableMenuItem(1,MF_BYPOSITION|MF_ENABLED);
char szResponse[4096];
CString TempString;
TempString="MO;";
m_DMCWin.Command((char*)((const char*)TempString), szResponse, sizeof(szResponse));
m_DMCWin.Close();
GetDlgItem(IDC_MOTIONRESET)->EnableWindow(FALSE);
GetDlgItem(IDC_MOVEWIDTH)->EnableWindow(FALSE);
GetDlgItem(IDC_MOTION3NOTEN)->EnableWindow(FALSE);
}
void CLaserscanView::OnMotion3en()
{
// TODO: Add your control notification handler code here
AfxGetMainWnd()->GetMenu()->EnableMenuItem(1,MF_BYPOSITION|MF_DISABLED|MF_GRAYED);
GetDlgItem(IDC_MOTION3EN)->EnableWindow(FALSE);
// TODO: Add your control notification handler code here
CEdit* pEdit = (CEdit*)GetDlgItem(IDC_STATUS1);
CDMCWinRegistry DMCWinRegistry;
GALILREGISTRY galilregistry;
// Is the controller registered?
if (DMCWinRegistry.GetGalilRegistryInfo(nController, &galilregistry) != 0)
{
pEdit->SetWindowText("Could not find controller in the Windows registry");
GetDlgItem(IDC_MOTION3EN)->EnableWindow(TRUE);
}
// Initialize the DMCWin object
m_DMCWin.SetController(nController);// Controller 1 in the Windows registry
m_DMCWin.SethWnd(GetSafeHwnd());// Our hWnd;
// Open a connection to the controller
m_DMCWin.Open();
if (m_DMCWin.IsConnected())
{
// Display the controller version information
//if (m_DMCWin.GetVersion(szVersion, sizeof(szVersion)) == 0)
//pEdit->SetWindowText(szVersion);
}
else
{
// Report error
char szMessage[128];
CString TempString;
m_DMCWin.GetErrorText(m_DMCWin.GetLastError(), szMessage, sizeof(szMessage));
TempString = "Could not connect to controller. ";
TempString += szMessage;
AfxMessageBox(TempString);
//pEdit->SetWindowText("Not connected with controller");
}
char szResponse[4096];
CString TempString;
TempString="SH;";
m_DMCWin.Command((char*)((const char*)TempString), szResponse, sizeof(szResponse));
if(szResponse[0]!=*:*)
{
AfxMessageBox("电机上电失败");
GetDlgItem(IDC_MOTION3EN)->EnableWindow(TRUE);
return;
}
GetDlgItem(IDC_MOTION3EN)->EnableWindow(TRUE);
GetDlgItem(IDC_MOTIONRESET)->EnableWindow(TRUE);
GetDlgItem(IDC_MOVEWIDTH)->EnableWindow(TRUE);
GetDlgItem(IDC_MOTION3NOTEN)->EnableWindow(TRUE);
GetDlgItem(IDC_EXIT)->EnableWindow(TRUE);
}
BOOL CLaserscanView::OnPreparePrinting(CPrintInfo* pInfo)
{
// default preparation
return DoPreparePrinting(pInfo);
}
void CLaserscanView::OnInitialUpdate()
{
CView::OnInitialUpdate();
GetParentFrame()->RecalcLayout();
ResizeParentToFit();
//初始化,使各编辑框为0
CString init;
init="0.0";
SetDlgItemText(IDC_EDIT_WIDTH,init);
//字体大小设置
font1.CreatePointFont(150,"Times New Roman");
GetDlgItem(IDC_EDIT_WIDTH)->SetFont(&font1);
GetDlgItem(IDC_STATIC_W)->SetFont(&font1);
font2.CreatePointFont(350,"黑体");
GetDlgItem(IDC_MOTION3EN)->SetFont(&font2);
GetDlgItem(IDC_MOTION3NOTEN)->SetFont(&font2);
GetDlgItem(IDC_EXIT)->SetFont(&font2);
font3.CreatePointFont(200,"黑体");
GetDlgItem(IDC_MOTIONRESET)->SetFont(&font3);
font4.CreatePointFont(200,"Times New Roman");
GetDlgItem(IDC_MOVEWIDTH)->SetFont(&font4);
//字体颜色设置
brush.CreateSolidBrush(RGB(192,192,192));
// TODO: Add your specialized code here and/or call the base class
}
void CLaserscanView::DoDataExchange(CDataExchange* pDX)
{
CView::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CLaserscanView)
DDX_Control(pDX, IDC_MOTION3NOTEN, m_dd);
DDX_Control(pDX, IDC_MOTION3EN, m_sd);
DDX_Control(pDX, IDC_EXIT, m_tc);
DDX_Text(pDX, IDC_EDIT_WIDTH, m_xmove);
//}}AFX_DATA_MAP
}
void CLaserscanView::OnVScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar)
{
// TODO: Add your message handler code here and/or call default
CView::OnVScroll(nSBCode, nPos, pScrollBar);
}
下面试头文件源代码:
// laserscanView.h : interface of the CLaserscanView class
//
/////////////////////////////////////////////////////////////////////////////
#if !defined(AFX_LASERSCANVIEW_H__DFBBBCE7_B8F4_4673_AC14_91E7F7F22350__INCLUDED_)
#define AFX_LASERSCANVIEW_H__DFBBBCE7_B8F4_4673_AC14_91E7F7F22350__INCLUDED_
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
#include "dmcwin.h"
class CLaserscanView : public CFormView
{
protected: // create from serialization only
CLaserscanView();
DECLARE_DYNCREATE(CLaserscanView)
public:
//{{AFX_DATA(CLaserscanView)
enum { IDD = IDD_LASERSCAN};
CButtonm_dd;
CButtonm_sd;
CButtonm_tc;
CStringm_xmove;
//}}AFX_DATA
// Attributes
public:
CLaserscanDoc* GetDocument();
// Operations
public:
// Overrides
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CLaserscanView)
public:
virtual BOOL PreCreateWindow(CREATESTRUCT& cs);
protected:
virtual void OnInitialUpdate();
virtual BOOL OnPreparePrinting(CPrintInfo* pInfo);
virtual void OnBeginPrinting(CDC* pDC, CPrintInfo* pInfo);
virtual void OnEndPrinting(CDC* pDC, CPrintInfo* pInfo);
virtual void OnPrint(CDC* pDC, CPrintInfo* pInfo);
virtual void DoDataExchange(CDataExchange* pDX);// DDX/DDV support
//}}AFX_VIRTUAL
// Implementation
public:
CFont font1;
CFont font2;
CFont font3;
CFont font4;
CBrush brush;
int m_Vx;
int m_Acx;
virtual ~CLaserscanView();
#ifdef _DEBUG
virtual void AssertValid() const;
virtual void Dump(CDumpContext& dc) const;
#endif
protected:
CDMCWin m_DMCWin;
// Generated message map functions
protected:
//{{AFX_MSG(CLaserscanView)
afx_msg void OnExit();
afx_msg void OnMovewidth();
afx_msg void OnMotionreset();
afx_msg void OnMotion3noten();
afx_msg void OnMotion3en();
afx_msg void OnVScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar);
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};
#ifndef _DEBUG // debug version in laserscanView.cpp
inline CLaserscanDoc* CLaserscanView::GetDocument()
{ return (CLaserscanDoc*)m_pDocument; }
#endif
/////////////////////////////////////////////////////////////////////////////
//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.
#endif // !defined(AFX_LASERSCANVIEW_H__DFBBBCE7_B8F4_4673_AC14_91E7F7F22350__INCLUDED_)
错误指定的地方附近代码为:
void AFXAPI DDX_Control(CDataExchange* pDX, int nIDC, CWnd& rControl)
{
if (rControl.m_hWnd == NULL) // not subclassed yet
{
ASSERT(!pDX->m_bSaveAndValidate);
HWND hWndCtrl = pDX->PrepareCtrl(nIDC);
if (!rControl.SubclassWindow(hWndCtrl))
{
ASSERT(FALSE); // possibly trying to subclass twice?
AfxThrowNotSupportedException();
}
#ifndef _AFX_NO_OCC_SUPPORT
else
{
// If the control has reparented itself (e.g., invisible control),
// make sure that the CWnd gets properly wired to its control site.
if (pDX->m_pDlgWnd->m_hWnd != ::GetParent(rControl.m_hWnd))
rControl.AttachControlSite(pDX->m_pDlgWnd);
}
#endif //!_AFX_NO_OCC_SUPPORT
}
}
急求,哪位大神肯帮忙
2014年08月25日 03点08分 1
1