Re: CStatic and selection box

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance

From: Johan Rosengren (johan.rosengren_at_telia.com)
Date: 03/17/04


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



Relevant Pages

  • Re: Anchors and Objects
    ... "Webbiz" wrote in message ... What I specifically meant was set the drawmode to vbInvert, draw the line, then whe nthe mouse moves you draw over that line and it restores the previous background. ... I'd like to do the little boxes as it is common for this type of program. ... The logic usually used is to allow selection, then in either a continuation of the mouse movement or a spate mouse movement, move the line. ...
    (microsoft.public.vb.general.discussion)
  • Re: Anchors and Objects
    ... thanks for the play by play. ... The logic usually used is to allow selection, ... Draw little boxes at the end. ...
    (microsoft.public.vb.general.discussion)
  • Re: Anchors and Objects
    ... The logic usually used is to allow selection, then in either a continuation of the mouse movement or a spate mouse movement, move the line. ... You may want to first start the movement by drawing the screen without the line, then draw the line as you would a bounding box. ... Then all one needs to do is to click and drag one of those little boxes in order to lengthen the line and drop it in a new location. ... You can use windows for them, but you need to set the window region. ...
    (microsoft.public.vb.general.discussion)
  • Re: ASCII-Paint version 0.1 released
    ... If you draw using the right mouse button, ... brush when trying to draw two different things again and again. ... Right now you can press ESC to cancel symbol selection. ... To manually adjust the RGB values you can mouse-drag the ...
    (rec.games.roguelike.development)
  • Re: NMLVCUSTOMDRAW in ListView, what am I doing wrong ?
    ... You're not calling the base class in your WndProc ... You'll probably have to draw it yourself. ... > I'm trying to custom draw selection in ListView. ...
    (microsoft.public.dotnet.framework.windowsforms.controls)