[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 999
  • Last Modified:

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

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
PMH4514
Asked:
PMH4514
  • 7
  • 6
2 Solutions
 
jkrCommented:
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
 
PMH4514Author Commented:
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
 
millsoftCommented:
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
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
millsoftCommented:
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
 
PMH4514Author Commented:
I am using MFC
0
 
PMH4514Author Commented:
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
 
millsoftCommented:
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
 
PMH4514Author Commented:
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
 
millsoftCommented:
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
 
PMH4514Author Commented:
>>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
 
millsoftCommented:
PMH4514,
> becuase I never specified in my post that I was using MFC.
FYI: There is an MFC-specific forum.

Brad
0
 
PMH4514Author Commented:
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
 
millsoftCommented:
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
 
PMH4514Author Commented:
:-)
0

Featured Post

The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

  • 7
  • 6
Tackle projects and never again get stuck behind a technical roadblock.
Join Now