《VC++深入详解》 9.6.2错误 解决办法 分类: MFC 2014-11-06 08:46 47人阅读 评论(0) 收藏
在《VC++深入详解中》 在状态栏的窗格中创建进度栏中,添加自定义的消息响应函数
书中
在MainFream.h中添加
afx_msg void OnProgress();在MaiinFream.cpp中添加
ON_MESSAGE(UM_PROGRESS,OnProgress)并添加消息响应函数
void CMainFrame::OnProgress() { CRect rect; m_wndStatusBar.GetItemRect(2,&rect); m_progress.Create(WS_CHILD | WS_VISIBLE | PBS_SMOOTH, rect,&m_wndStatusBar,123); m_progress.SetPos(50); }
这在VC++6.0中是可行的,但是在VS2010中会出现编译错误
error C2440: “static_cast”: 无法从“void (__thiscall CPppView::* )(WPARAM,LPARAM)”转换为“LRESULT (__thiscall CWnd::* )(WPARAM,LPARAM)”
解决方法如下:
在函数原型定义以及函数相应的返回值由void改为LRESULT,随便弄一个返回值 return TRUE; 并加上参数
WPARAM wParam, LPARAM lParam
代码如下
头文件声明:
afx_msg LRESULT OnProgress(WPARAM wParam, LPARAM lParam);
源文件:
ON_MESSAGE(UM_PROGRESS, &CMainFrame::OnProgress)
LRESULT CMainFrame::OnProgress(WPARAM wParam, LPARAM lParam) { int index2 = 0; index2 = m_wndStatusBar.CommandToIndex(IDS_PROGRESS); CRect rect; m_wndStatusBar.GetItemRect(index2, &rect); if (NULL == m_progress.m_hWnd) m_progress.Create(WS_CHILD | WS_VISIBLE, rect, &m_wndStatusBar, 123); else m_progress.MoveWindow(rect); m_progress.SetPos(50); return 1; }
版权声明:本文为博主原创文章,未经博主允许不得转载。