Link to home
Start Free TrialLog in
Avatar of bi7206327
bi7206327

asked on

Draw graphs.

i have currently developed a sdi program for my sch's project. the window has two panes which i have derived from the CFormView and CView.

the users will enter some parameters in the CFormView, they will be processed by some equations. the question is... how do i draw a graph wif x and y axis on the CView so that when the user enter the parameters (from the CFormView), the results can be shown on the CView with a graph. the graph is not unlike a sin/cos curve.
Avatar of bi7206327
bi7206327

ASKER

Edited text of question
Edited text of question
ASKER CERTIFIED SOLUTION
Avatar of Answers2000
Answers2000

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
You're editted text came thru while I was typing, so commercial toolkits may be out the question ?  

If you need more help on #3 and #4 then let me know what you need.  

The coordinate system by default has 0,0 at the top left and is in pixels.

I've got to go offline for a bit, but I'll be back later, so post any comments on what else you might need.
In the form view catch when the user makes any changes to the children controls. One good technique for this is to create handler for notification messages of the children controls. For example you might catch EN_CHANGE or EN_KILLFOCUS for an edit control, or BN_CLICKED for a check box and so on. Then in these handlers call the UpdateData(TRUE) method of the CFormView. Link your controls to corresponding data members of your document class. You can do that by using DDX mechanism in your CFormView's DoDataExchange(). The easiest way to link them is to create member variables for the controls in the class wizard, and then in the DoDataExchange() replace those variables with your document variables. Be sure however to move the changed code outside of the class wizard comments. Otherwise the class wizord will not work the next time you start it.
Finally after calling UpdateData(TRUE) in your handlers call UpdateAllViews() method of your document. This will ensure that the document (assuming it is the document of the CView) will call the CView's OnUpdate() and will repaint your other view.
Basically that's the MFC way of one view to react to changes of another view.
Milenvk makes a good point.  The only caveat is that if regenerating the graph takes a long time you may prefer to either
(i) have a manual update/refresh button
or
(ii) Setup a timer (SetTimer funciton) in the FormView, add a boolean member to it to (initially set to FALSE), and whenever one of milenvk's changes happen set the flag to TRUE.  In the TimerProc look for a true flag, and only in this case redraw the graph (and then reset the flag back to false).  This way you don't have to have a long pause immediately after the user types in each digit into say a numeric field.

commercial toolkits are out of the question bcos my school project does not have a budget for it (such toolkits cost money rite??)

pls forgive me for i have just started learning VC++.... so can you kindly explain in more details the following:

1) Drawing of grids using the LineTo, TextOut etc etc functions.

2) For the program to generate the graph... let say i got two variables, theta and displacement, i will calculate the displacement at certain interval of theta. eg, at theta equal to 5, 10, 15, 20.... displacements are d1, d2, d3, d4. as such i would have the various pts. question is, how do i map this points into the grid i have drawn?? also, how to i join this various pts up after i mapped them into the grid i drawn??

the project gonna due very soon and i just can't seem to solve the problem. your help is very much appreciated. thanz in advance.