-
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.
-
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.
-
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;
}
}
-
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?
-
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?
-
No. You create a new CRectTracker object; at that point, how big do you think its rectangle is going to be?
-
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?
-
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.