Solved

Sine Wave

Posted on 2001-08-30
7
1,024 Views
Last Modified: 2013-11-20
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
Comment
Question by:sudeep_shrivastava
7 Comments
 
LVL 31

Expert Comment

by:Zoppo
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,

ZOPPO
0
 

Author Comment

by:sudeep_shrivastava
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

by:
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.

ZOPPO
0
Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

 

Author Comment

by:sudeep_shrivastava
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

by:orange_juice
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

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.

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

Roshan Davis
EE Cleanup Volunteer
0

Featured Post

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

Suggested Solutions

Introduction: Ownerdraw of the grid button.  A singleton class implentation and usage. Continuing from the fifth article about sudoku.   Open the project in visual studio. Go to the class view – CGridButton should be visible as a class.  R…
If you use Adobe Reader X it is possible you can't open OLE PDF documents in the standard. The reason is the 'save box mode' in adobe reader X. Many people think the protected Mode of adobe reader x is only to stop the write access. But this fe…
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 video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…

786 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