Solved

How do I setup my class to accept LRESULT WINAPI MsgProc() calls?

Posted on 2004-08-27
14
964 Views
Last Modified: 2012-06-21
I've added DirectShow filters to my app to support playback of an AVI file.  So far I'm pretty close, but now I need to get the message handling setup so that I can handle messages sent back by direct show. (That is, my WINAPI MsgProc function, how to call it?)

So far I have this (I've stripped out irrelevant code and error checking for clarity)

-------------------------------
in my header:

#define WM_GRAPHNOTIFY  WM_USER+13

class CMovieView : public CStatic
{
.. // constructors etc..

public
    LRESULT WINAPI MsgProc( HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam );
.
.


in the .CPP file:

DWORD CMovieView::LoadMovie(LPCTSTR a_lpszMovieName)
{
  // setup all the filter graph stuff.. this is all working.

  // setup IMediaEventEx for callbacks.
  g_pGraph->QueryInterface(IID_IMediaEventEx, (void **)&g_pMediaEvent);
  g_pMediaEvent->SetNotifyWindow((OAHWND)GetSafeHwnd(), WM_GRAPHNOTIFY, 0);

  g_pMediaControl->Run();
}

HRESULT CImageView::HandleGraphEvent(void)
{
   //.. code to handle events.
}


LRESULT WINAPI MsgProc( HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam )
{
    switch( msg )
    {
      case WM_GRAPHNOTIFY:
            CImageView::HandleGraphEvent();
            return 0;
    }

    return DefWindowProc( hWnd, msg, wParam, lParam );
}

-------------------------------

Ok - that said.. I can get to the point where my movie opens and plays.. but when it's done (i.e. the media event sends EC_COMPLETE message) nothing happens, because my MsgProc() is never being called.  What do I have to do to setup my class so that it can accept messages?

thanks!
-Paul
0
Comment
Question by:PMH4514
  • 7
  • 6
14 Comments
 
LVL 86

Accepted Solution

by:
jkr earned 20 total points
Comment Utility
You need to redirect the calls to the respective CMovieView instance. To do that, you need to know which one the call is meant for. To achieve that, I'd store that object's 'this' pointer in the 'GWL_USERDATA slot of the window instance, I.e.

// upon creation of the window
SetWindowLong ( m_hWnd, GWL_USERDATA, (LONG) this);

LRESULT WINAPI MsgProc( HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam )
{
   CMovieView* pView = (CMovieView*) GetWindowLong ( hWnd, GWL_USERDATA);

    //...

0
 

Author Comment

by:PMH4514
Comment Utility
wow. ok I gotta re-read this a couple times :)

so what/who actualy calls MsgProc? Is it valid to say that if I define:
LRESULT WINAPI MsgProc( HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam )

within a class (any class I create) - that it can then accept messages? Who actually pushes the message into my class?
0
 
LVL 5

Assisted Solution

by:millsoft
millsoft earned 30 total points
Comment Utility
Hi PMH4514,

It appears you are using MFC (since you are using CStatic).

Add this to your class's Message Map...

    ON_MESSAGE( EC_COMPLETE, HandleGraphEvent )

and declare the function in your class as:

    afx_msg LRESULT HandleGraphEvent(WPARAM wParam, LPARAM lParam);

That's all you should need.  (I.e. no MsgProc, etc.)




Cheers!
Brad
0
 
LVL 5

Expert Comment

by:millsoft
Comment Utility
PMH4514,
> so what/who actualy calls MsgProc? Is it valid to say that if I define:

It depends upon your application architecture.  If you're using MFC, then messages are dispatched by a special Window procedure inside the guts of the library.  They messages wind their way through the message dispatch maps until they land on the appopropriate member function, which they then call.

If you're not using MFC, then you'd have to answer that question based upon the framework you are using, or have setup.

See these pages for more details:
http://support.microsoft.com/default.aspx?scid=kb;en-us;99848
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vclib/html/_MFCNOTES_TN006.asp

Brad
0
 

Author Comment

by:PMH4514
Comment Utility
I am using MFC
0
 

Author Comment

by:PMH4514
Comment Utility
I swear, I've been coding for the last 10 years and ever day since I started C++ and windows programming (only 4 months now) I feel like a clueless idiot! At least I have all the theory under my belt..  but man, every little step along the way I have to look stuff up and ask for help! I can't believe the depth of this language/platform.

anyway..

I'm gonna play around with both of your approaches.. I think Brad's is probably a bit more appropriate in my case, since I am using MFC and I already have a message map setup.
0
 
LVL 5

Expert Comment

by:millsoft
Comment Utility
PMH4514,
> ever day since I started C++ and windows programming (only 4 months now) ...

Yeah, the water get's very deep once you step into the Windows API end of the pool!  I've been doing Windows API programming since Windows 3.1 (remember 16 bits?) and I'm *STILL* learning things.  It's absolutely huge.  A lot of programmers drown trying to make the jump, so you're ahead of the game because you realize it's hard and are not afraid to ask for help and learn.  :)

Cheers,
Brad

0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 

Author Comment

by:PMH4514
Comment Utility
brad - in your code, I think actually for my case it should be:

   ON_MESSAGE( WM_GRAPHNOTIFY, HandleGraphEvent )

because that is the defined message I told the IMediaEventEx to notify the window with:
 g_pMediaEvent->SetNotifyWindow((OAHWND)GetSafeHwnd(), WM_GRAPHNOTIFY, 0);

right?

>>Yeah, the water get's very deep once you step into the Windows API end of the pool!  I've been doing Windows API programming since Windows 3.1
>>(remember 16 bits?) and I'm *STILL* learning things.  It's absolutely huge.  A lot of programmers drown trying to make the jump, so you're ahead of the >>game because you realize it's hard and are not afraid to ask for help and learn.  :)

yeah, it amazes me, jkr has very quickly jumped in and answered so many of my EE questions, it's astonishing.. if I had any time I'd be doing the same thing over in the ASP/VB/databases/java/.NET/ecommerce forums.. that's where my expertise has lied for the last few years at least..

-Paul
0
 
LVL 5

Expert Comment

by:millsoft
Comment Utility
PMH4514,
> ON_MESSAGE( WM_GRAPHNOTIFY, HandleGraphEvent )
You're correct.  My mistake. :)

BTW, jkr's reply would be appropriate for a normal (non-MFC) application since you'd have setup the Window Procedure in the first place.  

The learning curve isn't made any easier by the mix of C++ (which is incredibly complex by itself) with MFC on top (and the win32 API under that).  It's like learning 3 things at once.

Brad
0
 

Author Comment

by:PMH4514
Comment Utility
>>It's like learning 3 things at once.
tell me about i!

well - adding ON_MESSAGE( WM_GRAPHNOTIFY, HandleGraphEvent ) to my message map worked perfectly.  Thanks! I think JKR deserves an assited credit on this one though, becuase I never specified in my post that I was using MFC.
0
 
LVL 5

Expert Comment

by:millsoft
Comment Utility
PMH4514,
> becuase I never specified in my post that I was using MFC.
FYI: There is an MFC-specific forum.

Brad
0
 

Author Comment

by:PMH4514
Comment Utility
ahh yes.. shows you how much fully don't understand where the line is drawn between C++ and MFC.. Until you pointed it out I didn't realize it was an MFC question!
0
 
LVL 5

Expert Comment

by:millsoft
Comment Utility
PMH4514,
> where the line is drawn between C++ and MFC..

Good rule of thumb: If you have an MFC application, and the question relates to Windows O/S Programming (i.e. Windows, Messages, Dialogs, Resources, Graphics, etc.) it's probably going to be an MFC question.

If it's a question about C++ class inheritance, getting C++ to compile/link, templates, or the C++ standard library functions, then it would go here.

Of course, I'm sure everyone's happy to help wherever you post the question.

Cheers,
Brad
0
 

Author Comment

by:PMH4514
Comment Utility
:-)
0

Featured Post

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Errors will happen. It is a fact of life for the programmer. How and when errors are detected have a great impact on quality and cost of a product. It is better to detect errors at compile time, when possible and practical. Errors that make their wa…
Many modern programming languages support the concept of a property -- a class member that combines characteristics of both a data member and a method.  These are sometimes called "smart fields" because you can add logic that is applied automaticall…
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now