home *** CD-ROM | disk | FTP | other *** search
/ Media Share 13 / mediashare_13.zip / mediashare_13 / ZIPPED / PROGRAM / WTJ9403.ZIP / POKER / MAINFRM.CPP < prev    next >
C/C++ Source or Header  |  1993-10-08  |  7KB  |  239 lines

  1. // mainfrm.cpp : implementation of the CMainFrame class
  2. //
  3.  
  4. #include "stdafx.h"
  5. #include "poker.h"
  6.  
  7. #include "pokerdoc.h"
  8. #include "pokervw.h"
  9.  
  10. #include "mainfrm.h"
  11.  
  12. #ifdef _DEBUG
  13. #undef THIS_FILE
  14. static char BASED_CODE THIS_FILE[] = __FILE__;
  15. #endif
  16.  
  17. /////////////////////////////////////////////////////////////////////////////
  18. // CMainFrame
  19.  
  20. IMPLEMENT_DYNCREATE(CMainFrame, CFrameWnd)
  21.  
  22. BEGIN_MESSAGE_MAP(CMainFrame, CFrameWnd)
  23.     //{{AFX_MSG_MAP(CMainFrame)
  24.     ON_WM_CREATE()
  25.     //}}AFX_MSG_MAP
  26.     ON_UPDATE_COMMAND_UI(ID_INDICATOR_POT, OnUpdateKeyIndicator)
  27.     ON_UPDATE_COMMAND_UI(ID_INDICATOR_POT_VALUE, OnUpdateKeyIndicator)
  28.     ON_UPDATE_COMMAND_UI(ID_INDICATOR_CREDIT, OnUpdateKeyIndicator)
  29.     ON_UPDATE_COMMAND_UI(ID_INDICATOR_CREDIT_VALUE, OnUpdateKeyIndicator)
  30.     ON_UPDATE_COMMAND_UI(ID_INDICATOR_OWED, OnUpdateKeyIndicator)
  31.     ON_UPDATE_COMMAND_UI(ID_INDICATOR_OWED_VALUE, OnUpdateKeyIndicator)
  32.     ON_UPDATE_COMMAND_UI(ID_INDICATOR_BET, OnUpdateKeyIndicator)
  33.     ON_UPDATE_COMMAND_UI(ID_INDICATOR_BET_VALUE, OnUpdateKeyIndicator)
  34.  
  35. END_MESSAGE_MAP()
  36.  
  37. /////////////////////////////////////////////////////////////////////////////
  38. // arrays of IDs used to initialize control bars
  39.  
  40. // toolbar buttons - IDs are command buttons
  41. static UINT BASED_CODE buttons[] =
  42. {
  43.     // same order as in the bitmap 'toolbar.bmp'
  44.     ID_FILE_NEWGAME,
  45.         ID_SEPARATOR,
  46.     ID_MOVES_CALL,
  47.     ID_MOVES_BET,
  48.     ID_MOVES_FOLD,
  49.     ID_MOVES_RAISE,
  50.     ID_MOVES_CHECK,
  51.         ID_SEPARATOR,
  52.     ID_MOVES_DEAL,
  53. };
  54.  
  55. static UINT BASED_CODE indicators[] =
  56. {
  57.     ID_SEPARATOR,            // status line indicator
  58.     
  59.     ID_INDICATOR_POT,
  60.     ID_INDICATOR_POT_VALUE,
  61.     ID_INDICATOR_CREDIT,
  62.     ID_INDICATOR_CREDIT_VALUE,
  63.     ID_INDICATOR_OWED,
  64.     ID_INDICATOR_OWED_VALUE,
  65.     ID_INDICATOR_BET,
  66.     ID_INDICATOR_BET_VALUE,
  67. };
  68.  
  69. /////////////////////////////////////////////////////////////////////////////
  70. // CMainFrame construction/destruction
  71.  
  72. CMainFrame::CMainFrame()
  73. {
  74.     // TODO: add member initialization code here
  75. }
  76.  
  77. CMainFrame::~CMainFrame()
  78. {
  79. }
  80.  
  81. int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
  82. {
  83.     if (CFrameWnd::OnCreate(lpCreateStruct) == -1)
  84.         return -1;
  85.  
  86.     if (!m_wndToolBar.Create(this) ||
  87.         !m_wndToolBar.LoadBitmap(IDR_MAINFRAME) ||
  88.         !m_wndToolBar.SetButtons(buttons,
  89.  
  90.           sizeof(buttons)/sizeof(UINT)))
  91.     {
  92.         TRACE("Failed to create toolbar\n");
  93.         return -1;        // fail to create
  94.     }
  95.  
  96.     if (!m_wndStatusBar.Create(this) ||
  97.         !m_wndStatusBar.SetIndicators(indicators,
  98.           sizeof(indicators)/sizeof(UINT)))
  99.     {
  100.         TRACE("Failed to create status bar\n");
  101.         return -1;        // fail to create
  102.     }
  103.     else
  104.     {    
  105.         UINT    nID;
  106.         UINT    nStyle;
  107.         int        cxWidth;
  108.         int        nIndex;
  109.  
  110.         nIndex = m_wndStatusBar.CommandToIndex(ID_INDICATOR_POT);
  111.         m_wndStatusBar.GetPaneInfo(nIndex, nID, nStyle, cxWidth);
  112.         nStyle = SBPS_NORMAL | SBPS_NOBORDERS;
  113.         m_wndStatusBar.SetPaneInfo(nIndex, nID, nStyle, cxWidth);
  114.         
  115.         nIndex = m_wndStatusBar.CommandToIndex(ID_INDICATOR_CREDIT);
  116.         m_wndStatusBar.GetPaneInfo(nIndex, nID, nStyle, cxWidth);
  117.         nStyle = SBPS_NORMAL | SBPS_NOBORDERS;
  118.         m_wndStatusBar.SetPaneInfo(nIndex, nID, nStyle, cxWidth);
  119.         
  120.         nIndex = m_wndStatusBar.CommandToIndex(ID_INDICATOR_OWED);
  121.         m_wndStatusBar.GetPaneInfo(nIndex, nID, nStyle, cxWidth);
  122.         nStyle = SBPS_NORMAL | SBPS_NOBORDERS;
  123.         m_wndStatusBar.SetPaneInfo(nIndex, nID, nStyle, cxWidth);
  124.         
  125.         nIndex = m_wndStatusBar.CommandToIndex(ID_INDICATOR_BET);
  126.         m_wndStatusBar.GetPaneInfo(nIndex, nID, nStyle, cxWidth);
  127.         nStyle = SBPS_NORMAL | SBPS_NOBORDERS;
  128.         m_wndStatusBar.SetPaneInfo(nIndex, nID, nStyle, cxWidth);
  129.         
  130.         nIndex = m_wndStatusBar.CommandToIndex(ID_INDICATOR_POT_VALUE);
  131.         m_wndStatusBar.SetPaneText(nIndex, "0");
  132.         nIndex = m_wndStatusBar.CommandToIndex(ID_INDICATOR_CREDIT_VALUE);
  133.         m_wndStatusBar.SetPaneText(nIndex, "0");
  134.         nIndex = m_wndStatusBar.CommandToIndex(ID_INDICATOR_OWED_VALUE);
  135.         m_wndStatusBar.SetPaneText(nIndex, "0");
  136.         nIndex = m_wndStatusBar.CommandToIndex(ID_INDICATOR_BET_VALUE);
  137.         m_wndStatusBar.SetPaneText(nIndex, "0");
  138.     }
  139.  
  140.     SetWindowPos(&wndTopMost, 0, 0, 640, 480, SWP_NOZORDER); 
  141.  
  142.     return 0;
  143. }
  144.  
  145. /////////////////////////////////////////////////////////////////////////////
  146. // CMainFrame diagnostics
  147.  
  148. #ifdef _DEBUG
  149. void CMainFrame::AssertValid() const
  150. {
  151.     CFrameWnd::AssertValid();
  152. }
  153.  
  154. void CMainFrame::Dump(CDumpContext& dc) const
  155. {
  156.     CFrameWnd::Dump(dc);
  157. }
  158.  
  159. #endif //_DEBUG
  160.  
  161. /////////////////////////////////////////////////////////////////////////////
  162. // CMainFrame message handlers
  163.  
  164. /////////////////////////////////////////////////////////////////////////////
  165. // Support for standard status bar
  166.  
  167. void CMainFrame::OnUpdateKeyIndicator(CCmdUI* pCmdUI)
  168. {
  169. UINT    nVK = 1;
  170. char    szBuffer[20];
  171. UINT    nIndex = m_wndStatusBar.CommandToIndex(pCmdUI->m_nID);
  172.  
  173. //  Get the current document, to update the status bar indicators...
  174.  
  175.     CPokerView* pView = (CPokerView *)GetActiveView();
  176.     CPokerDoc* pDoc = pView->GetDocument();
  177.  
  178.     switch (pCmdUI->m_nID)
  179.     {
  180.         case ID_INDICATOR_CAPS:
  181.                 nVK = VK_CAPITAL;
  182.                 break;
  183.  
  184.         case ID_INDICATOR_NUM:
  185.                 nVK = VK_NUMLOCK;
  186.                 break;
  187.  
  188.         case ID_INDICATOR_SCRL:
  189.                 nVK = VK_SCROLL;
  190.                 break;
  191.  
  192.         case ID_INDICATOR_POT_VALUE:
  193.                 sprintf(szBuffer, "%d", pDoc->nPot * 5);                
  194.                 m_wndStatusBar.SetPaneText(nIndex, szBuffer);
  195.                 nVK = 0;
  196.                 break;
  197.         case ID_INDICATOR_CREDIT_VALUE:
  198.                 sprintf(szBuffer, "%d", pDoc->nChips[3] * 5);
  199.                 m_wndStatusBar.SetPaneText(nIndex, szBuffer);
  200.                 nVK = 0;
  201.                 break;
  202.         case ID_INDICATOR_OWED_VALUE:
  203.                 sprintf(szBuffer, "%d", pDoc->nOwed[3]);                
  204.                 m_wndStatusBar.SetPaneText(nIndex, szBuffer);
  205.                 nVK = 0;
  206.                 break;
  207.         case ID_INDICATOR_BET_VALUE:
  208.                 sprintf(szBuffer, "%d", pDoc->nOwed[3]);                
  209.                 m_wndStatusBar.SetPaneText(nIndex, szBuffer);
  210.                 nVK = 0;
  211.                 break;
  212.                 
  213.         case ID_INDICATOR_POT:
  214.         case ID_INDICATOR_CREDIT:
  215.         case ID_INDICATOR_OWED:
  216.         case ID_INDICATOR_BET:
  217.                 nVK = 0;
  218.                 break;
  219.  
  220.         default:
  221.                 TRACE1("Warning: OnUpdateKeyIndicator - unknown indicator 0x%04X\n",
  222.                         pCmdUI->m_nID);
  223.                 pCmdUI->ContinueRouting();
  224.                 return; // not for us
  225.     }
  226.         
  227.     if (nVK)
  228.     {
  229.            pCmdUI->Enable(::GetKeyState(nVK) & 1);
  230.     }
  231.     else
  232.     {
  233.         pCmdUI->Enable(TRUE);            
  234.     }
  235.     // enable static text based on toggled key state
  236.     ASSERT(pCmdUI->m_bEnableChanged);
  237. }
  238.  
  239.