Sports Simulation

Posted on 1998-10-07
Last Modified: 2013-11-20
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.
Question by:nexguy
  • 2

Accepted Solution

cramer091498 earned 100 total points
Comment Utility
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.


Author Comment

Comment Utility
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.

Author Comment

Comment Utility
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

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Introduction: Dynamic window placements and drawing on a form, simple usage of windows registry as a storage place for information. Continuing from the first article about sudoku.  There we have designed the application and put a lot of user int…
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 gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor ( If you're looking for how to monitor bandwidth using netflow or packet s…

771 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now