新手请教函数问题!!

neuly 2004-01-13 02:45:55
在*.h中添加:
afx_msg void OnNumberKey(UINT nID);
afx_msg void OnOperationKey(UINT nID);

在*.cpp中添加:
ON_COMMAND_RANGE(IDC_NUMBER1,IDC_NUMBER10,OnNumberKey);
ON_COMMAND_RANGE(IDC_NUMBER11,IDC_NUMBER20,OnOperationKey);

其他没做任何改动,系统总是报错为:
--------------------Configuration: Calculator - Win32 Debug--------------------
Compiling...
CalculatorDlg.cpp
F:\VcStudy\vc0109\Calculator\CalculatorDlg.cpp(14) : error C2447: missing function header (old-style formal list?)
F:\VcStudy\vc0109\Calculator\CalculatorDlg.cpp(14) : error C2143: syntax error : missing ';' before ','
F:\VcStudy\vc0109\Calculator\CalculatorDlg.cpp(15) : error C2447: missing function header (old-style formal list?)
F:\VcStudy\vc0109\Calculator\CalculatorDlg.cpp(15) : error C2143: syntax error : missing ';' before ','
Error executing cl.exe.

Calculator.exe - 4 error(s), 0 warning(s)


请问是怎么回事,该如何解决,谢谢谢谢!!~~~
...全文
112 11 打赏 收藏 转发到动态 举报
写回复
用AI写文章
11 条回复
切换为时间正序
请发表友善的回复…
发表回复
neuly98 2004-01-13
  • 打赏
  • 举报
回复
搞定了 谢谢各位!!!
yaolan1999 2004-01-13
  • 打赏
  • 举报
回复
这是源代码,你对照一下。

class CCaculatorDlg : public CDialog
{
// Construction
public:
int CacuType;
int NoState;
float No2;
float No1;
CCaculatorDlg(CWnd* pParent = NULL); // standard constructor

// Dialog Data
//{{AFX_DATA(CCaculatorDlg)
enum { IDD = IDD_CACULATOR_DIALOG };
float m_fEdit;
//}}AFX_DATA

// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CCaculatorDlg)
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
//}}AFX_VIRTUAL

// Implementation
protected:
HICON m_hIcon;

// Generated message map functions
//{{AFX_MSG(CCaculatorDlg)
virtual BOOL OnInitDialog();
afx_msg void OnSysCommand(UINT nID, LPARAM lParam);
afx_msg void OnPaint();
afx_msg HCURSOR OnQueryDragIcon();
afx_msg void OnNumberKey(UINT nID);
afx_msg void OnOperateKey(UINT nID);
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};

#include "stdafx.h"
#include "Caculator.h"
#include "CaculatorDlg.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()

/////////////////////////////////////////////////////////////////////////////
// CCaculatorDlg dialog

CCaculatorDlg::CCaculatorDlg(CWnd* pParent /*=NULL*/)
: CDialog(CCaculatorDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CCaculatorDlg)
m_fEdit = 0.0f;
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
NoState=1;
m_fEdit=0;
No1=0;
No2=0;
CacuType=0;

}

void CCaculatorDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CCaculatorDlg)
DDX_Text(pDX, IDC_EDIT1, m_fEdit);
//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CCaculatorDlg, CDialog)
//{{AFX_MSG_MAP(CCaculatorDlg)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_COMMAND_RANGE(IDC_NUMBER1,IDC_NUMBER10,OnNumberKey)
ON_COMMAND_RANGE(IDC_NUMBER11,IDC_NUMBER20,OnOperateKey)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CCaculatorDlg message handlers

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

return TRUE; // return TRUE unless you set the focus to a control
}

void CCaculatorDlg::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 CCaculatorDlg::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 CCaculatorDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
void CCaculatorDlg::OnNumberKey(UINT nID)
{
int n=0;
switch(nID)
{
case IDC_NUMBER1:n=1;break;
case IDC_NUMBER2:n=2;break;
case IDC_NUMBER3:n=3;break;
case IDC_NUMBER4:n=4;break;
case IDC_NUMBER5:n=5;break;
case IDC_NUMBER6:n=6;break;
case IDC_NUMBER7:n=7;break;
case IDC_NUMBER8:n=8;break;
case IDC_NUMBER9:n=9;break;
case IDC_NUMBER10:n=0;
}
switch(NoState)
{
case 1:m_fEdit=m_fEdit*10+n;
No1=m_fEdit;
UpdateData(FALSE);
break;
case 2:m_fEdit=m_fEdit*10+n;
No2=m_fEdit;
UpdateData(FALSE);
}

}
void CCaculatorDlg::OnOperateKey(UINT nID)
{
switch(nID)
{
case IDC_NUMBER11:m_fEdit=-m_fEdit;
UpdateData(FALSE);
if(1==NoState)
No1=m_fEdit;
else
No2=m_fEdit;
break;
case IDC_NUMBER12:m_fEdit=(int)m_fEdit/10;
UpdateData(FALSE);
if(1==NoState)
No1=m_fEdit;
else
No2=m_fEdit;
break;
case IDC_NUMBER13:m_fEdit=0;
No2=0;
NoState=2;
CacuType=4;
break;
case IDC_NUMBER14:NoState=2;
m_fEdit=0;
No2=0;
CacuType=3;
break;
case IDC_NUMBER15:NoState=2;
No2=0;
m_fEdit=0;
CacuType=1;
break;
case IDC_NUMBER16:NoState=2;
No2=0;
m_fEdit=0;
CacuType=2;
break;
case IDC_NUMBER17:m_fEdit=0;
NoState=1;
No1=No2=CacuType=0;
UpdateData(FALSE);
break;
case IDC_NUMBER18:if(1==NoState)
{
m_fEdit=m_fEdit*m_fEdit;
No1=m_fEdit;
UpdateData(FALSE);
}
if(2==NoState)
{
m_fEdit=m_fEdit*m_fEdit;
No2=m_fEdit;
UpdateData(FALSE);
}
break;
case IDC_NUMBER19:if(1==NoState)
{
m_fEdit=1/m_fEdit;
No1=m_fEdit;
UpdateData(FALSE);
}
if(2==NoState)
{
m_fEdit=1/m_fEdit;
No2=m_fEdit;
UpdateData(FALSE);
}
break;
case IDC_NUMBER20:if(1==CacuType)
{
m_fEdit=No1+No2;
No2=0;
No1=m_fEdit;
UpdateData(FALSE);
}
else if(2==CacuType)
{
m_fEdit=No1-No2;
No2=0;
No1=m_fEdit;
UpdateData(FALSE);
}
else if(3==CacuType)
{
m_fEdit=No1*No2;
No2=0;
No1=m_fEdit;
UpdateData(FALSE);
}
else if(4==CacuType)
{
m_fEdit=No1/No2;
No2=0;
No1=m_fEdit;
UpdateData(FALSE);
}
NoState=1;

}
}
neuly 2004-01-13
  • 打赏
  • 举报
回复
分号去掉了,而且也把它放在BEGING_MESSAGE_MAP和END_MESSAGE_MAP之间了,还是有错啊!!

--------------------Configuration: Calculator - Win32 Debug--------------------
Compiling...
CalculatorDlg.cpp
F:\VcStudy\vc0109\Calculator\CalculatorDlg.cpp(57) : error C2440: 'type cast' : cannot convert from 'void (__cdecl *)(unsigned int)' to 'void (__thiscall CCmdTarget::*)(unsigned int)'
There is no context in which this conversion is possible
F:\VcStudy\vc0109\Calculator\CalculatorDlg.cpp(58) : error C2440: 'type cast' : cannot convert from 'void (__cdecl *)(unsigned int)' to 'void (__thiscall CCmdTarget::*)(unsigned int)'
There is no context in which this conversion is possible
F:\VcStudy\vc0109\Calculator\CalculatorDlg.cpp(180) : error C2039: 'OnNumberKey' : is not a member of 'CCalculatorDlg'
f:\vcstudy\vc0109\calculator\calculatordlg.h(17) : see declaration of 'CCalculatorDlg'
F:\VcStudy\vc0109\Calculator\CalculatorDlg.cpp(198) : error C2065: 'NumberState' : undeclared identifier
F:\VcStudy\vc0109\Calculator\CalculatorDlg.cpp(200) : error C2065: 'm_number' : undeclared identifier
F:\VcStudy\vc0109\Calculator\CalculatorDlg.cpp(201) : error C2065: 'number1' : undeclared identifier
F:\VcStudy\vc0109\Calculator\CalculatorDlg.cpp(202) : error C2065: 'UpdateData' : undeclared identifier
F:\VcStudy\vc0109\Calculator\CalculatorDlg.cpp(208) : error C2065: 'number2' : undeclared identifier
F:\VcStudy\vc0109\Calculator\CalculatorDlg.cpp(213) : error C2039: 'OnOperationKey' : is not a member of 'CCalculatorDlg'
f:\vcstudy\vc0109\calculator\calculatordlg.h(17) : see declaration of 'CCalculatorDlg'
F:\VcStudy\vc0109\Calculator\CalculatorDlg.cpp(239) : error C2065: 'OperationState' : undeclared identifier
F:\VcStudy\vc0109\Calculator\CalculatorDlg.cpp(268) : error C2065: 'sqrt' : undeclared identifier
F:\VcStudy\vc0109\Calculator\CalculatorDlg.cpp(272) : warning C4244: '=' : conversion from 'double' to 'int', possible loss of data
F:\VcStudy\vc0109\Calculator\CalculatorDlg.cpp(276) : error C2065: 'cal' : undeclared identifier
Error executing cl.exe.

Calculator.exe - 12 error(s), 1 warning(s)
lygfqy 2004-01-13
  • 打赏
  • 举报
回复
宏定义一定要去掉分号
0sch 2004-01-13
  • 打赏
  • 举报
回复
对,分号也要去掉
freeshoot 2004-01-13
  • 打赏
  • 举报
回复
哈哈,楼上的都没注意:
ON_COMMAND_RANGE(IDC_NUMBER1,IDC_NUMBER10,OnNumberKey);

后面不要加分号!!!
0sch 2004-01-13
  • 打赏
  • 举报
回复
*.cpp中添加的消息响应声明要放在BEGING_MESSAGE_MAP和END_MESSAGE_MAP之间
neuly 2004-01-13
  • 打赏
  • 举报
回复
还有两个问题:
1: 我在CCalculatorDlg .h中的添加变量和函数在OnNumberKey函数和OnOperationKey函数中怎么都不认识的,报错为未定义;
class CCalculatorDlg : public CDialog
{
int NumberState;
void cal();
}


void CCalculatorDlg::OnNumberKey(UINT nID)
{
NumberState = 1;
}

2, 刚才的报错依然存在

请高手指教!!!
neuly 2004-01-13
  • 打赏
  • 举报
回复
哦 那个还没写 我试试看 :)
meil 2004-01-13
  • 打赏
  • 举报
回复
同意楼上说的,应该编写实现部分,空的也行.
0sch 2004-01-13
  • 打赏
  • 举报
回复
这两部分实现函数(消息响应函数)的定义,还有函数的实现部分呢?编译器没有找到,所以出错。

16,471

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC相关问题讨论
社区管理员
  • 基础类社区
  • Web++
  • encoderlee
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

        VC/MFC社区版块或许是CSDN最“古老”的版块了,记忆之中,与CSDN的年龄几乎差不多。随着时间的推移,MFC技术渐渐的偏离了开发主流,若干年之后的今天,当我们面对着微软的这个经典之笔,内心充满着敬意,那些曾经的记忆,可以说代表着二十年前曾经的辉煌……
        向经典致敬,或许是老一代程序员内心里面难以释怀的感受。互联网大行其道的今天,我们期待着MFC技术能够恢复其曾经的辉煌,或许这个期待会永远成为一种“梦想”,或许一切皆有可能……
        我们希望这个版块可以很好的适配Web时代,期待更好的互联网技术能够使得MFC技术框架得以重现活力,……

试试用AI创作助手写篇文章吧