要求是用::OnTimer不停的产生随机数然后发送消息给页面
mainfrm.app中有语句void CMainFrame::OnTimer(UINT nIDEvent)
{
for (int i=0;i<1000;i++)
{
Demo_Data.DI_DO[i]=rand()%2;
}
for (i=0;i<1000;i++)
{
Demo_Data.AI_AO[i]=rand()+10.0;
}
::SendMessage(vHwnd,WM_DEMO_DATA,0,0);
CFrameWnd::OnTimer(nIDEvent);
}运行的时候发现没有声明以下是mainfrm.h文件应该在哪里声明 怎么声明呢?
class CMainFrame : public CFrameWnd
{
protected: // create from serialization only
CMainFrame();
DECLARE_DYNCREATE(CMainFrame)
public:
HWND vHwnd;
// Attributes
public:// Operations
public: virtual BOOL PreCreateWindow(CREATESTRUCT& cs);
public:
virtual ~CMainFrame();
#ifdef _DEBUG
virtual void AssertValid() const;
virtual void Dump(CDumpContext& dc) const;
#endifprotected:
CStatusBar m_wndStatusBar;
CToolBar m_wndToolBar;
protected:
afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct);
DECLARE_MESSAGE_MAP()
};
mainfrm.app中有语句void CMainFrame::OnTimer(UINT nIDEvent)
{
for (int i=0;i<1000;i++)
{
Demo_Data.DI_DO[i]=rand()%2;
}
for (i=0;i<1000;i++)
{
Demo_Data.AI_AO[i]=rand()+10.0;
}
::SendMessage(vHwnd,WM_DEMO_DATA,0,0);
CFrameWnd::OnTimer(nIDEvent);
}运行的时候发现没有声明以下是mainfrm.h文件应该在哪里声明 怎么声明呢?
class CMainFrame : public CFrameWnd
{
protected: // create from serialization only
CMainFrame();
DECLARE_DYNCREATE(CMainFrame)
public:
HWND vHwnd;
// Attributes
public:// Operations
public: virtual BOOL PreCreateWindow(CREATESTRUCT& cs);
public:
virtual ~CMainFrame();
#ifdef _DEBUG
virtual void AssertValid() const;
virtual void Dump(CDumpContext& dc) const;
#endifprotected:
CStatusBar m_wndStatusBar;
CToolBar m_wndToolBar;
protected:
afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct);
DECLARE_MESSAGE_MAP()
};
在afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct);后增加
afx_msg void OnTimer(UINT nIDEvent);mainfrm.app中:
BEGIN_MESSAGE_MAP(CUserSysDlg, CDialog)
ON_WM_TIMER()
END_MESSAGE_MAP()试试是否可行!
ON_WM_TIMER()
END_MESSAGE_MAP()里面已经有了IMPLEMENT_DYNCREATE(CMainFrame, CFrameWnd)
BEGIN_MESSAGE_MAP(CMainFrame, CFrameWnd)
ON_WM_CREATE()
END_MESSAGE_MAP()要替换吗?
顺序:ctrl+w 启动MFC ClassWizard ,类选择CMainFrame,ObjectIDS 选择CMainFrame,message选择WM_TIMER,单击add function,edit code .OK