Click here to Skip to main content
15,884,472 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I want to close my dialog after no movement of cursor over dialog for 5 seconds.

What I have tried:

OnTimer();
int iclose;

iclose+=1;
If(iclose==5)
this->SetWindow(SW_HIDE);
Posted
Updated 25-Feb-17 9:53am
Comments
[no name] 25-Feb-17 14:30pm    
Okay so post your real code, format it and ask a question.

1 solution

Hiding the window will hide the dialog but not close it.  To close the dialog, call CDialog::EndDialog[^].

Of course, you also have to write the logic to periodically check if the appropriate time has elapsed before you end the dialog.

/ravi
 
Share this answer
 
v3
Comments
Shahzad Naseer 25-Feb-17 16:30pm    
Thanks ravi, and what about no mouse movement for 5 seconds to enddialog, i want to track mousemovement over dialog , i know some other articles are here i.e OnSetCursrs(); but it didnt work, any sultion plz, my watsap +923004794622,
Ravi Bhavnani 25-Feb-17 16:40pm    
Please don't expect me (or any other CP volunteer) to do your work for you. And if you expect us to send you a custom solution via WhatsApp, you're smoking some really good s---.

Why are you using SetCursor()? The purpose of that method is to set the visual cursor and has nothing to do with determining the position of the cursor. Instead, override CWnd::OnMouseMove() to determine whether the mouse is within the bounds of your dialog. You will need to write additional logic to compute how long the mouse has remained stationary over the dialog in order to determine whether the dialog should be automatically closed.

/ravi
Shahzad Naseer 25-Feb-17 19:38pm    
I am sorry,
I think things can be made possible at c++;

BOOL CMyDialog::OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT message)
{
CWnd* pWndtooltip = GetDlgItem(IDC_STATIC_TOOLTIP);

if (pWnd != this)
{
if (IDC_SN_START_ON == pWnd->GetDlgCtrlID())
pWndtooltip->ShowWindow(SW_SHOW);

}
else
pWndtooltip->ShowWindow(SW_HIDE);

SetCursor(AfxGetApp()->LoadStandardCursor(IDC_ARROW));


return true;
Ravi Bhavnani 25-Feb-17 19:42pm    
I apologize - I misread OnSetCursor() for SetCursor().

But I'm confused by your desire to show/hide a tooltip window. I thought you wanted to automatically end the dialog when the mouse has been stationary over the dialog for 5 seconds or more?

/ravi
Ravi Bhavnani 25-Feb-17 19:46pm    
I think you can achieve your goal by modelling your logic on the code in this article:
https://www.codeproject.com/Articles/19714/Auto-close-message-box

/ravi

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900