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(UINT 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
DJ_AM_JuiceboxAsked:
Who is Participating?
 
alb66Commented:
When you create a new window, and the mouse is in its client area, a WM_MOUSEMOVE is generated even if the mouse is not moving.
If you put the mouse near a border of the main frame and then press ctrl+N, the new child window will be create but, since mouse is outside its client area, no mouse message will be generated for the new window.
0
 
DJ_AM_JuiceboxAuthor Commented:
the other strange thing is that the file choose dialog is created before the child frame even exists, so I don't see how it could be sending a mouse move message?:

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, m_pMainWnd);
    CChildFrame* pChildFrame = (CChildFrame*)pFrame->CreateNewChild(RUNTIME_CLASS(CChildFrame), IDR_MtApp_WindoTYPE, m_hMDIMenu, m_hMDIAccel);
   
    // Here already a mouse move message has been generated, and it thinks that one of the mouse buttons was being held!
}
0
 
DJ_AM_JuiceboxAuthor Commented:
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
0
Cloud Class® Course: CompTIA Healthcare IT Tech

This course will help prep you to earn the CompTIA Healthcare IT Technician certification showing that you have the knowledge and skills needed to succeed in installing, managing, and troubleshooting IT systems in medical and clinical settings.

 
jkrCommented:
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);
0
 
DJ_AM_JuiceboxAuthor Commented:
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.
0
 
jkrCommented:
Have you checked "point"? Just to be sure...
0
 
DJ_AM_JuiceboxAuthor Commented:
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.
0
 
DJ_AM_JuiceboxAuthor Commented:
@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!
0
 
alb66Commented:
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...
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.