`
beckshanling
  • 浏览: 255638 次
  • 性别: Icon_minigender_1
  • 来自: 宁波
社区版块
存档分类
最新评论

error C2440 “static_cast” 无法从“void (__thiscall CPppView )(void)”转换为“LRESULT (__t

    博客分类:
  • C++
阅读更多

不能转换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的方法详解

    本篇文章是对C++中无法从void转换为LRESULT的解决方法进行了详细的分析介绍,需要的朋友参考下

    CListCtrl功能的全部应用

    void CListDemoDlg::OnLvnBegindragListFolder(NMHDR *pNMHDR, LRESULT *pResult) { if(m_listFolder.GetListType()!=TYPE_PICNOTIP && m_listFolder.GetListType() != TYPE_PICTIP) return; static int i = 0...

    贪吃蛇 c语言代码 实现。

    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 ...

    VC 6.0 使用消息实现线程通信.rar

     LRESULT CThreadCommunicationDlg::OnDisplayResult(WPARAM wParam,LPARAM lParam)  {   int nResult = (int)wParam;   SetDlgItemInt(IDC_STATIC_RESULT,nResult,FALSE);   return 0;  }  void ...

    MFC制作的MP3

    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 ); ...

    C环境下简易俄罗斯方块

    LRESULT CALLBACK WndProc(HWND, UINT , WPARAM , LPARAM ); BOOL Compare();//判定是否碰撞 BOOL TransBlock(int);//转换函数(包含变形,加速,左右移动。 void HandleTable();//得分时处理游戏区域 //定义24种方块

    CSplitterControl_对话框分割拖拉窗口控件封装类及使用例子.7z

    // 上下分割 IDC_SPLITTER_TOP 分割线资源更改资源可见属性为不可见,防止出现2条线 void DoResize1(int delta); CSplitterControl m_wndSplitter2; // 左右分割 IDC_SPLITTER_LEFT void DoResize2(int delta);...

    网络右下角弹出新闻窗口_VC源码.rar

    CNewsWindow(void); ~CNewsWindow(void); public: HWND m_hWnd; public: // 设置皮肤(位图资源名称,标题栏文本颜色) BOOL SetSkin(LPCTSTR lpSkinBitmapName,COLORREF CaptionColor=0x000000); // 创建窗口 ...

    ShapeReader

    protected: // 仅从序列化创建 CMainFrame(); DECLARE_DYNCREATE(CMainFrame) // 属性 public: // 操作 public: // 重写 public: virtual BOOL PreCreateWindow(CREATESTRUCT& cs); virtual BOOL LoadFrame...

    XPButton控件

    void PrepareImageRect(BOOL bHasTitle, RECT* rpItem, CRect* rpTitle, BOOL bIsPressed, DWORD dwWidth, DWORD dwHeight, CRect* rpImage); HBITMAP CreateBitmapMask(HBITMAP hSourceBitmap, DWORD dwWidth, ...

    ftp server 源代码

    void SetGoodbyeMessage(LPCTSTR lpszText); void SetWelcomeMessage(LPCTSTR lpszText); void SetTimeout(int nValue); void SetPort(int nValue); void SetMaxUsers(int nValue); void ...

    opengl画图程序附带源代码

    #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 ...

    VC之美化界面篇本文专题讨论VC中的界面美化,适用于具有中等VC水平的读者。读者最好具有以下VC基础:

    CTLCOLOR_STATIC 静态控件 表2 nCtlColor的类型值与含义 作为一个简单的例子,观察以下的代码: BOOL CUi5Dlg::OnInitDialog() { //… //创建字体 //CFont CUi1View::m_Font1, CUi1View::m_Font2 m_Font1....

    gertt点阵图读取器(opengl)

    * 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, ...

    VC托盘程序

    static char THIS_FILE[] = __FILE__; #endif IMPLEMENT_DYNAMIC(CSystemTray, CObject) ///////////////////////////////////////////////// // CSystemTray construction/creation/destruction CSystemTray::...

    explorer重启后图标消失处理

    然后要定义消息处理的函数,这里的函数定义也需要注意要定义成类似afx_msg LRESULT OnAddIconToTaskbar(WPARAM wParam, LPARAM lParam),这里如果不写成LRESULT而写成void,编绎可能通不过。而且如果不加WAPARAM和...

    应用trayicon类实现通知区的操作

    //任务栏图标,注意引入的图标的ID值为连续的,且IDI_ICON1的值为图标ID中最小的 m_hIcons[i] = AfxGetApp()->LoadIcon(IDI_ICON1 + i); } //在CMainFrame的OnCreate(LPCREATESTRUCT lpCreateStruct) 函数中...

Global site tag (gtag.js) - Google Analytics