CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    Aug 2009
    Posts
    84

    [MFC] PolyLine and autoscrolling canvas

    Hello everyone!!!!

    I'm creating a task manager's-like-scroll-graphic.
    So for this I was thinking to create a vector of vectors of values, where the main vector is to draw more sources, and inside each "internal" vector there are a set of values. The size of each vector containing values would be the same as rect.right converted in points using ((float)rc.right / (float)dwDPI) * 72) where dwDPI was read from the registry to get the current DPI screen.
    BUT, since I thought to have a wide size of array due for resizing/enlarging window, since I was thinking to use PolyPolyLine, how I can make it drawing so the last element of the array would be drawn at rc.right of the drawing region?... Or maybe there's a better way to draw it avoiding also flickering?....

    Thanks to everyone in advance
    Ciao,
    Luigi

  2. #2
    Join Date
    May 2006
    Location
    Dresden, Germany
    Posts
    458

    Re: [MFC] PolyLine and autoscrolling canvas

    Hi,

    can you give us a little bit more information about your application?
    Is it a dialog or a frame window?

    Generally speaking: There is no need to calculate the drawing positions with DPI and float and so on. You can get the right most position of a window (which can be a control too) by calling GetClientRect(&r);
    Code:
    CRect rect2draw;
    GetClientRect(&rect2draw);
    Now you can draw on this rectangle without using any float values:
    Code:
    for (int xx = rect2draw.right; xx>=rect2draw.left; xx--)
    {
      // calculate your yy value here (depending of your data)
      // xx,yy is the point to draw
    }
    Using PolyPolyLine is also possible, the calculations will be similar.

    If you want to draw flickerfree search this forum for "double buffering", there are some examples (at least one from me).

    With regards
    Programartist
    Last edited by ProgramArtist; January 27th, 2010 at 04:39 AM. Reason: calculating error

  3. #3
    Join Date
    Aug 2009
    Posts
    84

    Re: [MFC] PolyLine and autoscrolling canvas

    HI ProgramArtist,

    first, thank you for your reply...
    What I'm making is a CWnd class component that will be integrated in another application which will pass some data. I'm thinking about a DLL component because in this component I will have to draw lines with sliding screen in a tab of the application, and some vertical rectangle bars in another tab of same application.
    I was in doubt about the calculation of drawing position basing on DPI because if I move the application in another PC which could have different screen resolution or different monitor...

    I was thinking first to put values in a vector, sized as the whole screen width so if I want to maximize the application those values that are "hided" in the left would appear, and at the same time to calculate the Y axis in a vector of POINT (a precisation, both vectors, values and POINT, could be also vector of vector if I have more than one source) starting from the end of the vector (I guess) so PolyPolyLine will draw the vector from the right side of the client...

    Would that be a good idea?... If yes, since values are simply double values, to represent them on the screen, is there something like a formula which would put convert a certain value in POINT Y considering an interval from 0 to clientrect.bottom?
    And considering this way I'm doing, do you think is good using vector or would be better using std:eque for performance (I see in the help it has resize() so I could set n-elements as ParentWndRect.right )?...

    Thanks again in advance for the little help
    Ciao
    Luigi

  4. #4
    Join Date
    Aug 2009
    Posts
    84

    Re: [MFC] PolyLine and autoscrolling canvas

    Hello again ProgramArtist,

    I've figured about "drawing" a PolyLine graphic on the canvas but I have this doubt: is the PolyLine compatible with MM_ANISOTROPIC and rescaling automatically graphic at repaint?...
    This because, having this code below:

    Code:
            CPaintDC dc(this); // device context for painting
            dc.SetBkColor(RGB(0,0,0));
           
            CRect rect;
            GetClientRect(&rect);
     
            int save = dc.SaveDC();
     
            if(bSetDraw)
            {
                    CMemDC mDC(&dc);
     
                    //mDC.SetBkColor(RGB(0,0,0));
                    mDC.SetMapMode(MM_ANISOTROPIC);
                    mDC.SetWindowOrg(rect.BottomRight());
                    mDC.SetViewportOrg(0, 0);
                    mDC.SetViewportExt(-1, -1);
                    mDC.SetWindowExt(1, 1);
                    // ********** Background ***********
                    // Grid
                    if (bActivateGrid)
                    {
                            CPen qLinePen(PS_SOLID, 1, RGB(0,139,0));
                            mDC.SelectObject(&qLinePen);
     
                            // Grid - Horizontal lines
                            mDC.MoveTo(1, 0);
                            mDC.LineTo(rect.Width(), 0);
                            int height = rect.Height();
                            int maxlines = height / (int)12.5;
                            for (int i=1;i<=maxlines;i++){
                                    int y_axis = (int)((double)i * 12.5);
                                    if (y_axis <= rect.Height()) {
                                            mDC.MoveTo(1, y_axis);
                                            mDC.LineTo(rect.Width(), y_axis);
                                    }
                            }
     
                            // Grid - Vertical lines
                            mDC.MoveTo(0, 0);
                            mDC.LineTo(0, rect.Height());
                            int width = rect.Width();
                            maxlines = width / (int)12.5;
                            for (int i=1;i<=maxlines;i++){
                                    int x_axis = (int)(((double)i * 12.5) - gridOffset);
                                    if (x_axis <= rect.Width()) {
                                            mDC.MoveTo(x_axis, 1);
                                            mDC.LineTo(x_axis, rect.Height());
                                    }
                            }
     
                            qLinePen.DeleteObject();
                    }
                    // *********** graphic component ***********
                    // based on choice of graph type
                    CPen qPolylinePen(PS_SOLID, 1, RGB(0, 255, 0));
                    switch (iGraphType)
                    {
                    case GRAPH_BARS:
                            break;
     
                    case GRAPH_LINES:
                            {                              
                                    if (vtPoints.capacity() == 1)
                                    {
                                            mDC.SelectObject(qPolylinePen);
                                            vectfPoints* pointsline = &vtPoints[0];
                                            mDC.Polyline(&(*pointsline)[0], (int)pointsline->size());
                                            //mDC->PolyPolyline()
                                            qPolylinePen.DeleteObject();
                                    }
                            }
                            break;
     
                    default:
                            break;
                    }
                    GDI_FLUSH();
            }
     
            dc.RestoreDC(save);
    inside the OnPaint() event it draws the graphic but when I resize window it doesn't rescale and redraw graphic depending of the height of the canvas...May I have forgot something or coded wrong something else?...

    Thanks in advance!!
    Ciao, Luigi

  5. #5
    Join Date
    Aug 2009
    Posts
    84

    Re: [MFC] PolyLine and autoscrolling canvas

    Hello everyone!!!!

    No suggest or hint on my last question?...

    Thanks in advance,
    Ciao
    Luigi

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured