Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

check if mouse button being pressed (win32)

Posted on 2007-08-07
9
Medium Priority
?
447 Views
Last Modified: 2013-11-20
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
0
Comment
Question by:DJ_AM_Juicebox
  • 5
  • 2
  • 2
9 Comments
 

Author Comment

by:DJ_AM_Juicebox
ID: 19649474
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
 

Author Comment

by:DJ_AM_Juicebox
ID: 19649519
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
 
LVL 86

Expert Comment

by:jkr
ID: 19649689
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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 

Author Comment

by:DJ_AM_Juicebox
ID: 19650122
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
 
LVL 86

Expert Comment

by:jkr
ID: 19650791
Have you checked "point"? Just to be sure...
0
 

Author Comment

by:DJ_AM_Juicebox
ID: 19650910
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
 
LVL 19

Accepted Solution

by:
alb66 earned 2000 total points
ID: 19651921
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
 

Author Comment

by:DJ_AM_Juicebox
ID: 19653705
@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
 
LVL 19

Expert Comment

by:alb66
ID: 19653750
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

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction: The undo support, implementing a stack. Continuing from the eigth article about sudoku.   We need a mechanism to keep track of the digits entered so as to implement an undo mechanism.  This should be a ‘Last In First Out’ collec…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

580 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question