home *** CD-ROM | disk | FTP | other *** search
/ The Best of Windows 95.com 1996 September / WIN95_09963.iso / strategy / hangman.zip / Hangman32Dlg.cpp < prev    next >
C/C++ Source or Header  |  1996-01-16  |  25KB  |  742 lines

  1. // Hangman32Dlg.cpp : implementation file
  2. //
  3.  
  4. #include "stdafx.h"
  5. #include "Hangman32.h"
  6. #include "Hangman32Dlg.h"
  7. #include "GenericDlg.h"
  8. #include "HintDlg.h"
  9.  
  10. #ifdef _DEBUG
  11. #define new DEBUG_NEW
  12. #undef THIS_FILE
  13. static char THIS_FILE[] = __FILE__;
  14. #endif
  15.  
  16. CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
  17. {
  18.     //{{AFX_DATA_INIT(CAboutDlg)
  19.     //}}AFX_DATA_INIT
  20.  
  21. }
  22.  
  23. void CAboutDlg::DoDataExchange(CDataExchange* pDX)
  24. {
  25.     CDialog::DoDataExchange(pDX);
  26.     //{{AFX_DATA_MAP(CAboutDlg)
  27.     //}}AFX_DATA_MAP
  28. }
  29.  
  30. BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
  31.     //{{AFX_MSG_MAP(CAboutDlg)
  32.         // No message handlers
  33.     //}}AFX_MSG_MAP
  34. END_MESSAGE_MAP()
  35.  
  36. /////////////////////////////////////////////////////////////////////////////
  37. // CHangman32Dlg dialog
  38.  
  39. CHangman32Dlg::CHangman32Dlg(CWnd* pParent /*=NULL*/)
  40.     : CDialog(CHangman32Dlg::IDD, pParent)
  41. {
  42.     //{{AFX_DATA_INIT(CHangman32Dlg)
  43.     //}}AFX_DATA_INIT
  44.     // Note that LoadIcon does not require a subsequent DestroyIcon in Win32
  45.     m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
  46. }
  47.  
  48. void CHangman32Dlg::DoDataExchange(CDataExchange* pDX)
  49. {
  50.     CDialog::DoDataExchange(pDX);
  51.     //{{AFX_DATA_MAP(CHangman32Dlg)
  52.     DDX_Control(pDX, IDC_PICTURE, m_cntrlPic);
  53.     DDX_Control(pDX, IDC_BUTTON26, m_btn26Z);
  54.     DDX_Control(pDX, IDC_BUTTON25, m_btn25Y);
  55.     DDX_Control(pDX, IDC_BUTTON24, m_btn24X);
  56.     DDX_Control(pDX, IDC_BUTTON23, m_btn23W);
  57.     DDX_Control(pDX, IDC_BUTTON22, m_btn22V);
  58.     DDX_Control(pDX, IDC_BUTTON21, m_btn21U);
  59.     DDX_Control(pDX, IDC_BUTTON20, m_btn20T);
  60.     DDX_Control(pDX, IDC_BUTTON19, m_btn19S);
  61.     DDX_Control(pDX, IDC_BUTTON18, m_btn18R);
  62.     DDX_Control(pDX, IDC_BUTTON17, m_btn17Q);
  63.     DDX_Control(pDX, IDC_BUTTON16, m_btn16P);
  64.     DDX_Control(pDX, IDC_BUTTON15, m_btn15O);
  65.     DDX_Control(pDX, IDC_BUTTON14, m_btn14N);
  66.     DDX_Control(pDX, IDC_BUTTON13, m_btn13M);
  67.     DDX_Control(pDX, IDC_BUTTON12, m_btn12L);
  68.     DDX_Control(pDX, IDC_BUTTON11, m_btn11K);
  69.     DDX_Control(pDX, IDC_BUTTON10, m_btn10J);
  70.     DDX_Control(pDX, IDC_BUTTON9, m_btn9I);
  71.     DDX_Control(pDX, IDC_BUTTON8, m_btn8H);
  72.     DDX_Control(pDX, IDC_BUTTON7, m_btn7G);
  73.     DDX_Control(pDX, IDC_BUTTON6, m_btn6F);
  74.     DDX_Control(pDX, IDC_BUTTON5, m_btn5E);
  75.     DDX_Control(pDX, IDC_BUTTON4, m_btn4D);
  76.     DDX_Control(pDX, IDC_BUTTON3, m_btn3C);
  77.     DDX_Control(pDX, IDC_BUTTON2, m_btn2B);
  78.     DDX_Control(pDX, IDC_BUTTON1, m_btn1A);
  79.     //}}AFX_DATA_MAP
  80. }
  81.  
  82. BEGIN_MESSAGE_MAP(CHangman32Dlg, CDialog)
  83.     //{{AFX_MSG_MAP(CHangman32Dlg)
  84.     ON_WM_SYSCOMMAND()
  85.     ON_WM_DESTROY()
  86.     ON_WM_PAINT()
  87.     ON_WM_QUERYDRAGICON()
  88.     ON_BN_CLICKED(IDC_BUTTON1, OnButton1_A)
  89.     ON_BN_CLICKED(IDC_BUTTON2, OnButton2_B)
  90.     ON_BN_CLICKED(IDC_BUTTON3, OnButton3_C)
  91.     ON_BN_CLICKED(IDC_BUTTON4, OnButton4_D)
  92.     ON_BN_CLICKED(IDC_BUTTON5, OnButton5_E)
  93.     ON_BN_CLICKED(IDC_BUTTON6, OnButton6_F)
  94.     ON_BN_CLICKED(IDC_BUTTON7, OnButton7_G)
  95.     ON_BN_CLICKED(IDC_BUTTON8, OnButton8_H)
  96.     ON_BN_CLICKED(IDC_BUTTON9, OnButton9_I)
  97.     ON_BN_CLICKED(IDC_BUTTON10, OnButton10_J)
  98.     ON_BN_CLICKED(IDC_BUTTON11, OnButton11_K)
  99.     ON_BN_CLICKED(IDC_BUTTON12, OnButton12_L)
  100.     ON_BN_CLICKED(IDC_BUTTON13, OnButton13_M)
  101.     ON_BN_CLICKED(IDC_BUTTON14, OnButton14_N)
  102.     ON_BN_CLICKED(IDC_BUTTON15, OnButton15_O)
  103.     ON_BN_CLICKED(IDC_BUTTON16, OnButton16_P)
  104.     ON_BN_CLICKED(IDC_BUTTON17, OnButton17_Q)
  105.     ON_BN_CLICKED(IDC_BUTTON18, OnButton18_R)
  106.     ON_BN_CLICKED(IDC_BUTTON19, OnButton19_S)
  107.     ON_BN_CLICKED(IDC_BUTTON20, OnButton20_T)
  108.     ON_BN_CLICKED(IDC_BUTTON21, OnButton21_U)
  109.     ON_BN_CLICKED(IDC_BUTTON22, OnButton22_V)
  110.     ON_BN_CLICKED(IDC_BUTTON23, OnButton23_W)
  111.     ON_BN_CLICKED(IDC_BUTTON24, OnButton24_X)
  112.     ON_BN_CLICKED(IDC_BUTTON25, OnButton25_Y)
  113.     ON_BN_CLICKED(IDC_BUTTON26, OnButton26_Z)
  114.     ON_COMMAND(ID_GAME_HINT, OnGameHint)
  115.     ON_COMMAND(ID_GAME_NEW, OnGameNew)
  116.     ON_COMMAND(ID_HELP_ABOUTHANGMAN32, OnHelpAbouthangman32)
  117.     //}}AFX_MSG_MAP
  118. END_MESSAGE_MAP()
  119.  
  120. /////////////////////////////////////////////////////////////////////////////
  121. // CHangman32Dlg message handlers
  122.  
  123. BOOL CHangman32Dlg::OnInitDialog()
  124. {
  125.     CDialog::OnInitDialog();
  126.  
  127.     // Add "About..." menu item to system menu.
  128.     // IDM_ABOUTBOX must be in the system command range.
  129.     ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
  130.     ASSERT(IDM_ABOUTBOX < 0xF000);
  131.  
  132.     CMenu* pSysMenu = GetSystemMenu(FALSE);
  133.     CString strAboutMenu;
  134.     strAboutMenu.LoadString(IDS_ABOUTBOX);
  135.     if (!strAboutMenu.IsEmpty())
  136.     {
  137.         pSysMenu->AppendMenu(MF_SEPARATOR);
  138.         pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
  139.     }
  140.  
  141.     // Set the icon for this dialog.  The framework does this automatically
  142.     //  when the application's main window is not a dialog
  143.     SetIcon(m_hIcon, TRUE);            // Set big icon
  144.     SetIcon(m_hIcon, FALSE);        // Set small icon
  145.  
  146.     // TODO: Add extra initialization here
  147.     ((CHangman32App *)AfxGetApp())->m_hwndDialog = m_hWnd;
  148.     if( m_Hangman.LoadDictionary() == FALSE )
  149.         m_Hangman.LoadErrorDictionary();
  150.     m_Hangman.LoadNewWord();
  151.     RefreshScoreDisplay();
  152.     DrawPic();
  153.  
  154.     return FALSE;  // return TRUE  unless you set the focus to a control
  155. }
  156.  
  157. void CHangman32Dlg::OnSysCommand(UINT nID, LPARAM lParam)
  158. {
  159.     if ((nID & 0xFFF0) == IDM_ABOUTBOX)
  160.     {
  161.         CAboutDlg dlgAbout;
  162.         ((CHangman32App *)AfxGetApp())->m_doAccel = FALSE;    // Block key presses
  163.         dlgAbout.DoModal();
  164.         ((CHangman32App *)AfxGetApp())->m_doAccel = TRUE;    // Allow key presses
  165.     }
  166.     else
  167.     {
  168.         CDialog::OnSysCommand(nID, lParam);
  169.     }
  170. }
  171.  
  172. void CHangman32Dlg::OnDestroy()
  173. {
  174.     WinHelp(0L, HELP_QUIT);
  175.     CDialog::OnDestroy();
  176.     ((CHangman32App *)AfxGetApp())->m_hwndDialog = NULL;
  177.     ((CHangman32App *)AfxGetApp())->m_doAccel = FALSE;    // Block key presses
  178. }
  179.  
  180. // If you add a minimize button to your dialog, you will need the code below
  181. //  to draw the icon.  For MFC applications using the document/view model,
  182. //  this is automatically done for you by the framework.
  183. void CHangman32Dlg::OnPaint() 
  184. {
  185.     if (IsIconic())
  186.     {
  187.         CPaintDC dc(this); // device context for painting
  188.  
  189.         SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);
  190.  
  191.         // Center icon in client rectangle
  192.         int cxIcon = GetSystemMetrics(SM_CXICON);
  193.         int cyIcon = GetSystemMetrics(SM_CYICON);
  194.         CRect rect;
  195.         GetClientRect(&rect);
  196.         int x = (rect.Width() - cxIcon + 1) / 2;
  197.         int y = (rect.Height() - cyIcon + 1) / 2;
  198.  
  199.         // Draw the icon
  200.         dc.DrawIcon(x, y, m_hIcon);
  201.     }
  202.     else
  203.     {
  204.         CDialog::OnPaint();
  205.     }
  206. }
  207.  
  208. // The system calls this to obtain the cursor to display while the user drags
  209. //  the minimized window.
  210. HCURSOR CHangman32Dlg::OnQueryDragIcon()
  211. {
  212.     return (HCURSOR) m_hIcon;
  213. }
  214.  
  215. // Handle the button presses
  216. void CHangman32Dlg::OnButton1_A() 
  217. {
  218.     if( m_btn1A.IsWindowVisible() )                // If visible handle button press  
  219.     {
  220.         m_btn1A.ShowWindow(SW_HIDE);            // Make it disappear
  221.         ProcessButtonPress('A');                // Send in the actual letter
  222.     }
  223.     else
  224.         MessageBeep( MB_ICONEXCLAMATION );        //Else user pressed letter for button
  225. }                                                //that has already been processed
  226.  
  227. void CHangman32Dlg::OnButton2_B() 
  228. {
  229.     if( m_btn2B.IsWindowVisible() )                // If visible handle button press
  230.     {
  231.         m_btn2B.ShowWindow(SW_HIDE);            // Make it disappear
  232.         ProcessButtonPress('B');                // Send in the actual letter
  233.     }
  234.     else
  235.         MessageBeep( MB_ICONEXCLAMATION );        //Else user pressed letter for button
  236. }                                                //that has already been processed
  237.  
  238. void CHangman32Dlg::OnButton3_C() 
  239. {
  240.     if( m_btn3C.IsWindowVisible() )                // If visible handle button press
  241.     {
  242.         m_btn3C.ShowWindow(SW_HIDE);            // Make it disappear
  243.         ProcessButtonPress('C');                // Send in the actual letter
  244.     }
  245.     else
  246.         MessageBeep( MB_ICONEXCLAMATION );        //Else user pressed letter for button            
  247. }                                                //that has already been processed
  248.  
  249. void CHangman32Dlg::OnButton4_D() 
  250. {
  251.     if( m_btn4D.IsWindowVisible() )                // If visible handle button press
  252.     {
  253.         m_btn4D.ShowWindow(SW_HIDE);            // Make it disappear
  254.         ProcessButtonPress('D');                // Send in the actual letter
  255.     }
  256.     else
  257.         MessageBeep( MB_ICONEXCLAMATION );        //Else user pressed letter for button
  258. }                                                //that has already been processed
  259.  
  260. void CHangman32Dlg::OnButton5_E() 
  261. {
  262.     if( m_btn5E.IsWindowVisible() )                // If visible handle button press
  263.     {
  264.         m_btn5E.ShowWindow(SW_HIDE);            // Make it disappear
  265.         ProcessButtonPress('E');                // Send in the actual letter
  266.     }
  267.     else
  268.         MessageBeep( MB_ICONEXCLAMATION );        //Else user pressed letter for button        
  269. }                                                //that has already been processed
  270.  
  271. void CHangman32Dlg::OnButton6_F() 
  272. {
  273.     if( m_btn6F.IsWindowVisible() )                // If visible handle button press
  274.     {
  275.         m_btn6F.ShowWindow(SW_HIDE);            // Make it disappear
  276.         ProcessButtonPress('F');                // Send in the actual letter
  277.     }
  278.     else
  279.         MessageBeep( MB_ICONEXCLAMATION );        //Else user pressed letter for button            
  280. }                                                //that has already been processed
  281.  
  282. void CHangman32Dlg::OnButton7_G() 
  283. {    
  284.     if( m_btn7G.IsWindowVisible() )                // If visible handle button press
  285.     {
  286.         m_btn7G.ShowWindow(SW_HIDE);            // Make it disappear
  287.         ProcessButtonPress('G');                // Send in the actual letter
  288.     }
  289.     else
  290.         MessageBeep( MB_ICONEXCLAMATION );        //Else user pressed letter for button        
  291. }                                                //that has already been processed
  292.  
  293. void CHangman32Dlg::OnButton8_H() 
  294. {    
  295.     if( m_btn8H.IsWindowVisible() )                // If visible handle button press
  296.     {
  297.         m_btn8H.ShowWindow(SW_HIDE);            // Make it disappear
  298.         ProcessButtonPress('H');                // Send in the actual letter
  299.     }
  300.     else
  301.         MessageBeep( MB_ICONEXCLAMATION );        //Else user pressed letter for button        
  302. }                                                //that has already been processed
  303.  
  304. void CHangman32Dlg::OnButton9_I() 
  305. {    
  306.     if( m_btn9I.IsWindowVisible() )                // If visible handle button press
  307.     {
  308.         m_btn9I.ShowWindow(SW_HIDE);            // Make it disappear
  309.         ProcessButtonPress('I');                // Send in the actual letter
  310.     }
  311.     else
  312.         MessageBeep( MB_ICONEXCLAMATION );        //Else user pressed letter for button        
  313. }                                                //that has already been processed
  314.  
  315. void CHangman32Dlg::OnButton10_J() 
  316. {    
  317.     if( m_btn10J.IsWindowVisible() )            // If visible handle button press
  318.     {
  319.         m_btn10J.ShowWindow(SW_HIDE);            // Make it disappear
  320.         ProcessButtonPress('J');                // Send in the actual letter
  321.     }
  322.     else
  323.         MessageBeep( MB_ICONEXCLAMATION );        //Else user pressed letter for button        
  324. }                                                //that has already been processed
  325.  
  326. void CHangman32Dlg::OnButton11_K() 
  327. {
  328.     if( m_btn11K.IsWindowVisible() )            // If visible handle button press
  329.     {
  330.         m_btn11K.ShowWindow(SW_HIDE);            // Make it disappear
  331.         ProcessButtonPress('K');                // Send in the actual letter
  332.     }
  333.     else
  334.         MessageBeep( MB_ICONEXCLAMATION );        //Else user pressed letter for button        
  335. }                                                //that has already been processed
  336.  
  337. void CHangman32Dlg::OnButton12_L() 
  338. {
  339.     if( m_btn12L.IsWindowVisible() )            // If visible handle button press
  340.     {
  341.         m_btn12L.ShowWindow(SW_HIDE);            // Make it disappear
  342.         ProcessButtonPress('L');                // Send in the actual letter
  343.     }
  344.     else
  345.         MessageBeep( MB_ICONEXCLAMATION );        //Else user pressed letter for button        
  346. }                                                //that has already been processed
  347.  
  348. void CHangman32Dlg::OnButton13_M() 
  349. {    
  350.     if( m_btn13M.IsWindowVisible() )            // If visible handle button press
  351.     {
  352.         m_btn13M.ShowWindow(SW_HIDE);            // Make it disappear
  353.         ProcessButtonPress('M');                // Send in the actual letter
  354.     }
  355.     else
  356.         MessageBeep( MB_ICONEXCLAMATION );        //Else user pressed letter for button        
  357. }                                                //that has already been processed
  358.  
  359. void CHangman32Dlg::OnButton14_N() 
  360. {
  361.     if( m_btn14N.IsWindowVisible() )            // If visible handle button press
  362.     {
  363.         m_btn14N.ShowWindow(SW_HIDE);            // Make it disappear
  364.         ProcessButtonPress('N');                // Send in the actual letter
  365.     }
  366.     else
  367.         MessageBeep( MB_ICONEXCLAMATION );        //Else user pressed letter for button        
  368. }                                                //that has already been processed
  369.  
  370. void CHangman32Dlg::OnButton15_O() 
  371. {
  372.     if( m_btn15O.IsWindowVisible() )            // If visible handle button press
  373.     {
  374.         m_btn15O.ShowWindow(SW_HIDE);            // Make it disappear
  375.         ProcessButtonPress('O');                // Send in the actual letter
  376.     }
  377.     else
  378.         MessageBeep( MB_ICONEXCLAMATION );        //Else user pressed letter for button        
  379. }                                                //that has already been processed
  380.  
  381. void CHangman32Dlg::OnButton16_P() 
  382. {
  383.     if( m_btn16P.IsWindowVisible() )            // If visible handle button press
  384.     {
  385.         m_btn16P.ShowWindow(SW_HIDE);            // Make it disappear
  386.         ProcessButtonPress('P');                // Send in the actual letter
  387.     }
  388.     else
  389.         MessageBeep( MB_ICONEXCLAMATION );        //Else user pressed letter for button        
  390. }                                                //that has already been processed
  391.  
  392. void CHangman32Dlg::OnButton17_Q() 
  393. {
  394.     if( m_btn17Q.IsWindowVisible() )            // If visible handle button press
  395.     {
  396.         m_btn17Q.ShowWindow(SW_HIDE);            // Make it disappear
  397.         ProcessButtonPress('Q');                // Send in the actual letter
  398.     }
  399.     else
  400.         MessageBeep( MB_ICONEXCLAMATION );        //Else user pressed letter for button        
  401. }                                                //that has already been processed
  402.  
  403. void CHangman32Dlg::OnButton18_R() 
  404. {    
  405.     if( m_btn18R.IsWindowVisible() )            // If visible handle button press
  406.     {
  407.         m_btn18R.ShowWindow(SW_HIDE);            // Make it disappear
  408.         ProcessButtonPress('R');                // Send in the actual letter
  409.     }
  410.     else
  411.         MessageBeep( MB_ICONEXCLAMATION );        //Else user pressed letter for button        
  412. }                                                //that has already been processed
  413.  
  414. void CHangman32Dlg::OnButton19_S() 
  415. {
  416.     if( m_btn19S.IsWindowVisible() )            // If visible handle button press
  417.     {
  418.         m_btn19S.ShowWindow(SW_HIDE);            // Make it disappear
  419.         ProcessButtonPress('S');                // Send in the actual letter
  420.     }
  421.     else
  422.         MessageBeep( MB_ICONEXCLAMATION );        //Else user pressed letter for button        
  423. }                                                //that has already been processed
  424.  
  425. void CHangman32Dlg::OnButton20_T() 
  426. {
  427.     if( m_btn20T.IsWindowVisible() )            // If visible handle button press
  428.     {
  429.         m_btn20T.ShowWindow(SW_HIDE);            // Make it disappear
  430.         ProcessButtonPress('T');                // Send in the actual letter
  431.     }
  432.     else
  433.         MessageBeep( MB_ICONEXCLAMATION );        //Else user pressed letter for button        
  434. }                                                //that has already been processed
  435.  
  436. void CHangman32Dlg::OnButton21_U() 
  437. {
  438.     if( m_btn21U.IsWindowVisible() )            // If visible handle button press
  439.     {
  440.         m_btn21U.ShowWindow(SW_HIDE);            // Make it disappear
  441.         ProcessButtonPress('U');                // Send in the actual letter
  442.     }
  443.     else
  444.         MessageBeep( MB_ICONEXCLAMATION );        //Else user pressed letter for button            
  445. }                                                //that has already been processed
  446.  
  447. void CHangman32Dlg::OnButton22_V() 
  448. {
  449.     if( m_btn22V.IsWindowVisible() )            // If visible handle button press
  450.     {
  451.         m_btn22V.ShowWindow(SW_HIDE);            // Make it disappear
  452.         ProcessButtonPress('V');                // Send in the actual letter
  453.     }
  454.     else
  455.         MessageBeep( MB_ICONEXCLAMATION );        //Else user pressed letter for button            
  456. }                                                //that has already been processed
  457.  
  458. void CHangman32Dlg::OnButton23_W() 
  459. {
  460.     if( m_btn23W.IsWindowVisible() )            // If visible handle button press
  461.     {
  462.         m_btn23W.ShowWindow(SW_HIDE);            // Make it disappear
  463.         ProcessButtonPress('W');                // Send in the actual letter
  464.     }
  465.     else
  466.         MessageBeep( MB_ICONEXCLAMATION );        //Else user pressed letter for button        
  467. }                                                //that has already been processed
  468.  
  469. void CHangman32Dlg::OnButton24_X() 
  470. {    
  471.     if( m_btn24X.IsWindowVisible() )            // If visible handle button press
  472.     {
  473.         m_btn24X.ShowWindow(SW_HIDE);            // Make it disappear
  474.         ProcessButtonPress('X');                // Send in the actual letter
  475.     }
  476.     else
  477.         MessageBeep( MB_ICONEXCLAMATION );        //Else user pressed letter for button        
  478. }                                                //that has already been processed
  479.  
  480. void CHangman32Dlg::OnButton25_Y() 
  481. {
  482.     if( m_btn25Y.IsWindowVisible() )            // If visible handle button press
  483.     {
  484.         m_btn25Y.ShowWindow(SW_HIDE);            // Make it disappear
  485.         ProcessButtonPress('Y');                // Send in the actual letter
  486.     }
  487.     else
  488.         MessageBeep( MB_ICONEXCLAMATION );        //Else user pressed letter for button        
  489. }                                                //that has already been processed
  490.  
  491. void CHangman32Dlg::OnButton26_Z() 
  492. {    
  493.     if( m_btn26Z.IsWindowVisible() )            // If visible handle button press
  494.     {    
  495.         m_btn26Z.ShowWindow(SW_HIDE);            // Make it disappear
  496.         ProcessButtonPress('Z');                // Send in the actual letter
  497.     }
  498.     else
  499.         MessageBeep( MB_ICONEXCLAMATION );        //Else user pressed letter for button        
  500. }                                                //that has already been processed
  501.  
  502. void CHangman32Dlg::ProcessButtonPress(char Letter)
  503. {
  504.     BOOL boolean;
  505.     char Str[30];
  506.     UINT OldGuessRemaining;
  507.  
  508.     OldGuessRemaining = m_Hangman.GetGuessRemain();    // Get # of guess remaining
  509.     boolean = m_Hangman.CheckLetter(Letter);        // Check the letter
  510.     if(boolean)
  511.         SetDlgItemText( IDC_GUESS, m_Hangman.GetCurrentGuess() );  // If true update
  512.  
  513.     _itoa( m_Hangman.GetGuessRemain(), Str, 10 );    // Update GuessRemain in dialog
  514.     SetDlgItemText( IDC_GUESS_REMAINING, Str );
  515.  
  516.     if( OldGuessRemaining != m_Hangman.GetGuessRemain() )
  517.         DrawPic();                                    // Only draw picture if have to
  518.  
  519.     if( m_Hangman.GetGuessRemain() == 0 )
  520.         DoLoser();                                    // We have a loser do processing
  521.     else
  522.     if( m_Hangman.CheckWordCompleted() )
  523.         DoWinner();                                    // We have a winner do processing
  524. }
  525.  
  526. void CHangman32Dlg::ResetButtons()
  527. {
  528.     // Reset all the buttons to visible
  529.     // Also make sure no button is a default button
  530.     m_btn1A.SetButtonStyle( m_btn1A.GetButtonStyle() & ~BS_DEFPUSHBUTTON, FALSE );
  531.     m_btn1A.ShowWindow(SW_SHOW);    
  532.     m_btn2B.SetButtonStyle( m_btn2B.GetButtonStyle() & ~BS_DEFPUSHBUTTON, FALSE );
  533.     m_btn2B.ShowWindow(SW_SHOW);
  534.     m_btn3C.SetButtonStyle( m_btn3C.GetButtonStyle() & ~BS_DEFPUSHBUTTON, FALSE );
  535.     m_btn3C.ShowWindow(SW_SHOW);
  536.     m_btn4D.SetButtonStyle( m_btn4D.GetButtonStyle() & ~BS_DEFPUSHBUTTON, FALSE );
  537.     m_btn4D.ShowWindow(SW_SHOW);
  538.     m_btn5E.SetButtonStyle( m_btn5E.GetButtonStyle() & ~BS_DEFPUSHBUTTON, FALSE );
  539.     m_btn5E.ShowWindow(SW_SHOW);
  540.     m_btn6F.SetButtonStyle( m_btn6F.GetButtonStyle() & ~BS_DEFPUSHBUTTON, FALSE );
  541.     m_btn6F.ShowWindow(SW_SHOW);
  542.     m_btn7G.SetButtonStyle( m_btn7G.GetButtonStyle() & ~BS_DEFPUSHBUTTON, FALSE );
  543.     m_btn7G.ShowWindow(SW_SHOW);
  544.     m_btn8H.SetButtonStyle( m_btn8H.GetButtonStyle() & ~BS_DEFPUSHBUTTON, FALSE );
  545.     m_btn8H.ShowWindow(SW_SHOW);
  546.     m_btn9I.SetButtonStyle( m_btn9I.GetButtonStyle() & ~BS_DEFPUSHBUTTON, FALSE );
  547.     m_btn9I.ShowWindow(SW_SHOW);
  548.     m_btn10J.SetButtonStyle( m_btn10J.GetButtonStyle() & ~BS_DEFPUSHBUTTON, FALSE );    
  549.     m_btn10J.ShowWindow(SW_SHOW);
  550.     m_btn11K.SetButtonStyle( m_btn11K.GetButtonStyle() & ~BS_DEFPUSHBUTTON, FALSE );     
  551.     m_btn11K.ShowWindow(SW_SHOW);
  552.     m_btn12L.SetButtonStyle( m_btn12L.GetButtonStyle() & ~BS_DEFPUSHBUTTON, FALSE );    
  553.     m_btn12L.ShowWindow(SW_SHOW);
  554.     m_btn13M.SetButtonStyle( m_btn13M.GetButtonStyle() & ~BS_DEFPUSHBUTTON, FALSE );    
  555.     m_btn13M.ShowWindow(SW_SHOW);
  556.     m_btn14N.SetButtonStyle( m_btn14N.GetButtonStyle() & ~BS_DEFPUSHBUTTON, FALSE );    
  557.     m_btn14N.ShowWindow(SW_SHOW);
  558.     m_btn15O.SetButtonStyle( m_btn15O.GetButtonStyle() & ~BS_DEFPUSHBUTTON, FALSE );    
  559.     m_btn15O.ShowWindow(SW_SHOW);
  560.     m_btn16P.SetButtonStyle( m_btn16P.GetButtonStyle() & ~BS_DEFPUSHBUTTON, FALSE );    
  561.     m_btn16P.ShowWindow(SW_SHOW);
  562.     m_btn17Q.SetButtonStyle( m_btn17Q.GetButtonStyle() & ~BS_DEFPUSHBUTTON, FALSE );    
  563.     m_btn17Q.ShowWindow(SW_SHOW);
  564.     m_btn18R.SetButtonStyle( m_btn18R.GetButtonStyle() & ~BS_DEFPUSHBUTTON, FALSE );    
  565.     m_btn18R.ShowWindow(SW_SHOW);
  566.     m_btn19S.SetButtonStyle( m_btn19S.GetButtonStyle() & ~BS_DEFPUSHBUTTON, FALSE );    
  567.     m_btn19S.ShowWindow(SW_SHOW);
  568.     m_btn20T.SetButtonStyle( m_btn20T.GetButtonStyle() & ~BS_DEFPUSHBUTTON, FALSE );    
  569.     m_btn20T.ShowWindow(SW_SHOW);
  570.     m_btn21U.SetButtonStyle( m_btn21U.GetButtonStyle() & ~BS_DEFPUSHBUTTON, FALSE );    
  571.     m_btn21U.ShowWindow(SW_SHOW);
  572.     m_btn22V.SetButtonStyle( m_btn22V.GetButtonStyle() & ~BS_DEFPUSHBUTTON, FALSE );    
  573.     m_btn22V.ShowWindow(SW_SHOW);
  574.     m_btn23W.SetButtonStyle( m_btn23W.GetButtonStyle() & ~BS_DEFPUSHBUTTON, FALSE );    
  575.     m_btn23W.ShowWindow(SW_SHOW);
  576.     m_btn24X.SetButtonStyle( m_btn24X.GetButtonStyle() & ~BS_DEFPUSHBUTTON, FALSE );    
  577.     m_btn24X.ShowWindow(SW_SHOW);
  578.     m_btn25Y.SetButtonStyle( m_btn25Y.GetButtonStyle() & ~BS_DEFPUSHBUTTON, FALSE );    
  579.     m_btn25Y.ShowWindow(SW_SHOW);
  580.     m_btn26Z.SetButtonStyle( m_btn26Z.GetButtonStyle() & ~BS_DEFPUSHBUTTON, FALSE );    
  581.     m_btn26Z.ShowWindow(SW_SHOW);
  582. }
  583.  
  584. void CHangman32Dlg::OnGameHint() 
  585. {
  586.     CHintDlg hintDlg;
  587.     CStringArray strArray;
  588.     CString tmpStr;
  589.     int Index;
  590.  
  591.     strArray.SetSize(10,10);    // Initialize to some size.  Ten is good for now.
  592.     strArray.SetAtGrow(0,"If I were you I'd try the letter ");
  593.     strArray.SetAtGrow(1,"You cheater!  Try the letter ");
  594.     strArray.SetAtGrow(2,"The magic eight ball says to try the letter ");
  595.     strArray.SetAtGrow(3,"Smart money is on the letter ");
  596.     strArray.SetAtGrow(4,"You can't go wrong with the letter ");
  597.     strArray.SetAtGrow(5,"It doesn't take a genius to know to try the letter ");
  598.     strArray.SetAtGrow(6,"Confucius says to try the letter ");
  599.     strArray.SetAtGrow(7,"A wise man would try the letter ");
  600.  
  601.     Index = rand() % 8;        // mod by the number of elements in strArray
  602.     tmpStr   = strArray.GetAt( Index ) + m_Hangman.GetHintLetter() + ".";
  603.     hintDlg.SetQuote(tmpStr);
  604.     ((CHangman32App *)AfxGetApp())->m_doAccel = FALSE;    // Block key presses
  605.     hintDlg.DoModal();
  606.     ((CHangman32App *)AfxGetApp())->m_doAccel = TRUE;    // Allow key presses
  607.  
  608.     m_Hangman.DecrementGuessRemain();    // Subtract two for cheating
  609.     m_Hangman.DecrementGuessRemain();
  610.     DrawPic();                            // Load in proper picture
  611.  
  612.     if( m_Hangman.GetGuessRemain() == 0 )    // Check if we hit zero
  613.     {
  614.         RefreshScoreDisplay();
  615.         DoLoser();
  616.     }
  617.  
  618.     RefreshScoreDisplay();                // Refresh everything
  619. }
  620.  
  621. void CHangman32Dlg::RefreshScoreDisplay()
  622. {
  623.     char tmpStr[30];
  624.     
  625.     // Refresh all the text in the main dialog
  626.     SetDlgItemText( IDC_GUESS, m_Hangman.GetCurrentGuess() );
  627.     _itoa( m_Hangman.GetGamesPlayed(), tmpStr, 10 );
  628.     SetDlgItemText( IDC_GAMES_PLAYED, tmpStr );
  629.     _itoa( m_Hangman.GetGamesWon(), tmpStr, 10 );
  630.     SetDlgItemText( IDC_GAMES_WON, tmpStr );
  631.     _itoa( m_Hangman.GetPercentage(), tmpStr, 10 );
  632.     SetDlgItemText( IDC_PERCENT_WON, tmpStr );    
  633.     _itoa( m_Hangman.GetGuessRemain(), tmpStr, 10 );
  634.     SetDlgItemText( IDC_GUESS_REMAINING, tmpStr );
  635. }
  636.  
  637. void CHangman32Dlg::DoLoser()
  638. {
  639.     CGenericDlg genericDlg;
  640.     CString tmpStr1;
  641.  
  642.     // Display what the word was to the player
  643.     tmpStr1 = "Sorry, the word was " + m_Hangman.GetCurrentWord();
  644.     
  645.     genericDlg.SetQuote( tmpStr1 );
  646.     ((CHangman32App *)AfxGetApp())->m_doAccel = FALSE;    // Block key presses
  647.     genericDlg.DoModal();
  648.     ((CHangman32App *)AfxGetApp())->m_doAccel = TRUE;    // Alllow key presses
  649.  
  650.     // Reset everything and do another round
  651.     ResetButtons();
  652.     m_Hangman.LoadNewWord();
  653.     m_Hangman.IncrementGamesPlayed();
  654.     DrawPic();
  655.     RefreshScoreDisplay();
  656. }
  657.  
  658. void CHangman32Dlg::DoWinner()
  659. {
  660.     CGenericDlg genericDlg;
  661.     CString tmpStr1;
  662.     char tmpStr2[30];
  663.  
  664.     _itoa( m_Hangman.GetTotalGuesses(), tmpStr2, 10 );
  665.  
  666.     // Display message to player
  667.     tmpStr1 =  "Good job!  You won in ";
  668.     tmpStr1 += tmpStr2;
  669.     tmpStr1 += " guesses.";
  670.  
  671.     genericDlg.SetQuote( tmpStr1 );
  672.     ((CHangman32App *)AfxGetApp())->m_doAccel = FALSE;    // Block key presses
  673.     genericDlg.DoModal();
  674.     ((CHangman32App *)AfxGetApp())->m_doAccel = TRUE;    // Allow key presses
  675.  
  676.     // Reset everything and do another round
  677.     ResetButtons();
  678.     m_Hangman.LoadNewWord();
  679.     m_Hangman.IncrementGamesPlayed();
  680.     m_Hangman.IncrementGamesWon();
  681.     DrawPic();
  682.     RefreshScoreDisplay();
  683. }
  684.  
  685. void CHangman32Dlg::OnGameNew() 
  686. {
  687.     // On new game reset all variables as if just started
  688.     m_Hangman.Reset();
  689.     m_Hangman.LoadNewWord();
  690.     ResetButtons();
  691.     DrawPic();
  692.     RefreshScoreDisplay();
  693. }
  694.  
  695. void CHangman32Dlg::OnHelpAbouthangman32() 
  696. {
  697.     CAboutDlg aboutDlg;
  698.     ((CHangman32App *)AfxGetApp())->m_doAccel = FALSE;    // Block key presses
  699.     aboutDlg.DoModal();
  700.     ((CHangman32App *)AfxGetApp())->m_doAccel = TRUE;    // Allow key presses
  701. }
  702.  
  703. void CHangman32Dlg::DrawPic()
  704. {
  705.     // Just load in the picture from the resource
  706.     switch( m_Hangman.GetGuessRemain() )
  707.     {
  708.         case 10 :    VERIFY(m_cntrlPic.LoadBitmaps(IDB_BITMAP10, NULL, NULL));
  709.                     break;
  710.         case 9  :    VERIFY(m_cntrlPic.LoadBitmaps(IDB_BITMAP9, NULL, NULL));
  711.                     break;
  712.         case 8  :    VERIFY(m_cntrlPic.LoadBitmaps(IDB_BITMAP8, NULL, NULL));
  713.                     break;
  714.         case 7  :    VERIFY(m_cntrlPic.LoadBitmaps(IDB_BITMAP7, NULL, NULL));
  715.                     break;
  716.         case 6  :    VERIFY(m_cntrlPic.LoadBitmaps(IDB_BITMAP6, NULL, NULL));
  717.                     break;
  718.         case 5  :    VERIFY(m_cntrlPic.LoadBitmaps(IDB_BITMAP5, NULL, NULL));
  719.                     break;
  720.         case 4  :    VERIFY(m_cntrlPic.LoadBitmaps(IDB_BITMAP4, NULL, NULL));
  721.                     break;
  722.         case 3  :    VERIFY(m_cntrlPic.LoadBitmaps(IDB_BITMAP3, NULL, NULL));
  723.                     break;
  724.         case 2  :    VERIFY(m_cntrlPic.LoadBitmaps(IDB_BITMAP2, NULL, NULL));
  725.                     break;
  726.         case 1  :    VERIFY(m_cntrlPic.LoadBitmaps(IDB_BITMAP1, NULL, NULL));
  727.                     break;
  728.         case 0  :    VERIFY(m_cntrlPic.LoadBitmaps(IDB_BITMAP0, NULL, NULL));    
  729.                     break;
  730.         default:    TRACE("CHangman32Dlg::ProcessButtonPress: Switch Default");
  731.                     break;
  732.     }
  733.     // Invalidate so that the new picture will get drawn
  734.     m_cntrlPic.Invalidate();
  735. }
  736.  
  737. void CHangman32Dlg::OnOK()
  738. {
  739.     // Do nothing here so that hitting return in the main
  740.     // dialog will not exit the program
  741. }
  742.