Solved

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

Posted on 2004-08-27
14
970 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
ID: 11914287
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
ID: 11914349
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
ID: 11914350
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
Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

 
LVL 5

Expert Comment

by:millsoft
ID: 11914408
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
ID: 11914462
I am using MFC
0
 

Author Comment

by:PMH4514
ID: 11914572
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
ID: 11914619
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
 

Author Comment

by:PMH4514
ID: 11914694
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
ID: 11914776
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
ID: 11914839
>>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
ID: 11914850
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
ID: 11915123
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
ID: 11915255
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
ID: 11915623
:-)
0

Featured Post

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

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…
Introduction This article is a continuation of the C/C++ Visual Studio Express debugger series. Part 1 provided a quick start guide in using the debugger. Part 2 focused on additional topics in breakpoints. As your assignments become a little more …
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.

815 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

13 Experts available now in Live!

Get 1:1 Help Now