//File 3 of 4 - WinMain() file - menus.cpp
#include <afxwin.h> // MFC application framework
#include <strstream> // string stream
#include <iomanip> // I/O manipulators
#include "menu_ids.h" // application message ID symbols
using namespace std; //need for 2003. NET
#include "CGermMFCMenu.h" //CMenu class
//----------------------------------------------------------------------------------------------------------------------------
// Scope resolves to CGermMFCMenu Declared in First File
//Define CGermMFCMenu constructor
CGermMFCMenu::CGermMFCMenu() // construct window
: MFCOutputString( m_szText, TEXT_SIZE ) // initialize ostrstream object
{
// Window Caption and Label. Note: "Calculate" is the name of the menu object from the .rc file
Create( NULL, "C. Germany 2004 - MFC Menu Example", WS_OVERLAPPEDWINDOW,
CRect( 0, 0, 300, 200 ), NULL, "Calculate" );
// Use the pointers to CStatic declared previously to create 2 static text
// boxes on the heap (free store) and write to their labels and captions.
m_pWindowText1 = new CStatic; // create a static text control box
m_pWindowText1->Create("Subcontract programming fees and hourly rates.\nC. Germany 2004", //text to display
WS_CHILD | WS_VISIBLE | WS_BORDER | SS_CENTER, //window styles
CRect( 70, 60, 210, 130 ), // window coordinates
this ); //window to draw text in
m_pWindowText2 = new CStatic; // create a static text control box
m_pWindowText2->Create("Programming, rated by hour per programmer. Pick a language!", //text to display
WS_CHILD | WS_VISIBLE | SS_CENTER, //window styles
CRect(22,10,270,50), // window coordinates
this ); //window to draw text in
//Initialize all variables to null
m_nJava = m_nVisualBasic = 0;
m_nCPlusPlus = m_nPHP = 0;
m_dTotal = 0.0;
} // close CGermMFCMenu constructor defnition
//----------------------------------------------------------------------------------------------------------------------------
// count each type of item ordered, compute total bill
void CGermMFCMenu::tally( int & nCount, double dAmount )
{
nCount++;
m_dTotal += dAmount;
}
//----------------------------------------------------------------------------------------------------------------------------
//afx_msg precedes each message handler function. We are setting up
//functions that, after they are called, will "listen" for messages.
afx_msg void CGermMFCMenu::OnExit()
{
SendMessage( WM_CLOSE );
}
//----------------------------------------------------------------------------------------------------------------------------
afx_msg void CGermMFCMenu::OnDoCalculate(UINT nCalculate)
{
switch (nCalculate)
{
case IDM_Java:
tally( m_nJava, 50.75 );
break;
case IDM_VisualBasic:
tally( m_nVisualBasic, 45.25 );
break;
case IDM_CPlusPlus:
tally( m_nCPlusPlus, 50.95 );
break;
case IDM_PHP:
tally( m_nPHP, 45.10 );
break;
}
}
//----------------------------------------------------------------------------------------------------------------------------
afx_msg void CGermMFCMenu::OnShowTotal()
{
MFCOutputString.seekp( 0 ); // reset output string
MFCOutputString << setprecision( 2 )
<< setiosflags( ios::fixed | ios::showpoint )
<< " $" << m_dTotal << ends; // stopper
// display new dialog box with output string
MessageBox( m_szText, "Your total project cost per hour by number and type of programmers is:" );
m_dTotal = 0.0;
}
//----------------------------------------------------------------------------------------------------------------------------
afx_msg void CGermMFCMenu::OnClearTotal()
{
m_dTotal = 0.0;
MessageBox( " $0.00", "Cleared Order" );
}
//----------------------------------------------------------------------------------------------------------------------------
afx_msg void CGermMFCMenu::LaunchAdventure()
{
system("AdventureGame9.exe");
}
//----------------------------------------------------------------------------------------------------------------------------
afx_msg void CGermMFCMenu::LaunchHangMan()
{
system("HangMan.exe");
}
//----------------------------------------------------------------------------------------------------------------------------
// Begin MessageMap is sort of like adding an itemListener() in Java...
// Open Message Map Tags, tells compiler which function to call when a message is received.
BEGIN_MESSAGE_MAP( CGermMFCMenu, CFrameWnd )
ON_COMMAND( IDM_EXIT, OnExit )
ON_COMMAND_RANGE(IDM_Java, IDM_PHP, OnDoCalculate)
ON_COMMAND( IDM_SHOW_TOTAL, OnShowTotal )
ON_COMMAND( IDM_CLEAR_TOTAL, OnClearTotal )
ON_COMMAND( IDM_ADVENTURE_GAME, LaunchAdventure )
ON_COMMAND( IDM_HANG_MAN, LaunchHangMan )
END_MESSAGE_MAP()
//----------------------------------------------------------------------------------------------------------------------------
// Below, CMenusApp, deriving from the mandatory CWinApp, acts like main() in a
// console program. It creates a new CGermMFCMenu on the heap, which itself derives from
// the mandatory CFrameWnd. Remember that CGermMFCMenu was declared in the 1st file.
class MakeCGermMFCMenu : public CWinApp {
public:
BOOL InitInstance() // called by CWinApp::CWinApp
{
m_pMainWnd = new CGermMFCMenu; // create window
m_pMainWnd->ShowWindow( m_nCmdShow ); // make it visible
m_pMainWnd->UpdateWindow(); // force refresh
return true; // report success
}
} // Notice there's no semicolon here at end of class specification
MakeCGermMFCMenu; // calls CWinApp::CWinApp constructor
//---------------------------------------------------------------------------------------------------------------------------- |