• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 504
  • Last Modified:

Sports Simulation

I am creating a sports textual/statistical simulation.  I would like to make the program output its text to a windown instead of a dos prompt.  I am very new at windows programming and know little about creating win apps.

All I would need is a window that has a text box in the middle for displaying information and one input box for entering commands(as text).  

Of course I will need a more elaborate interface later, but need something simple to start out with.
  • 2
1 Solution
A couple of questions first. Are you using MS Dev. Studio (Visual C++). I assume you are.
Next, there are 2 ways to write Windows apps. The best, most popular is MFC (microsoft foundation class). This uses C++ ideas, although you don't need to know much C++ to use it.
The other is using the SDK (software developer kit). This is a C approach and a bit more longwinded. It gives you a bit more control. I'll explain the MFC route for you.
Visual C++ comes with Application Wizards. These create a basic structure for you. They compile and run straight away so theyre a good place to start.

Run up Visual C++
File...New...Projects and select MFC AppWizard (EXE). Give a project name and path too.
From the options choose Dialog based and get rid of everything else (choose none if possible, or deselect the tick boxes).
Select Yes to generate comments and use the MFC lib as a shared DLL.
Hit finish and compile this. You should have a basic window appear.
It should show a window with 'TO DO :Place controls here' or something like that.

We now have a dialog window, which we can paste onto.
On the right window of DevStudio, select the Resource tab and edit the dialog created by the wizard (called something like IDD_project_DIALOG)
From the controls toolbar, paste 2 editboxes into the dialog
Right click...Properties on them and note or edit the names of these controls (e.g IDC_EDIT1 and IDC_EDIT2);
Add a button and get it's name too (e.g IDC_BUTTON1)

Right click on the first text edit box and select ClassWizard. This tool allows us to put code into special 'pockets' for events.
Select the member variables tab. We're going to make this edit box a member variable of the class we're in. So from any code within this class, we can talk to the edit box.
Double click on IDC_EDIT1
choose a name for the member variable, eg m_edit1
Do the same for m_edit2. Click OK

Right click on the new button and select ClassWizard.
Select the message maps tab.
The highlight the IDC_BUTTON1. Select BN_CLICKED. We will now add code for when the button is pressed.
do 'Add Function' (any name for this will do,
then 'Edit Code'. We now see the code for this action. It's empty.
From here we can access the new member variables we added.
Add the following code into the function:
void CAbcDlg::OnButton1()
      // TODO: Add your control notification handler code here
      m_edit2 = "hello " + m_edit1;
        // whatever code you want, function calls, etc.
UpdateData(TRUE) gets the latest text from the windows.
then set whatever text you want out (m_edit2 = .....)
We also use the text from m_edit1 (...+ m_edit1;)
UpdateData(FALSE) sets the altered text in the window so we see it.

Thats it! A basic text in-out for the MFC beginner.

Any problems or if you want the project I just wrote, email me.

nexguyAuthor Commented:
Thankyou very much.  I will try this out and get back to you.  If you want to know more about what I am doing, I asked a related question in the C++ area.

nexguyAuthor Commented:
I have your program running and it is almost exactly what I need.  I have a few more modifications I would like to make(many, but a few at a time)

My window has two edit boxes and three buttons.

The top left is one large edit box to display text(edit2).
The bottom left is a smaller flat edit box designed for entering text one line at a time(edit1).
There is an "Enter Button" that retrieves the text that is in edit1 and puts it into the variable m_edit1(i believe).
The other two buttons are the ok and cancel button.

What I would like is to be able to enter text in edit1 and use the "enter key" instead of the enter button to put the text in the m_edit1 variable.  From there I will decide what to print out in the edit2 box according to the simulation.

edit2 box should accept no input, it is strictly to display commands and the simulation output.

I was reading about the CEdit class.  Why am I using Update Data() instead of the GetLine() function from CEdit?  How would I use GetLine() if I should?  

I also would like edit2(the output window) to be a multi-line edit window so that I may put multiple lines of text into it.  I would like to display menus and statistics in the window,which would take up the whole window.  Then clear out the window when I need to display a different menu.

Also, for this type of program, I do not think I need an "OK" button, only an "Exit' button.  How could I modify the Cancel button to be an Exit button?  Do I need to only make the "Cancel" button read "Exit"?

When the program starts, a menu will appear in the edit2 box.  From there you can enter commands in the edit1 box and press the enter key to input the commands(instead of the "enter button")

Thankyou very much for you help.  I have learned more in the last few days about MFC than in the last year.
                            Chris Blue
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Hire Technology Freelancers with Gigs

Work with 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.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now