Thread: ON_WM_BUTTONDOWN problem

  1. #1
    R
    Guest

    Angry ON_WM_BUTTONDOWN problem

    Ok this is how it is,

    I created an empty single document using wizard in VC 6 win98.

    Then i directly modified the

    BEGIN_MESSAGE_MAP(CMainFrame, CFrameWnd)
    //{{AFX_MSG_MAP(CMainFrame)

    ON_WM_LBUTTONDOWN() ////////////added this line

    ON_WM_CREATE()
    //}}AFX_MSG_MAP
    // Global help commands
    ON_COMMAND(ID_HELP_FINDER, CFrameWnd::OnHelpFinder)
    ON_COMMAND(ID_HELP, CFrameWnd::OnHelp)
    ON_COMMAND(ID_CONTEXT_HELP, CFrameWnd::OnContextHelp)
    ON_COMMAND(ID_DEFAULT_HELP, CFrameWnd::OnHelpFinder)
    END_MESSAGE_MAP()

    and then i defined the functions as, public:
    afx_msg void OnLButtonDown(UINT nFlags, CPoint point);

    and in the body of the function just placed a message box.
    void CMainFrame::OnLButtonDown(UINT nFlags, CPoint point)
    {
    MessageBeep(-1);

    MessageBox("yeeha", NULL, MB_OK);
    }

    Now the problem is when i presses the left mouse button beep or the message box does not pops up? why is it.

  2. #2
    Registered User Esss's Avatar
    Join Date
    Aug 2001
    Posts
    133
    The client area of the window is covered by a view. If you want to process mouse messages, you'll have to do it in the view class.
    Ess
    Like a rat in a maze who says,
    "Watch me choose my own direction"
    Are you under the illusion
    The path is winding your way?
    - Rush

  3. #3
    R
    Guest

    Question

    Ok , thanks, but now when i try to draw on the screen nothing pops up?

    void CView::OnLButtonDown(UINT nFlags, CPoint point)
    {

    //MessageBeep(-1);

    MessageBox("yeeha", NULL, MB_OK); //this pops up
    CRectTracker tracker;
    tracker.TrackRubberBand(this, point);


    CClientDC dc(this);
    dc.SelectObject(m_pen);
    dc.SelectObject(CBrush::FromHandle((HBRUSH)::GetSt ockObject(NULL_BRUSH)));


    switch(m_nDrawMode)
    {
    case DM_LINE:
    dc.MoveTo(tracker.m_rect.TopLeft());
    dc.LineTo(tracker.m_rect.BottomRight());
    break;

    }

    }

  4. #4
    Registered User Esss's Avatar
    Join Date
    Aug 2001
    Posts
    133
    I think you misunderstand the functionality of CRectTracker.

    CRectTracker is designed to implement the sizing rectangles you see around OLE objects and the like. As such, you keep it around for as long as the rectangle is to be displayed - you don't just create it for a fraction of a millisecond when you click the left mouse button.

    What are you hoping to achieve?
    Ess
    Like a rat in a maze who says,
    "Watch me choose my own direction"
    Are you under the illusion
    The path is winding your way?
    - Rush

  5. #5
    R
    Guest
    just want to draw a line on screen,


    switch(m_nDrawMode)
    {
    case DM_LINE:
    dc.MoveTo(tracker.m_rect.TopLeft());
    dc.LineTo(tracker.m_rect.BottomRight());
    break;

    }


    isn't above block suppose to do that?

  6. #6
    Registered User Esss's Avatar
    Join Date
    Aug 2001
    Posts
    133
    No. You create a new CRectTracker object; at that point, how big do you think its rectangle is going to be?
    Ess
    Like a rat in a maze who says,
    "Watch me choose my own direction"
    Are you under the illusion
    The path is winding your way?
    - Rush

  7. #7
    R
    Guest
    void CView::OnLButtonDown(UINT nFlags, CPoint point)
    {

    //MessageBeep(-1);

    MessageBox("yeeha", NULL, MB_OK); //this pops up


    CRectTracker tracker;
    tracker.TrackRubberBand(this, point);


    CClientDC dc(this);
    dc.SelectObject(m_pen);
    dc. SelectObject(CBrush::FromHandle((HBRUSH)::GetStock
    Object(NULL_BRUSH)));


    switch(m_nDrawMode)
    {
    case DM_LINE:
    dc.MoveTo(tracker.m_rect.TopLeft());
    dc.LineTo(tracker.m_rect.BottomRight());
    break;

    }

    }



    Would not the tracker above return the size (top & bottom coordinate) of the size of rectangle? and the when (if) it does why does code in switch draw it?

  8. #8
    Registered User Esss's Avatar
    Join Date
    Aug 2001
    Posts
    133
    I fail to see why posting the same code three times is going to help your cause.

    When you create a CRectTracker object, it starts with a zero-size rectangle. That is why nothing is displayed. Why do you expect it will do anything else?

    You are using the wrong technique for rubber-band lines. Do not use CRectTracker. Store the original position in OnLButtonDown, and redraw the line in OnMouseMove.
    Ess
    Like a rat in a maze who says,
    "Watch me choose my own direction"
    Are you under the illusion
    The path is winding your way?
    - Rush

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Need help understanding a problem
    By dnguyen1022 in forum C++ Programming
    Replies: 2
    Last Post: 04-29-2009, 04:21 PM
  2. Memory problem with Borland C 3.1
    By AZ1699 in forum C Programming
    Replies: 16
    Last Post: 11-16-2007, 11:22 AM
  3. Someone having same problem with Code Block?
    By ofayto in forum C++ Programming
    Replies: 1
    Last Post: 07-12-2007, 08:38 AM
  4. A question related to strcmp
    By meili100 in forum C++ Programming
    Replies: 6
    Last Post: 07-07-2007, 02:51 PM
  5. WS_POPUP, continuation of old problem
    By blurrymadness in forum Windows Programming
    Replies: 1
    Last Post: 04-20-2007, 06:54 PM