I am using vlc to capture a video and audio stream and display it in a picture box. The new libvlc api no longer supports the double click/fullscreen in windows and I need to have that functionality. I don’t have a problem creating a new form, adding a picture box to it and showing the video in that, but I do have a problem capturing the double click event in the vlc window in order to tell the app to make the video feed fullscreen. I found out that I need to use a hook. I have the hook installed and all of that. My only problem is, I only want to handle the message if it is a click in one of my pictureboxes. So, from my callback method, here is what I need:
private static IntPtr HookCallback(int nCode, IntPtr wParam, IntPtr lParam)
{
if (nCode >= 0 && MouseMessages.WM_LBUTTONDOWN == (MouseMessages)wParam)
{
//Here I need to grab the Handle of the control that the mouse was clicked in.
//Now I need to cast the Control.FromHandle() as PictureBox.
// then if(control != null)
// send the event to the form via. form.on_double_click or whatever.
}
return CallNextHookEx(_hookID, nCode, wParam, lParam);
}
Any ideas?
Ubdate:
Here is what I’ve got now, look good?
private static IntPtr HookCallback(int nCode, IntPtr wParam, IntPtr lParam)
{
if (nCode >= 0 && MouseMessages.WM_LBUTTONDOWN == (MouseMessages)wParam)
{
MOUSEHOOKSTRUCT msg = (MOUSEHOOKSTRUCT)Marshal.PtrToStructure(lParam, typeof(MOUSEHOOKSTRUCT));
PictureBox control = Control.FromHandle(msg.hwnd) as PictureBox;
if (control != null)
{
PreviewForm.pbox_MouseDoubleClick(control, new MouseEventArgs(MouseButtons.Left, 2, msg.pt.x, msg.pt.y, 0));
}
}
return CallNextHookEx(_hookID, nCode, wParam, lParam);
}
Update
Another little gotcha for those coming in from Google. In Windows 7, If you attach your debugger to the callback, it will appear to be broken. There is a timeout value on hook responses, if that timeout ever expires, your hook will never fire again for the life of the hook. From my reading, it appears that this is a Windows 7 issue while it works on Windows Vista and less. The break point in your debugger will most certainly force this timeout to expire and as a result, your callback will only be called once. However, it will work fine without the break point.
Your
lParamis a pointer to a MOUSEHOOKSTRUCT which will contain the window handle.You can use the definition a Pinvoke.net and marshal lParam to that type.