Drawing in Dialog in VC++ MFC
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 8 of 8

Thread: Drawing in Dialog in VC++ MFC

  1. #1
    Join Date
    Dec 2009
    Posts
    4

    Drawing in Dialog in VC++ MFC

    I have drawn drawing on a dialog using CRect function with CClientDC. This drawing is set of 90 rectangles. I am updating the position of rectangles using the following code. The values of LeafA[i] value will be changes during the running time. automatically the rectangle position also should change. But updation is not happening. for that I am using InvalidateRect() function. Flickring is happening when I am using InvalidateRect() to update the rectangles position.

    Please suggest if any thing is wrong or any other process to update or process for not flickering the region.

    void CMLCTreatDlg::OnPaint()
    {
    CPaintDC dc(this);
    DrawMLC();
    }

    void CMLCTreatDlg:rawMLC()
    {
    CPaintDC dc(this);
    int lpos,spos;
    int i;
    HDC hdc;

    CButton * but=(CButton*)GetDlgItem(IDC_STATIC_MLC);
    but->GetWindowRect(rect);

    CPen NewPen(PS_DASH,1,RGB(0,0,0));
    CPen NewPen1(PS_SOLID,1,RGB(0,0,0));
    CPen *OldPen;
    CBrush WinBrush(RGB(236,233,216));
    CBrush Setbrush(RGB(100,149,237));
    CBrush Actbrush(RGB(150,0,90));
    CBrush *OldBrush;//(RGB(216,233,236));
    hdc = GetDC ()->m_hDC;

    lpos=274,spos=157;
    CClientDC dcline(this);
    CClientDC actDC(this);
    CClientDC setDC(this);

    CDC memdc;
    memdc.CreateCompatibleDC(&dc);
    /* HBITMAP hbmp=CreateCompatibleBitmap(dc.m_hDC,rectArea->right,rectArea->bottom);
    HBITMAP hOld=(HBITMAP)memdc.SelectObject(hbmp);*/

    dcline.SelectObject(NewPen);

    actDC.SetBkMode(TRANSPARENT);
    setDC.SetBkMode(TRANSPARENT);
    setDC.SelectObject(Setbrush);
    actDC.SelectObject(WinBrush);



    GetClientRect(&rect);

    int pos;


    actDC.SetBkMode(TRANSPARENT);
    actDC.SelectObject(Actbrush);

    for(i=0;i<NOOFLEAVES;i++)
    {
    pos=(LEAFLENGTH/175)*LeafB[i];
    rect=CRect(spos+pos,lpos,spos+LEAFLENGTH+pos,lpos+LEAFWIDTH);
    setDC.Rectangle(rect);

    t=(float)(LEAFLENGTH/175.0)*LeafA[i];
    pos=(int)t;
    if(((spos+2*LEAFLENGTH)+pos)<=847)
    rect=CRect(spos+LEAFLENGTH+pos,lpos,(spos+2*LEAFLENGTH)+pos,lpos+LEAFWIDTH);
    else
    rect=CRect(spos+LEAFLENGTH+pos,lpos,847,lpos+LEAFWIDTH);
    //RedrawWindow(rect,NULL,RDW_ERASE);
    setDC.Rectangle(rect);

    lpos+=LEAFWIDTH;
    }


    /*to draw X-Axis and Y axis*/
    dcline.MoveTo(432,150);
    dcline.LineTo(432,950);
    dcline.MoveTo(25,550);
    dcline.LineTo(835,550);

    /*10x10 field*/
    dcline.MoveTo(353,471);
    dcline.LineTo(353,629);
    dcline.MoveTo(511,471);
    dcline.LineTo(511,629);

    dcline.MoveTo(353,471);
    dcline.LineTo(511,471);
    dcline.MoveTo(353,629);
    dcline.LineTo(511,629);

    /*20x20 field*/
    dcline.MoveTo(274,392);
    dcline.LineTo(274,708);
    dcline.MoveTo(590,392);
    dcline.LineTo(590,708);

    dcline.MoveTo(274,392);
    dcline.LineTo(590,392);
    dcline.MoveTo(274,708);
    dcline.LineTo(590,708);
    }

  2. #2
    Join Date
    Jul 2002
    Posts
    2,526

    Re: Drawing in Dialog in VC++ MFC

    void CMLCTreatDlg::OnPaint()
    {
    CPaintDC dc(this);
    DrawMLC(&dc);
    }

    void CMLCTreatDlg:rawMLC(CDC* pDC)
    {
    // draw to pDC here
    }

  3. #3
    Join Date
    May 2009
    Location
    Bengaluru, India
    Posts
    422

    Re: Drawing in Dialog in VC++ MFC

    Instead of or along with InvalidateRect() function try to use Refresh() call

  4. #4
    Join Date
    Dec 2009
    Posts
    4

    Re: Drawing in Dialog in VC++ MFC

    Alex,
    I tried like that, but same result.

    My problem is, continuously the LeafA[] values will be updated from hardware thru communication. Here the values are updating. But it is not moving. When we mnimized the screen, and restored, then the drawing is updated. But Iwant to display how it is moving. for this I use InvalidateRect() function to update the drawing. It is updating but some flickring is coming. Instead of Invalidrect(), is there any other funtion or process for this.

  5. #5
    Join Date
    Dec 2009
    Posts
    4

    Re: Drawing in Dialog in VC++ MFC

    I didn't find any refresh call, Let me know how to implement refresh call?

  6. #6
    Join Date
    Feb 2005
    Posts
    2,160

    Re: Drawing in Dialog in VC++ MFC

    I don't have any idea what vcedebugger means by "Refresh()", but your flickering is probably because by default, windows erases the background first before painting anything onto the client DC. As for anything else, please post actual working code (with code tags). The above won't compile, has typos, and many missing variables/defines.

  7. #7
    Join Date
    Jul 2002
    Posts
    2,526

    Re: Drawing in Dialog in VC++ MFC

    Your problem in not in OnPaint. See InvalidateRect API and CWnd:: Invalidate functions.

  8. #8
    Join Date
    Jul 2010
    Posts
    8

    Re: Drawing in Dialog in VC++ MFC

    you can use CreateCompatibleDC to create a DC in memory, and use CreateCompatibleBitmap to create a client for your memory dc, and draw what you need in this memory dc, and then use BitBlt to put your content in memory dc to your client dc.

Posting Permissions

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


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center