Go Premium for a chance to win a PS4. Enter to Win

x
Solved

# Sine Wave

Posted on 2001-08-30
Medium Priority
1,056 Views
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
Question by:sudeep_shrivastava

LVL 31

Expert Comment

ID: 6440264
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 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.
0

LVL 31

Accepted Solution

Zoppo earned 400 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.

ZOPPO
0

Author Comment

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

LVL 1

Expert Comment

ID: 6457644
http://www.codeproject.com/miscctrl/oscope.asp

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

LVL 23

Expert Comment

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:

Roshan Davis
EE Cleanup Volunteer
0

## Featured Post

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: Displaying information on the statusbar.   Continuing from the third article about sudoku.   Open the project in visual studio. Status bar – let’s display the timestamp there.  We need to get the timestamp from the document s…
This Micro Tutorial will teach you how to add a cinematic look to any film or video out there. There are very few simple steps that you will follow to do so. This will be demonstrated using Adobe Premiere Pro CS6.
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.
###### Suggested Courses
Course of the Month10 days, 13 hours left to enroll