Solved

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

Posted on 2004-08-27
14
977 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

This article will show you some of the more useful Standard Template Library (STL) algorithms through the use of working examples.  You will learn about how these algorithms fit into the STL architecture, how they work with STL containers, and why t…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
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.

738 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