x
• Status: Solved
• Priority: Medium
• Security: Public
• Views: 1064

# Sine Wave

Hi,
I want to draw sine wave in my appliction.I am using VC++ 6.0.And i have created my project with MFC APPWizard(exe).
I have tried with microsoft chart. But i am unable to draw. Can u help me.Waiting for ur reply.
Thanx.........
0
sudeep_shrivastava
1 Solution

Commented:
Hi sudeep_shrivastava,

Drawing to a window is easy if you can use SDI or MDI application with a view/document
structure ... simply implement drawing code in the used view's overridden OnDraw
function using CDC's MoveTo and LineTo functions.

But, i.e. which  view class you should use as base for your view depends on intention

To draw a sine-graph in a view I would do something like this:

const double pi = 3.14159265358979;
const double pi2 = 2 * pi; // for better performance... this defines sine is drawn for range from 0 to 2Pi.

void CMyView::OnDraw(CDC* pDC)
{
CRect rect;
GetClientRect( rect );

const double width = rect.Width();
const double pps = width * 0.005;  // pixel per step, here set to 200 steps, can be a const value too
const double step = pps * pi2 / width; // for better performance it's better to calculate as much as
const double stretch = pps * 1.0 / step; // possible which is const before the loop

const double amp = rect.Height() * 0.5;

pDC->MoveTo( 0, (int)amp );
int x1, y1;

for ( double x = 0; x <= pi2; x += step )
{
x1 = (int)( x * stretch );
y1 = (int)( ( 1.0 + sin( x ) ) * amp );
pDC->LineTo( x1, y1 );
}
}

hope that helps,

ZOPPO
0

Author Commented:
Actually i am using Dialog based application.Is it possible to draw sinewave by msChart.If not then how will i draw that wave in Dialog Based application.
0

Commented:
sorry, I don't have used msChart til now ... maybe it's possible but I don't know.

I think I would derive a class from CStatic, add a WM_PAINT message handler and
implement drawing in there.

Then I would add a frame to the dialog resource and subclass it with an instance
of my derived static-class.

ZOPPO
0

Author Commented:
Hi,
Ok it's all right.Thanks to give attention on my question.I will try with SDi or MDI.
0

Commented:
http://www.codeproject.com/miscctrl/oscope.asp

this is not done by me, see it yourself whether you like it or not
0

Commented:
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:

Roshan Davis
EE Cleanup Volunteer
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.