You are here:

C++/1)Inserting \showing graph 2)making run\stop button


Followup To
Question -
Hi Eddie,
In c++(using dot net &MFC), how can I:
1)Showing "regular" X-Y graph which depending
on the results of the last running.
2)Right now my program running in a limted number of iterations, how can I make a "stop" button
(Do->modal wasn't good,Do->modaless wasn't working)

Answer -
Hello Tomer,

I'm not sure I understand what you mean by:
Showing "regular" X-Y graph which depending
on the results of the last running.

If you could be a little more specific I would be glad to try and  help with that. As far as the "stop" button. Lets say you make a box in your program for stopping and exiting. You give it the ID "IDC_EXIT". You create the prototype in the message map for the function, and the definition would be(assuming you are using a dialouge box):

void CDialogue::OnExit()

This function posts the WM_DESTROY message in the windows operating system and the program should exit.

I hope this information was of some help to you. Feel free to respond again if I failed to address something.

- Eddie
First of all thanks for the quick responde(and your time :-))

1)The program me and my partner working on it using heuristic algorithm
 for the TSP problem(finding minmal weight hamilton path), what we want
 to show is a graph where the x-axis is the number of iteration,and
 y-axis is the value of the "local minmum" variable of the i'th iteration.
 (in other words its sould look like a graph of speed/time of a car)
2)There is a "run" mode for the program which make all the program options
 unavailble for the user till the running is finshed.
 Right now this running is limited by number of iterations of the
 algorithm , we want to make another running mode "unlimted" which allow
 the algorithm to run till the user push "stop" button.
 We want that in this running mode the user wouldn't be able to use/change
 options of the program, and after he push "stop" we want to stay in the

 Thanks again,

Hello Again Tomer,

For graphing in the window, since you are using MFC you can call a function called SetPixel. Its a member function of CDC. It actually sounds like it will take care of exactly what you want. It takes in a POINT object and a color:


p.x = graphX;
p.y = graphY;

cdc->SetPixel(p, RGB(255, 0, 0));

That should draw at your x and y graph style.

For the run mode, I would suggest using a finite state machine. It should take care of those issues.

void App::Update()
case APP_RUN:

case APP_STOP:
// do options

case APP_EXIT:


Its been so long since I worked with MFC, but I believe that should do the trick.

I hope that helped.

- Eddie


All Answers

Answers by Expert:

Ask Experts




I can answer questions about the C++ language, object oriented design and architecture. I am knowledgable in a lot of the math that goes into programming, and am certified by I also know a good deal about graphics via OpenGL, and GUIs.


I have completed numerous games and demos created with the C++ programming language. Currently employed as a software engineer in the modeling and simulation field. I have about 7 years experience.

©2017 All rights reserved.