??error C2440
?“static_cast” 無法從“void (__thiscall CPppView )(void)”轉換為“LRESULT (__thiscall CWnd )(WPARAM,LPARAM)”
?
?????? 不能轉換void (_thiscall CMainFrame::*)(void)to LRESULT (__thiscall CWnd::* )(WPARAM,LPARAM)開發平臺由VC6.0升級至VS2005,需要將原有的項目遷移。
可能碰到類似錯誤:
???????????????????????????? error C2440: 'static_cast' : cannot convert from 'void (__thiscall CMainFrame::* )
???????????????????????????????????????????????????????????????????????????????(void)' to 'LRESULT (__thiscall CWnd::* )(WPARAM,LPARAM)'??
VS2005對消息的檢查更為嚴格,以前在VC6下完全正常運行的消息映射在VS2005下編譯不通過
??????????? ON_MESSAGE(WM_message,OnMyMessage);
????????????OnMyMessage返回值必須為LRESULT,其形式為:afx_msg LRESULT OnMyMessage(WPARAM, LPARAM);如果不符合,則有錯誤提示:
????????????????error C2440: “static_cast”: 無法從“void (__thiscall CPppView::* )(WPARAM,LPARAM)”轉換為“LRESULT (__thiscall CWnd::* )(WPARAM,LPARAM)”在匹配目標類型的范圍內沒有具有該名稱的函數
?????????????????error C2440: “static_cast”: 無法從“void (__thiscall CPppView::* )? (void)”轉換為“LRESULT (__thiscall CWnd::* )(WPARAM,LPARAM)”在匹配目標類型的范圍內沒有具有該名稱的函數
?
解決方法如下:
例如:TransparentWnd.cpp中ON_MESSAGE(WM_LIBEN,OnLiben):
第一:把原來的消息函數返回值類型改為LRESULT(找到OnLiben定義,如Viod?? CTransparentWnd::OnLiben(WPARAM wParam,LPARAM lParam)改成LRESULT CTransparentWnd::OnLiben(WPARAM wParam,LPARAM lParam),聲明處也要改,如afx_msg LRESULT OnLiben(WPARAM wParam,LPARAM lParam););
第二:函數內可以隨便寫個return TRUE;
第三:然后消息函數的參數必須改寫成(WPARAM wParam,LPARAM lParam)而不論這兩個參數是否用得到;
第四:消息映射如ON_MESSAGE(WM_message,& OnMyMessage