PMH4514
asked on
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(LPCT STR a_lpszMovieName)
{
// setup all the filter graph stuff.. this is all working.
// setup IMediaEventEx for callbacks.
g_pGraph->QueryInterface(I ID_IMediaE ventEx, (void **)&g_pMediaEvent);
g_pMediaEvent->SetNotifyWi ndow((OAHW ND)GetSafe Hwnd(), WM_GRAPHNOTIFY, 0);
g_pMediaControl->Run();
}
HRESULT CImageView::HandleGraphEve nt(void)
{
//.. code to handle events.
}
LRESULT WINAPI MsgProc( HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam )
{
switch( msg )
{
case WM_GRAPHNOTIFY:
CImageView::HandleGraphEve nt();
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
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(LPCT
{
// setup all the filter graph stuff.. this is all working.
// setup IMediaEventEx for callbacks.
g_pGraph->QueryInterface(I
g_pMediaEvent->SetNotifyWi
g_pMediaControl->Run();
}
HRESULT CImageView::HandleGraphEve
{
//.. code to handle events.
}
LRESULT WINAPI MsgProc( HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam )
{
switch( msg )
{
case WM_GRAPHNOTIFY:
CImageView::HandleGraphEve
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
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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
> 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
ASKER
I am using MFC
ASKER
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.
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.
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
> 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
ASKER
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->SetNotifyWi ndow((OAHW ND)GetSafe Hwnd(), 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
ON_MESSAGE( WM_GRAPHNOTIFY, HandleGraphEvent )
because that is the defined message I told the IMediaEventEx to notify the window with:
g_pMediaEvent->SetNotifyWi
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
-Paul
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
> 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
ASKER
>>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.
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.
PMH4514,
> becuase I never specified in my post that I was using MFC.
FYI: There is an MFC-specific forum.
Brad
> becuase I never specified in my post that I was using MFC.
FYI: There is an MFC-specific forum.
Brad
ASKER
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!
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
> 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
ASKER
:-)
ASKER
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?