PDA

View Full Version : Detecting mouse status and position



JensRichter
November 23, 2004, 14:59:38
Hi!

I have a application (CFormView) where I need to detect the position of the mouse and the state of the mousebuttons. This works fine within the form view except within the window displaying the live video. After stopping the live video I am also able to get the position within the "video window"

Is there any chance to get the mouse messages while displaying the live video?

Thanks in advanve

Best regards

Jens

Stefan Geissler
November 23, 2004, 16:37:06
Hello,

yes, this is possible. I assume you use a CStatic class window, to display the live video in. You need a window, that is able to handle mouse events. CStatic has no mouse event handlers, thus you should derive your own window class from CWnd and add the mouse handlers to it. Write the header file as follows:


class CICView : public CWnd
{
public:
CICView();
virtual ~CICView();

protected:
afx_msg void OnMouseMove(UINT nFlags, CPoint point);
DECLARE_MESSAGE_MAP()
}


Then create the class cpp file as follows:


#include "ICView.h"

BEGIN_MESSAGE_MAP(CICView, CWnd)
ON_WM_MOUSEMOVE()
END_MESSAGE_MAP()

CICView::CICView()
{
}

CICView::~CICView()
{
}

//////////////////////////////////////////////////////////////////////////
/* Mouse Move Event handler
*/
void CICView::OnMouseMove(UINT nFlags, CPoint point)
{
GetOwner()->SendMessage(WM_MOUSEMOVE,(WPARAM)point.x, (LPARAM)point.y);
TRACE("Flags %d Pos %d/%d\n",nFlags, point.x, point.y);
CWnd::OnMouseMove(nFlags, point);
}

This small class just implemets only a mouse move handler and sends this event to its parent.

Now add the CStatic that was created with the resource workshop in your form view as new member variable (control) to your form view class. In the header of this class include the the header of the new CICView class and change


// Dialog Data
//{{AFX_DATA(CVCDPropertyTreeDlg)
enum { IDD = IDD_VCDPROPERTYTREE_DIALOG };
CStatic m_cICView;
//}}AFX_DATA

to


// Dialog Data
//{{AFX_DATA(CVCDPropertyTreeDlg)
enum { IDD = IDD_VCDPROPERTYTREE_DIALOG };
CICView m_cICView;
//}}AFX_DATA

(“CStatic” changed to “CICView”). Just add the line m_Grabber.setHWND( m_cICView.m_hWnd ); where it is needed.
Now you can add any mouse event handlers you need to your class.

JensRichter
November 24, 2004, 08:25:55
Hi Stefan,
thanks a lot for your help.

You found the solution to my problem.

Best regards

Jens