#1
  1. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Jan 2002
    Location
    Seattle WA
    Posts
    863
    Rep Power
    14

    ON_MESSAGE in C++.net


    Has anyone managed to get ON_MESSAGE to work in MSVC++ .net? I've noticed lot's of help requests splattered across the web, but it seems no one knows how to make it work, since none of them get replies. Here's the old-fashioned way of doing it, works in MSVC++ 6.0.

    In MainFrm.h
    Code:
    DECLARE_MESSAGE_MAP()
    LRESULT OnMyMessage(LPARAM lParam, WPARAM wParam);
    In MainFrm.cpp
    Code:
    #define UWM_MYMESSAGE (WM_USER + 1)
    
    BEGIN_MESSAGE_MAP(CMainFrame, CFrameWnd)
        ON_MESSAGE(UWM_MYMESSAGE, OnMyMessage)
    END_MESSAGE_MAP()
    
    LRESULT CMainFrame::OnMyMessage(LPARAM lParam, WPARAM wParam)
    {
        return 0;
    }
    And the error:
    ...\MainFrm.cpp(30): error C2440: 'static_cast' : cannot convert from 'LRESULT (__thiscall CMainFrame::* )(LPARAM,WPARAM)' to 'LRESULT (__thiscall CWnd::* )(WPARAM,LPARAM)'

    Why is this a problem now? Evidently, the framework doesn't like messages being handled outside of the CWnd class? It doesn't make sense, since you usually don't modify the CWnd class. CMainFrame is inherits from CWnd, so I don't see how the cast should be causing a problem. I've looked up the docs on c2440, but frankly, it's beyond me how that applies to MFC, since I'm not really familiar with the bowels of the MFC code.

    How do you get WM_MESSAGE to work in c++.net?
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed God 1st Plane (5500 - 5999 posts)

    Join Date
    Oct 2000
    Location
    Back in the real world.
    Posts
    5,966
    Rep Power
    191
    im no c++ pro, but from my view:
    CMainFrame should be a descendant of CWin, is it? so the declaration should be valid.

    oooops, you switched LPARAM and WPARAM
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Jan 2002
    Location
    Seattle WA
    Posts
    863
    Rep Power
    14
    Wow, aren't I the fool? I knew it was something trivial. Hehehe...weeeeee!

    I guess it's a good thing that the message map macros now catch bad prototypes, they never used to. Handy.

IMN logo majestic logo threadwatch logo seochat tools logo