problem w CWnd and SendMessage - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

problem w CWnd and SendMessage

arvind17arvind17 Posts: 62Member
hi,
I have a Draw_Consumer class deveried fr CWnd. I want to use the sendmessage here. I want to send message to WM_LBUTTONDOWN.

see code:
SendMessage( WM_LBUTTONDOWN, MK_LBUTTON, 50 );

My OnLButtonDown fn is implemented in the view class. This is where the message is targeted to go.

I run my application as above and the following assertion error.

_AFXWIN_INLINE LRESULT CWnd::SendMessage(UINT message, WPARAM wParam, LPARAM lParam)
{ ASSERT(::IsWindow(m_hWnd)); return ::SendMessage(m_hWnd, message, wParam, lParam); }

in one of the C:program files.. files where vc++ has been installed.

I guess that that the sendmessage is complaining that the message is not send it the same window - IsWindow(m_hWnd).

Well, I will need to send the message to the view class as I desc above and I will be needing some help for that.
Thanks.............

regards
-arvind

Comments

  • AldebaranAldebaran Posts: 23Member
    : hi,
    : I have a Draw_Consumer class deveried fr CWnd. I want to use the sendmessage here. I want to send message to WM_LBUTTONDOWN.
    :
    : see code:
    : SendMessage( WM_LBUTTONDOWN, MK_LBUTTON, 50 );
    :
    : My OnLButtonDown fn is implemented in the view class. This is where the message is targeted to go.
    :
    : I run my application as above and the following assertion error.
    :
    : _AFXWIN_INLINE LRESULT CWnd::SendMessage(UINT message, WPARAM wParam, LPARAM lParam)
    : { ASSERT(::IsWindow(m_hWnd)); return ::SendMessage(m_hWnd, message, wParam, lParam); }
    :
    : in one of the C:program files.. files where vc++ has been installed.
    :
    : I guess that that the sendmessage is complaining that the message is not send it the same window - IsWindow(m_hWnd).
    :
    : Well, I will need to send the message to the view class as I desc above and I will be needing some help for that.
    : Thanks.............
    :
    : regards
    : -arvind

    If you want to send a message to target object x, you call it as

    x.SendMessage(....);

    In this case, since the target, ie, the object that should receive the WM_LBUTTONDOWN message is a CView object, you have to call as

    [code].SendMessage(....);[/code]

    In your code, you haven't specified the instance on which the method should be called. When no instance is explicitly specified, the default instance is [b]this[/b], ie the object that made the call. Hence in your case, since the call is made from a Draw_Consumer object, the message is sent to the same Draw_Consumer object, not to the desired CView object. Since you aren't handling the message in your message map, you end up with the assertion.

    Change the method, say Draw_Consumer::func(), which calls SendMessage to take a CWnd* or CWnd& argument, and while calling this method, pass the address or reference of your CView object.



  • arvind17arvind17 Posts: 62Member
    hi,
    I understand what u say but what are the code to get the view object.
    It's the default view object that's created when with the mfc wizard that I am speaking about.

    regards
    -arvind




  • AldebaranAldebaran Posts: 23Member
    : hi,
    : I understand what u say but what are the code to get the view object.
    : It's the default view object that's created when with the mfc wizard that I am speaking about.
    :
    : regards
    : -arvind

    Since you want to send to default view object, do
    [code]
    CWnd* defview = AfxGetApp() -> m_pMainWnd;
    defview -> SendMessage (WM_LBUTTONDOWN, etc.)
    [/code]



Sign In or Register to comment.