Improve company productivity with a Business Account.Sign Up

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1064
  • Last Modified:

Sine Wave

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.
1 Solution
Hi sudeep_shrivastava,

how to start with this may depend on what your application should be used for.

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
of your app...

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,

sudeep_shrivastavaAuthor 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.
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.

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

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

this is not done by me, see it yourself whether you like it or not
Roshan DavisCommented:
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:

Answered by: Zoppo

Please leave any comments here within the next seven days.


Roshan Davis
EE Cleanup Volunteer
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.

Join & Write a Comment

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now