不能转换void (_thiscall CMainFrame::*)(void)to LRESULT (__thiscall CWnd::* )(WPARAM,LPARAM)2010-05-13 11:35开发平台由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)”
在匹配目标类型的范围内没有具有该名称的函数
解决方法如下:
首先,把原来的消息函数返回值类型改为LRESULT,函数内可以随便写个return TRUE; 然后消息函数的参数必须改写成(WPARAM wParam,LPARAM lParam)而不论这两个参数是否用得到;最后,消息映射如ON_MESSAGE(WM_message,& OnMyMessage)
分享到:
相关推荐
本篇文章是对C++中无法从void转换为LRESULT的解决方法进行了详细的分析介绍,需要的朋友参考下
void CListDemoDlg::OnLvnBegindragListFolder(NMHDR *pNMHDR, LRESULT *pResult) { if(m_listFolder.GetListType()!=TYPE_PICNOTIP && m_listFolder.GetListType() != TYPE_PICTIP) return; static int i = 0...
LRESULT CALLBACK WndProc(HWND hWnd,UINT message, WPARAM wParam,LPARAM lParam); void DrawGame(void); void ShellDraw( HDC hdc ); void GameAreaDraw(HDC hdc); void OnTimer(UINT uTIMER_ID); void ...
LRESULT CThreadCommunicationDlg::OnDisplayResult(WPARAM wParam,LPARAM lParam) { int nResult = (int)wParam; SetDlgItemInt(IDC_STATIC_RESULT,nResult,FALSE); return 0; } void ...
static char THIS_FILE[]=__FILE__; #define new DEBUG_NEW #endif ////////////////////////////////////////////////////////////////////// // Construction/Destruction /////////////////////////////////////...
// 从磁盘上读取图像。 BOOL LoadBitmapsM(LPCTSTR normalImageFile, LPCTSTR downImageFile, LPCTSTR overImageFile=NULL, LPCTSTR disableImageFile=NULL ); void SetNormalImageM( VrImageCL& norImg ); ...
LRESULT CALLBACK WndProc(HWND, UINT , WPARAM , LPARAM ); BOOL Compare();//判定是否碰撞 BOOL TransBlock(int);//转换函数(包含变形,加速,左右移动。 void HandleTable();//得分时处理游戏区域 //定义24种方块
// 上下分割 IDC_SPLITTER_TOP 分割线资源更改资源可见属性为不可见,防止出现2条线 void DoResize1(int delta); CSplitterControl m_wndSplitter2; // 左右分割 IDC_SPLITTER_LEFT void DoResize2(int delta);...
CNewsWindow(void); ~CNewsWindow(void); public: HWND m_hWnd; public: // 设置皮肤(位图资源名称,标题栏文本颜色) BOOL SetSkin(LPCTSTR lpSkinBitmapName,COLORREF CaptionColor=0x000000); // 创建窗口 ...
protected: // 仅从序列化创建 CMainFrame(); DECLARE_DYNCREATE(CMainFrame) // 属性 public: // 操作 public: // 重写 public: virtual BOOL PreCreateWindow(CREATESTRUCT& cs); virtual BOOL LoadFrame...
void PrepareImageRect(BOOL bHasTitle, RECT* rpItem, CRect* rpTitle, BOOL bIsPressed, DWORD dwWidth, DWORD dwHeight, CRect* rpImage); HBITMAP CreateBitmapMask(HBITMAP hSourceBitmap, DWORD dwWidth, ...
void SetGoodbyeMessage(LPCTSTR lpszText); void SetWelcomeMessage(LPCTSTR lpszText); void SetTimeout(int nValue); void SetPort(int nValue); void SetMaxUsers(int nValue); void ...
#include <windows.h> // Header File For ...static PIXELFORMATDESCRIPTOR pfd= // pfd Tells Windows How We Want Things To Be { sizeof(PIXELFORMATDESCRIPTOR), // Size Of This Pixel Format Descriptor ...
CTLCOLOR_STATIC 静态控件 表2 nCtlColor的类型值与含义 作为一个简单的例子,观察以下的代码: BOOL CUi5Dlg::OnInitDialog() { //… //创建字体 //CFont CUi1View::m_Font1, CUi1View::m_Font2 m_Font1....
* This Code Was Created By Jeff Molofee 2000 * A HUGE Thanks To Fredric Echols For Cleaning Up * And Optimizing The Base Code, Making It More Flexible! * If You've Found This Code Useful, ...
static char THIS_FILE[] = __FILE__; #endif IMPLEMENT_DYNAMIC(CSystemTray, CObject) ///////////////////////////////////////////////// // CSystemTray construction/creation/destruction CSystemTray::...
然后要定义消息处理的函数,这里的函数定义也需要注意要定义成类似afx_msg LRESULT OnAddIconToTaskbar(WPARAM wParam, LPARAM lParam),这里如果不写成LRESULT而写成void,编绎可能通不过。而且如果不加WAPARAM和...
//任务栏图标,注意引入的图标的ID值为连续的,且IDI_ICON1的值为图标ID中最小的 m_hIcons[i] = AfxGetApp()->LoadIcon(IDI_ICON1 + i); } //在CMainFrame的OnCreate(LPCREATESTRUCT lpCreateStruct) 函数中...