为什么我在编译mfc应用程序时得到这个错误
why am I getting this error when compiling an mfc application?
我有这样的代码:
void CALLBACK CTestTimeUpDlg::MyTimerProc(
HWND hWnd, // handle of CWnd that called SetTimer
UINT nMsg, // WM_TIMER
UINT_PTR nIDEvent, // timer identification
DWORD dwTime // system time
)
{
const int m_TimerValue=0;
double timeValueSec=m_TimerValue/1000.0;
CString valueString;
valueString.Format(L"%3.3f",timeValueSec);
m_TimerDisplayValue.SetWindowTextW(valueString);
}
void CTestTimeUpDlg::OnBnClickedButtonStart()
{
m_TimerValue=0;
m_Timer = SetTimer(1, 1, &CTestTimeUpDlg::MyTimerProc);
}
但是当我编译它时,我得到这个错误:
'CWnd::SetTimer' : cannot convert parameter 3 from 'void (__stdcall CTestTimeUpDlg::* )(HWND,UINT,UINT_PTR,DWORD)' to 'void (__stdcall *)(HWND,UINT,UINT_PTR,DWORD)'
代码类似于Microsoft文档中的代码:
http://msdn.microsoft.com/en-us/library/49313fdf.aspx您应该使CTestTimeUpDlg::MyTimerProc
为静态。然而,通过这样做,您不能访问实例成员,如m_TimerDisplayValue
。
在这种情况下你不应该使用callback。设置lpfnTimer
为NULL,作为链路样本中的第一个定时器。这样,计时器发布消息WM_TIMER
,您可以通过非静态成员函数处理它。
添加:
看来这份文件(加上我上面的话)缺少解释。
执行以下操作实现WM_TIMER
的处理程序。
在类声明中声明处理程序:
afx_msg void OnTimer(UINT_PTR nIDEvent);
在您的cpp文件中,添加消息映射:
BEGIN_MESSAGE_MAP(CTestTimeUpDlg, ...)
ON_WM_TIMER()
END_MESSAGE_MAP()
和实现:
void CTestTimeUpDlg::OnTimer(UINT_PTR nIDEvent)
{
// your code here...
}
相关文章:
- 示例外壳应用程序显示的 V8 "segmentation fault (core dumped)"错误
- C++应用程序 MySQL odbc 数据库连接错误:在引发"otl_tmpl_exception<>"实例后终止调用
- Visual Studio中的wxwidgets应用程序给出错误"LNK2019 unresolved external symbol"
- 调用 java 的回调() 时应用程序崩溃.由于 detatchThread 而获得运行时错误
- 设置我的应用程序 API 感知并防止系统使其模糊和错误定位
- 错误: 无效使用非静态数据成员"应用程序::应用程序构造函数"
- QT C++防止关闭应用程序时出现运行时错误
- JNI 在应用程序中检测到错误:在为 innerclass 调用 NewObject 时使用了无效的 jobject
- 如何使用CLion和MSVC编译器工具链编译wxWidgets Hello World应用程序而没有错误?
- 运行 libpng 应用程序时出现运行时错误
- .exe应用程序在windows10中创建新模块时抛出错误,但在windows7中工作正常
- 由于选项卡顺序的原因,鼠标光标总是得到错误的hwnd-MFC应用程序
- C++ 错误的分配应用程序失败
- Android (ART) 崩溃并显示错误 JNI 在应用程序中检测到错误:jstring 是无效的本地引用
- 使用提升过程编译简单的应用程序会生成错误
- Qt 应用程序中与Qt版本相关的运行时错误
- Windows 8上的.exe文件中的MSVCR90.dll错误 - 应用程序无法正确启动(0xc000007b)
- VS2012错误:应用程序无法正确启动(0xc000007b)
- Visual Studio 2012 错误:应用程序无法正确启动 (0xc0000007b)
- QObject::connect()错误.应用程序崩溃.无构建错误