Go Premium for a chance to win a PS4. Enter to Win


Sports Simulation

Posted on 1998-10-07
Medium Priority
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 400 total points
ID: 1323081
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

ID: 1323082
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

ID: 1323083
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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction: Displaying information on the statusbar.   Continuing from the third article about sudoku.   Open the project in visual studio. Status bar – let’s display the timestamp there.  We need to get the timestamp from the document s…
Introduction: Finishing the grid – keyboard support for arrow keys to manoeuvre, entering the numbers.  The PreTranslateMessage function is to be used to intercept and respond to keyboard events. Continuing from the fourth article about sudoku. …
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 lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
Suggested Courses

972 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