3

我有一个小型 SDI 应用程序,我正在尝试添加对菜单使用情况的跟踪,即。用户选择某些菜单项的次数。

一些菜单项由 View 组件 (DemoView.cpp) 处理,而其他菜单项由主应用程序 (DemoApp.cpp) 处理。Since the tracking structure is defined in the main app, I believe that I have to notify the View's parent with a special message when a menu item (handled by the View) is selected.

如果这是正确的,我的问题是我无法创建正确的 ON_MESSAGE 命令。它看起来像这样:

 ON_MESSAGE(WM_INCREASE_FREQ, &CDemoApp::OnIncreaseFreq)

其中 OnIncreaseFreq() 定义如下:

LRESULT CDemoApp::OnIncreaseFreq(WPARAM, LPARAM)

但是我收到此错误:

error C2440: 'static_cast' : cannot convert from 
'LRESULT (__thiscall CDemoApp::* )(WPARAM,LPARAM)' to 
'LRESULT (__thiscall CWnd::* )(WPARAM,LPARAM)'

我将不胜感激

4

2 回答 2

3

根据错误,回调函数必须是从CWnd派生的类的成员函数。使 CDemoApp 从 CWnd 派生,您的代码应该可以编译和工作。

于 2010-11-16T11:01:45.293 回答
0

如果您确定转换,则需要使用另一个演员表。它被称为可怕的 reinterpret_cast<>。

于 2010-11-16T10:59:34.280 回答