自己曾经也遇到过这样的问题,在中文网站发帖无果后,在一个英文的网站上找到了答案,内容很简单,不用我翻译了吧,看看就会明白。A1对这个问题做了一些思路的上的分析和引导;A2给出了最终解决方法(其实很简单,是我太孤陋寡闻了)。
Q:I am new to the DirectShow and need to change a transform filter. I need to capture and fire within the
CTransformFilter class the Click event when a user clicks on the image that the transform filter creates.
This is weird but only have the transform filter code.
Does anyone have a clue on how to do this???
Any advise will be much appreciated.
A1:
Source -> Transform ->Renderer
Your "normal" transform filter has no link to the displayed image other than transforming the received data as far as I know.
If catching the mouse click is indeed possible, I'm guessing you'd have to get the event in the renderer filter and then get the event back to your original transform filter using DirectShow notifications.
I've been googling around for a while but I haven't found anything useful as yet:
If it's not possible from an exisiting DS renderer, maybe the Windows Media Player supports this functionaly (though I haven't found anything there either yet), or you might have to dig deeper into the Windows API and write your own renderer?
In any case, let me know if you find anything and I'll do the same...
Does anyone else have any suggestions on how to capture the click event on the renderer window?
A2:
IVideoWindow:: put_MessageDrain
The put_MessageDrain method specifies a window to receive mouse and keyboard messages from the video window.
Remarks
This method enables an application to respond to mouse and keyboard events generated within the video window.
If Drain is non-NULL, the video renderer forwards certain messages to the specified window, using the PostMessage function. Which messages are forwarded might depend on the video renderer in use. The Video Renderer and Video Mixing Renderer (VMR) filters forward the following messages:
....
- WM_LBUTTONDBLCLK
- WM_LBUTTONDOWN
- WM_LBUTTONUP
.....
The message drain window does not need to be a parent of the video window, so full-screen applications can use this method. Note you don't get the simple click, you will have to handle yourself the ButtonDown and ButtonUp messages.
So you just need a window to handle the messages, and then, from this window, you notify the filter through a custom interface.
Alternatively, you could create a window in your filter, and set it as the message drain. Then you can easily trigger any processing you need when you detect a click