Sine Wave

Posted on 2001-08-30
Last Modified: 2013-11-20
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.
Question by:sudeep_shrivastava
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
LVL 31

Expert Comment

ID: 6440264
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,


Author Comment

ID: 6443881
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.
LVL 31

Accepted Solution

Zoppo earned 100 total points
ID: 6444326
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.

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!


Author Comment

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

Expert Comment

ID: 6457644

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

Expert Comment

by:Roshan Davis
ID: 9531966
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

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

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

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Here is how to use MFC's automatic Radio Button handling in your dialog boxes and forms.  Beginner programmers usually start with a OnClick handler for each radio button and that's just not the right way to go.  MFC has a very cool system for handli…
Introduction: Load and Save to file, Document-View interaction inside the SDI. Continuing from the second article about sudoku.   Open the project in visual studio. From the class view select CSudokuDoc and double click to open the header …
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
This is a high-level webinar that covers the history of enterprise open source database use. It addresses both the advantages companies see in using open source database technologies, as well as the fears and reservations they might have. In this…

696 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question