[英]If mouse movement detected, show cursor in a dialog window C++ MFC
The program written in C++ MFC has a Dialog Window which plays a full screen video and the cursor is hidden.用 C++ MFC 编写的程序有一个对话框窗口,它播放全屏视频并且光标被隐藏。
I want to display the cursor when there is movement in mouse (video is playing in background)我想在鼠标移动时显示光标(视频在后台播放)
Cursor disappears when the mouse is inactive for 3 seconds (Video still playing)当鼠标处于非活动状态 3 秒时光标消失(视频仍在播放)
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()
在
BOOL CDialog1::OnInitDialog()
But it shows (TRUE) even if there is no mouse movement.但即使没有鼠标移动,它也会显示 (TRUE)。
Thank you!谢谢!
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)
.看起来如果它是伪代码,
if(WM_MOUSEMOVE)
等价于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.你应该做的是捕捉
WM_MOUSEMOVE
消息,然后显示你的光标,仍然在这个消息处理程序中设置一个定时器,例如 3 秒,在定时器处理程序中隐藏你的光标。 Remember to recreate your timer each time WM_MOUSEMOVE
is received so it will reset it to start counting again from begining.请记住每次收到
WM_MOUSEMOVE
都要重新创建计时器,以便它会重置它以重新开始计数。
I am not getting into details, as this question is not on how to receive messages with MFC, right?我没有详细说明,因为这个问题不是关于如何使用 MFC 接收消息,对吗? You dont catch messages inside
OnInitDialog
.您不会在
OnInitDialog
捕获消息。
BOOL CDlg::PreTranslateMessage(MSG* pMsg)
{
if (pMsg->message == WM_MOUSEMOVE)
{}
return CDialogEx::PreTranslateMessage(pMsg);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.