mercredi 5 août 2015

MFC - How to draw pixel waves inside a rectangle


I am new to MFC trying to learn from the scratch.

I am trying to create a small dialog based application in VS2012 - MFC.

On the dialog window i have drawn a rectangle (in OnPaint event) like this.

CPaintDC dc(this);
CRect background1(10,10,208,92);
dc.Rectangle(10,10,208,92);

Then i filled the bacground with some color. Like this.

   CBrush brush1;
   brush1.CreateSolidBrush(RGB(2,3,4));
   dc.FillRect(background1,&brush1);

Now i wanted to draw waves in form of pixels continuously inside the rectangle.

As of now what i have done is,

bool top = false;
    for(i=10,j=92;i<200 && j>10;)
    {
        pDC->SetPixel(i,j,NewColor);
        Sleep(10);

        if(!top)
            j-=1;
        else
            j+=1;
        if(j%4==0)
        {
            i+=1;

        }
        if(j==12)
            top=true;
        if(j==90)
            top = false;

    }

I am just drawing the pixels straightaway on the window, but within the dimensions where the rectangle lies. And the waves stop as it reaches the right dimension of the rect. But i feel thats not the right way to do it.

I want to draw the waves inside the rectangle and also continuosly, like when it reacahes the right end it should move left and it should be continuous.

Is there any proper way in MFC to draw something inside a rectangle (technically inside another object)?

Please help me out.



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire