home *** CD-ROM | disk | FTP | other *** search
/ Over 1,000 Games for Windows / Over1000GamesForWindows.iso / CARDS / 7andHalf / DlgHelp.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  2003-02-09  |  7.1 KB  |  240 lines

  1. // DlgHelp.cpp : implementation file
  2. //
  3.  
  4. #include "stdafx.h"
  5. #include <fstream>
  6. #include <string>
  7.  
  8. #include "CardGame.h"
  9. #include "DlgHelp.h"
  10.  
  11. #ifdef _DEBUG
  12. #define new DEBUG_NEW
  13. #undef THIS_FILE
  14. static char THIS_FILE[] = __FILE__;
  15. #endif
  16.  
  17. /////////////////////////////////////////////////////////////////////////////
  18. // DlgHelp dialog
  19.  
  20. static LPPICTURE gpMe = NULL;
  21. static LPPICTURE gpPiazza = NULL;
  22. static LPPICTURE gpSan = NULL;
  23. static LPPICTURE gpPopolo = NULL;
  24.  
  25. // This method initialize the strings to show help rules and info
  26. // english or italian, construct is a bool to check if the method is 
  27. // called by constructor, and we do not need to invalidate the rect or by change to language
  28. void DlgHelp::init(bool construct)
  29. {
  30.  
  31.       // File names of the Info and for the Rules
  32.    const char* pFileNameEng[2] = 
  33.       {".\\napoletane\\rulesEng.txt",
  34.          ".\\napoletane\\infoEng.txt"};
  35.    const char* pFileNameIta[2] = 
  36.       {".\\napoletane\\rulesIta.txt",
  37.          ".\\napoletane\\infoIta.txt"};
  38.    
  39.    mMsgRules = "";
  40.    mMsgInfo = "";
  41.  
  42.    for (int i = 0; i <= 1; i++)
  43.    {
  44.       std::ifstream in((mLanguage == LANENGLISH) ? pFileNameEng[i] : pFileNameIta[i]);
  45.       if(!in) 
  46.       {
  47.          if (0 == i)
  48.             mMsgRules = "Could not open file .\\Napoletane\\RulesEng (Ita).txt";
  49.          else
  50.             mMsgInfo = "Could not open file .\\Napoletane\\InfoEng (Ita).txt";
  51.       }
  52.       else
  53.       {
  54.          // Loading the strings by the files
  55.          std::string line;
  56.          while(std::getline(in, line)) 
  57.             if (0 == i)
  58.                mMsgRules += line + "\r\n";
  59.             else
  60.                mMsgInfo += line + "\r\n";
  61.          in.close();
  62.       }
  63.    }
  64.    if (!construct)
  65.    {
  66.       CRect rect;
  67.       GetClientRect(&rect);
  68.       InvalidateRect(&rect, TRUE);   
  69.    }
  70. }
  71.  
  72. DlgHelp::DlgHelp(CWnd* pParent /*=NULL*/)
  73.     : CDialog(DlgHelp::IDD, pParent), mLanguage(LANENGLISH)
  74. {
  75.     //{{AFX_DATA_INIT(DlgHelp)
  76.         // NOTE: the ClassWizard will add member initialization here
  77.     //}}AFX_DATA_INIT
  78.    
  79.    // Loading picture in the help Dialog
  80.    myUtilities::LoadPictureFile(".\\napoletane\\me.jpg", gpMe);
  81.    myUtilities::LoadPictureFile(".\\napoletane\\piazza.jpg", gpPiazza);
  82.    myUtilities::LoadPictureFile(".\\napoletane\\san.jpg", gpSan);
  83.    myUtilities::LoadPictureFile(".\\napoletane\\Popolo.jpg", gpPopolo);
  84.    init(true);
  85. }
  86.  
  87.  
  88. void DlgHelp::DoDataExchange(CDataExchange* pDX)
  89. {
  90.     CDialog::DoDataExchange(pDX);
  91.     //{{AFX_DATA_MAP(DlgHelp)
  92.         // NOTE: the ClassWizard will add DDX and DDV calls here
  93.     //}}AFX_DATA_MAP
  94. }
  95.  
  96.  
  97. BEGIN_MESSAGE_MAP(DlgHelp, CDialog)
  98.     //{{AFX_MSG_MAP(DlgHelp)
  99.    ON_WM_INITMENUPOPUP()
  100.     ON_WM_PAINT()
  101.     ON_WM_CANCELMODE()
  102.     ON_COMMAND(IDM_LANGUAGE_ENGLISH, OnLanguageEnglish)
  103.     ON_COMMAND(IDM_LANGUAGE_ITALIAN, OnLanguageItalian)
  104.     ON_UPDATE_COMMAND_UI(IDM_LANGUAGE_ITALIAN, OnUpdateLanguageItalian)
  105.     ON_UPDATE_COMMAND_UI(IDM_LANGUAGE_ENGLISH, OnUpdateLanguageEnglish)
  106.     //}}AFX_MSG_MAP
  107. END_MESSAGE_MAP()
  108.  
  109. /////////////////////////////////////////////////////////////////////////////
  110. // DlgHelp message handlers
  111.  
  112.  
  113. // This method is important to solve the check "V" symbol problem in the menu
  114. // attached to a dialog box
  115. void DlgHelp::OnInitMenuPopup(CMenu *pPopupMenu, UINT nIndex,BOOL bSysMenu)
  116. {
  117.     ASSERT(pPopupMenu != NULL);
  118.     // Check the enabled state of various menu items.
  119.  
  120.     CCmdUI state;
  121.     state.m_pMenu = pPopupMenu;
  122.     ASSERT(state.m_pOther == NULL);
  123.     ASSERT(state.m_pParentMenu == NULL);
  124.  
  125.     // Determine if menu is popup in top-level menu and set m_pOther to
  126.     // it if so (m_pParentMenu == NULL indicates that it is secondary popup).
  127.     HMENU hParentMenu;
  128.     if (AfxGetThreadState()->m_hTrackingMenu == pPopupMenu->m_hMenu)
  129.         state.m_pParentMenu = pPopupMenu;    // Parent == child for tracking popup.
  130.     else if ((hParentMenu = ::GetMenu(m_hWnd)) != NULL)
  131.     {
  132.         CWnd* pParent = this;
  133.            // Child windows don't have menus--need to go to the top!
  134.         if (pParent != NULL &&
  135.            (hParentMenu = ::GetMenu(pParent->m_hWnd)) != NULL)
  136.         {
  137.            int nIndexMax = ::GetMenuItemCount(hParentMenu);
  138.            for (int nIndex = 0; nIndex < nIndexMax; nIndex++)
  139.            {
  140.             if (::GetSubMenu(hParentMenu, nIndex) == pPopupMenu->m_hMenu)
  141.             {
  142.                 // When popup is found, m_pParentMenu is containing menu.
  143.                 state.m_pParentMenu = CMenu::FromHandle(hParentMenu);
  144.                 break;
  145.             }
  146.            }
  147.         }
  148.     }
  149.  
  150.     state.m_nIndexMax = pPopupMenu->GetMenuItemCount();
  151.     for (state.m_nIndex = 0; state.m_nIndex < state.m_nIndexMax;
  152.       state.m_nIndex++)
  153.     {
  154.         state.m_nID = pPopupMenu->GetMenuItemID(state.m_nIndex);
  155.         if (state.m_nID == 0)
  156.            continue; // Menu separator or invalid cmd - ignore it.
  157.  
  158.         ASSERT(state.m_pOther == NULL);
  159.         ASSERT(state.m_pMenu != NULL);
  160.         if (state.m_nID == (UINT)-1)
  161.         {
  162.            // Possibly a popup menu, route to first item of that popup.
  163.            state.m_pSubMenu = pPopupMenu->GetSubMenu(state.m_nIndex);
  164.            if (state.m_pSubMenu == NULL ||
  165.             (state.m_nID = state.m_pSubMenu->GetMenuItemID(0)) == 0 ||
  166.             state.m_nID == (UINT)-1)
  167.            {
  168.             continue;       // First item of popup can't be routed to.
  169.            }
  170.            state.DoUpdate(this, TRUE);   // Popups are never auto disabled.
  171.         }
  172.         else
  173.         {
  174.            // Normal menu item.
  175.            // Auto enable/disable if frame window has m_bAutoMenuEnable
  176.            // set and command is _not_ a system command.
  177.            state.m_pSubMenu = NULL;
  178.            state.DoUpdate(this, FALSE);
  179.         }
  180.  
  181.         // Adjust for menu deletions and additions.
  182.         UINT nCount = pPopupMenu->GetMenuItemCount();
  183.         if (nCount < state.m_nIndexMax)
  184.         {
  185.            state.m_nIndex -= (state.m_nIndexMax - nCount);
  186.            while (state.m_nIndex < nCount &&
  187.             pPopupMenu->GetMenuItemID(state.m_nIndex) == state.m_nID)
  188.            {
  189.             state.m_nIndex++;
  190.            }
  191.         }
  192.         state.m_nIndexMax = nCount;
  193.     }
  194. }
  195.  
  196.  
  197.  
  198. void DlgHelp::OnPaint() 
  199. {
  200.     CPaintDC dc(this); // device context for painting
  201.    SetDlgItemText(IDC_EDITHELP, mMsgRules.c_str());
  202.    SetDlgItemText(IDC_EDITCV, mMsgInfo.c_str());
  203.    myUtilities::RenderPic(this, dc.m_hDC, gpMe, 30, 10);
  204.    myUtilities::RenderPic(this, dc.m_hDC, gpPiazza, 550, 10);
  205.    myUtilities::RenderPic(this, dc.m_hDC, gpPopolo, 550, 150);
  206.    myUtilities::RenderPic(this, dc.m_hDC, gpSan, 550, 300);
  207. //   SetCheck(mLanguage == LANENGLISH ? 0 : 1);
  208. }
  209.  
  210. void DlgHelp::OnCancelMode() 
  211. {
  212.     CDialog::OnCancelMode();
  213.     
  214. }
  215.  
  216. void DlgHelp::OnLanguageEnglish() 
  217. {
  218.  
  219.    mLanguage = LANENGLISH;
  220.    init(false);
  221. }
  222.  
  223. void DlgHelp::OnLanguageItalian() 
  224. {
  225.    mLanguage = LANITALIAN;
  226.    init(false);
  227. }
  228.  
  229. void DlgHelp::OnUpdateLanguageItalian(CCmdUI* pCmdUI) 
  230. {
  231.    pCmdUI->SetCheck(mLanguage == LANITALIAN ? 1 : 0);
  232.     
  233. }
  234.  
  235. void DlgHelp::OnUpdateLanguageEnglish(CCmdUI* pCmdUI) 
  236. {
  237.    pCmdUI->SetCheck(mLanguage == LANENGLISH ? 1 : 0);
  238. }
  239.  
  240.