Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

program to notify window when mouse is moved

webcrawlerwebcrawler Member Posts: 12
in sams teach yourself visual c++ 6 in chapter 9 as the first exercise they want you to modify the mousetst program to display the current mouse position as the mouse is moved over the view. I modified the code to do this and what happens is as soon as the program window comes up with the mouse over it (or if you start the program with the mouse view outside the area of the program window and move the mouse across the window) the window that tells you the program had an error and asks if you want to send the problem to microsoft will come up. Here's the pertinent code (if you need to see other parts of the program, let me know. This is just one function.

void CMouseTstView::OnMouseMove(UINT nFlags, CPoint point, CDC* pDC)
{
// TODO: Add your message handler code here and/or call default
m_ptMouse = point;
CString coordinates = (CString)m_ptMouse.x;
coordinates += "," + (CString)m_ptMouse.y;
pDC->TextOut(m_ptMouse.x, m_ptMouse.y, "stringy");
}

I'm not even sure that the coordinates variable would print because I'm not sure about typecasting with these types. It is supposed to print the coordinates while you have the mouse over the window.

Comments

  • stoberstober Member Posts: 9,765 ✭✭✭
    : in sams teach yourself visual c++ 6 in chapter 9 as the first
    : exercise they want you to modify the mousetst program to display the
    : current mouse position as the mouse is moved over the view. I
    : modified the code to do this and what happens is as soon as the
    : program window comes up with the mouse over it (or if you start the
    : program with the mouse view outside the area of the program window
    : and move the mouse across the window) the window that tells you the
    : program had an error and asks if you want to send the problem to
    : microsoft will come up. Here's the pertinent code (if you need to
    : see other parts of the program, let me know. This is just one
    : function.
    :
    : void CMouseTstView::OnMouseMove(UINT nFlags, CPoint point, CDC* pDC)
    : {
    : // TODO: Add your message handler code here and/or call default
    : m_ptMouse = point;
    : CString coordinates = (CString)m_ptMouse.x;
    : coordinates += "," + (CString)m_ptMouse.y;
    : pDC->TextOut(m_ptMouse.x, m_ptMouse.y, "stringy");
    : }
    :
    : I'm not even sure that the coordinates variable would print because
    : I'm not sure about typecasting with these types. It is supposed to
    : print the coordinates while you have the mouse over the window.
    :


    >>CString coordinates = (CString)m_ptMouse.x;
    This is just plain nonsense -- how do you expect to typecast an integer to a string and think it will work??? Just as in normal every-day C/C++ programming the integer has to be converted first. One way is to use sprintf() to convert it, but CString has something just as good -- called the Format() method and the arguments are identical to sprintf().

    [code]
    CString coordinates;
    coordinates.Format("%d", m_ptMouse.x);
    [/code]


    =============================================
    never lie -- the government doesn't like the competition. (Author unknown)
Sign In or Register to comment.