DJ_AM_Juicebox
asked on
check if mouse button being pressed (win32)
Hi,
I have a standard wizard generated MDI app. When the user opens a new file I create a new child frame/wnd. Before the child frame is created, I prompt the user with a file selction dialog, they have to pick a file to open. When they do this, my MouseMove() handler is called, which looks like:
void CChildView::OnMouseMove(UI NT nFlags, CPoint point)
{
if ((nFlags & MK_LBUTTON) ||
(nFlags & MK_RBUTTON))
{
TRACE("Yeah one of the mouse buttons is being held while moving....\n");
}
}
I don't understand why that's getting called when I pick a file from the choose file dialog. If I select a file to open with the enter key, then the mouse move function is not called....
Thanks
I have a standard wizard generated MDI app. When the user opens a new file I create a new child frame/wnd. Before the child frame is created, I prompt the user with a file selction dialog, they have to pick a file to open. When they do this, my MouseMove() handler is called, which looks like:
void CChildView::OnMouseMove(UI
{
if ((nFlags & MK_LBUTTON) ||
(nFlags & MK_RBUTTON))
{
TRACE("Yeah one of the mouse buttons is being held while moving....\n");
}
}
I don't understand why that's getting called when I pick a file from the choose file dialog. If I select a file to open with the enter key, then the mouse move function is not called....
Thanks
ASKER
actually it seems like it has nothing to do with the file choose dialog.
I can place my mouse in the middle of the main frame, hold down the left mouse button while NOT moving, then hit ctrl + n to create a new frame - and a mouse move message gets generated saying the left mouse button is being held.
Hmm what can I do??
Thanks
I can place my mouse in the middle of the main frame, hold down the left mouse button while NOT moving, then hit ctrl + n to create a new frame - and a mouse move message gets generated saying the left mouse button is being held.
Hmm what can I do??
Thanks
Mouse moves are very sensitive, even a slight movement that you wouldn't even notice can cause a move message. Is the CPoint always the same value? You can check tha using e.g.
TRACE2("Yeah one of the mouse buttons is being held while moving - x %d Y %d\n", point.x, point.y);
TRACE2("Yeah one of the mouse buttons is being held while moving - x %d Y %d\n", point.x, point.y);
ASKER
No it just comes up as wherever the mouse location is when I select a file.
I am certain the mouse is not moving, it's one of those thumb - ball ones so my finger isn't even on the ball when the frame is created - there's no way a mouse move should be generated. On the other hand, if I just press ctrl+n while over the main frame toolbar, no message is generated.
I am certain the mouse is not moving, it's one of those thumb - ball ones so my finger isn't even on the ball when the frame is created - there's no way a mouse move should be generated. On the other hand, if I just press ctrl+n while over the main frame toolbar, no message is generated.
Have you checked "point"? Just to be sure...
ASKER
No the CPoint is not always the same value on that message - it is wherever the mouse is at when I happen to hit ctrl + N.
For now I made a member of the wndow which is a CPoint initialized to (-1,-1). I set it to the last point moved on OnMouseMove(). I check to see if it is -1,-1 - if it is then I ignore the message. This always happens the first move message generated by a new frame.
It is strange.
For now I made a member of the wndow which is a CPoint initialized to (-1,-1). I set it to the last point moved on OnMouseMove(). I check to see if it is -1,-1 - if it is then I ignore the message. This always happens the first move message generated by a new frame.
It is strange.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
@alb66:
That is very strange, what is the purpose of generating a mouse move message upon creation?
I guess the fix I put it for now is sufficient, but it's an odd thing!
That is very strange, what is the purpose of generating a mouse move message upon creation?
I guess the fix I put it for now is sufficient, but it's an odd thing!
I think that in this way a window can instantly know that mouse is in its own client area.
Anyway this is the Windows behavior...
Anyway this is the Windows behavior...
ASKER
void CMyApp::OnFileNew()
{
// Prompt the user with a dialog where they can choose a single file.
CFileDialog cfd(TRUE, ".txt", NULL, OFN_FILEMUSTEXIST | OFN_NOCHANGEDIR, "text (*.txt)|*.txtAll Files (*.*)|*.*||", NULL, sizeof(OPENFILENAME));
if (cfd.DoModal() != IDOK) {
return;
}
CMainFrame* pFrame = STATIC_DOWNCAST(CMainFrame
CChildFrame* pChildFrame = (CChildFrame*)pFrame->Crea
// Here already a mouse move message has been generated, and it thinks that one of the mouse buttons was being held!
}