Re: CStatic and selection box
From: Johan Rosengren (johan.rosengren_at_telia.com)
Date: 03/17/04
- Next message: Scott McPhillips [MVP]: "Re: CStatic and selection box"
- Previous message: Scott McPhillips [MVP]: "Re: Detecting NM_CLICK in CMonthCalCtrl in CView--Right way?"
- In reply to: Stefano Malavasi: "CStatic and selection box"
- Next in thread: Scott McPhillips [MVP]: "Re: CStatic and selection box"
- Messages sorted by: [ date ] [ thread ]
Date: Wed, 17 Mar 2004 13:33:59 +0100
Stefano,
You will definitely have to draw the selection rectangle each time you
receive a mouse message :-))) But this is one case where you can draw
outside of the OnPaint handler.
You will have to handle WM_LBUTTONDOWN, WM_MOUSEMOVE and WM_LBUTTONUP. Add a
CRect member for the selection rect. Some code:
void CXXX::OnLButtonDown(UINT nFlags, CPoint point)
{
SetCapture();
m_selectionRect.left = m_selectionRect.right = point.x;
m_selectionRect.top = m_selectionRect.bottom = point.y;
}
void CXXX::OnMouseMove(UINT nFlags, CPoint point)
{
CClientDC dc( this );
// Erase old selection rect
if( m_selectionRect.left != m_selectionRect.right || m_selectionRect.top !=
m_selectionRect.bottom )
{
m_selectionRect.NormalizeRect();
dc.DrawFocusRect( m_selectionRect );
}
// Update and draw the new selection rect
m_selectionRect.right = point.x;
m_selectionRect.bottom = point.y;
m_selectionRect.NormalizeRect();
dc.DrawFocusRect( m_selectionRect );
}
void CXXX::OnLButtonUp(UINT nFlags, CPoint point)
{
ReleaseCapture();
RedrawWindow();
}
As for using a static, it is perfectly ok. Makes it a bit easier to use in a
dialog, even,
Johan Rosengren
Abstrakt Mekanik AB
"Stefano Malavasi" <s_malavasi_REMOVETHIS_@lycos_REMOVETHIS_.it> a écrit
dans le message de news:036g50dae9j8k34a6k2ntnkjr0pg6kmdc8@4ax.com...
> Hi,
> I derived a CStatic class to construct an owner draw control.
> This control is a XY-graph. Maybe it's the not the more efficient way
> ... but I did it that way. Now I'd like to select part of the graph
> and do a zoom on selection. How can I have a selection rectangle
> without having to draw a rectangle and invalidate the dc everytime
> that I move the mouse ?
>
> thanks in advance
>
> Stefano
> Stefano Malavasi
> ---------------------------------------------------------------------
> s_malavasi_REMOVETHIS_@_REMOVETHIS_lycos.it
> Remove the string _REMOVETHIS_ to reply by e-mail
- Next message: Scott McPhillips [MVP]: "Re: CStatic and selection box"
- Previous message: Scott McPhillips [MVP]: "Re: Detecting NM_CLICK in CMonthCalCtrl in CView--Right way?"
- In reply to: Stefano Malavasi: "CStatic and selection box"
- Next in thread: Scott McPhillips [MVP]: "Re: CStatic and selection box"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|