You are here:

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

Advertisement


Question
-------------------------
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()
{
    PostQuitMessage(0);1
}

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
 program.

 Thanks again,
 Tomer.  

Answer
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:

POINT p;

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()
{
switch(currentState)
case APP_RUN:
app.Update();
break;

case APP_STOP:
// do options
break;

case APP_EXIT:
PostQuitMessage(0);
break;

.....
}

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

I hope that helped.

- Eddie

C++

All Answers


Answers by Expert:


Ask Experts

Volunteer


Eddie

Expertise

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 ExpertRating.com. I also know a good deal about graphics via OpenGL, and GUIs.

Experience

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.

©2016 About.com. All rights reserved.