-3

The program written in C++ MFC has a Dialog Window which plays a full screen video and the cursor is hidden.

  1. I want to display the cursor when there is movement in mouse (video is playing in background)

  2. Cursor disappears when the mouse is inactive for 3 seconds (Video still playing)

Example:It is just like any video player in fullscreen mode, where the controls are hidden if mouse is inactive and mouse movement gets the controls back.

I have tried

if(WM_MOUSEMOVE)
{ShowCursor(TRUE)}

in the BOOL CDialog1::OnInitDialog()

But it shows (TRUE) even if there is no mouse movement.

Thank you!

rrirower
  • 4,338
  • 4
  • 27
  • 45
mrudulaw
  • 15
  • 1
  • 4

1 Answers1

3

This code:

I have tried if(WM_MOUSEMOVE) {ShowCursor(TRUE)

} in the BOOL CDialog1::OnInitDialog()

looks like if it was a pseudo code, if(WM_MOUSEMOVE) is equivalent to if(true).

What you should do is to catch WM_MOUSEMOVE message and then show your cursor, still inside this message handler set a timer with time for example 3 seconds, in timer handler hide your cursor. Remember to recreate your timer each time WM_MOUSEMOVE is received so it will reset it to start counting again from begining.

I am not getting into details, as this question is not on how to receive messages with MFC, right? You dont catch messages inside OnInitDialog.


BOOL CDlg::PreTranslateMessage(MSG* pMsg)
{
  if (pMsg->message == WM_MOUSEMOVE)
  {}
  return CDialogEx::PreTranslateMessage(pMsg);
}
marcinj
  • 48,511
  • 9
  • 79
  • 100
  • Yes, I may not have mentioned this in the Question, Where do i catch the MouseMove message? define a HRESULT or HCURSOR function? – mrudulaw Mar 01 '16 at 17:39
  • @mrudulaw http://stackoverflow.com/questions/22474863/how-to-capture-mousemove-event-in-a-mfc-dialog-based-application-for-a-checkbox – marcinj Mar 01 '16 at 17:42
  • BEGIN_MESSAGE_MAP(CFlickyFull, CDialogEx) ON_WM_PAINT() ON_WM_QUERYDRAGICON() ON_WM_MOUSEMOVE() END_MESSAGE_MAP() void CFlickyFull::OnMouseMove(UINT nFlags, CPoint point) { // TODO: Add your message handler code here and/or call default ShowCursor(TRUE); } If I move the mouse,it should enter the function (MouseMove)? That's not happening when i execute it. – mrudulaw Mar 01 '16 at 18:39
  • @mrudulaw I suppose some child controls is eating this message, you might try catching it inside PreTranslateMessage, see my answer for example. – marcinj Mar 01 '16 at 19:13
  • Ok, now it catches, but it does it after the video is played and stopped. I have written the video play code inside OnPaint(). – mrudulaw Mar 01 '16 at 19:33
  • @mrudulaw maybe you are blocking OnPaint? This would prevent pretranslatemessage from receiving messages. If that is true then you sholuld follow some video play tutorial, ie.: http://www.codeproject.com/Questions/516017/Howplustoplusdiaplayplustheplusvideopluswithinplus, or maybe use DirectShow. – marcinj Mar 01 '16 at 19:46