home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Windows Gam…ming Gurus (2nd Edition) / Disc2.iso / msdn_vcb / samples / vc98 / atl / atlfire / propdlg.cpp < prev    next >
C/C++ Source or Header  |  1998-03-26  |  9KB  |  314 lines

  1. // PropDlg.cpp : Implementation of CPropDlg
  2. //
  3. // This is a part of the Active Template Library.
  4. // Copyright (C) 1996-1998 Microsoft Corporation
  5. // All rights reserved.
  6. //
  7. // This source code is only intended as a supplement to the
  8. // Active Template Library Reference and related
  9. // electronic documentation provided with the library.
  10. // See these sources for detailed information regarding the
  11. // Active Template Library product.
  12.  
  13. #include "stdafx.h"
  14. #include "PropDlg.h"
  15. #include <commctrl.h>
  16. #include <stdlib.h>
  17. #include "firewnd.h"
  18.  
  19. /////////////////////////////////////////////////////////////////////////////
  20. // CPropDlg
  21.  
  22. CPropDlg::CPropDlg(CFireWnd* p):
  23.     m_Display(p),
  24.     m_hSetting(0),
  25.     m_hSettingCtl(0),
  26.     m_hTreeViewCtl(0),
  27.     m_nChaos(0),
  28.     m_nDecay(0),
  29.     m_nDistribution(0),
  30.     m_nMaxHeat(0),
  31.     m_nSmoothness(0),
  32.     m_nSpreadRate(0)
  33. {
  34. }
  35.  
  36. CPropDlg::~CPropDlg()
  37. {
  38. }
  39.  
  40. LRESULT CPropDlg::OnSelChanging(int idCtrl, LPNMHDR pnmh, BOOL& bHandled)
  41. {
  42.     ATLTRACE(_T("CPropDlg::OnSelChanging()\n"));
  43.     Apply();
  44.     return 0;
  45. }
  46.  
  47. LRESULT CPropDlg::OnPropertyChanged(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled)
  48. {
  49.     ATLTRACE(_T("CPropDlg::OnPropertyChanged()\n"));
  50.     const int getLen = 127;
  51.     _TCHAR buf[128] = _T("");
  52.     _TCHAR *bufend;
  53.  
  54.     int nVal = 0;
  55.     switch(m_nCurSel)
  56.     {
  57.     case 0: // Fire
  58.         break;
  59.     case 1: // Decay
  60.         GetDlgItemText(IDC_EDIT1, buf, getLen);
  61.         nVal = _tcstol(buf,&bufend,10);
  62.         if( nVal != m_nDecay )
  63.         {
  64.             m_nDecay = nVal;
  65.             ::EnableWindow(GetDlgItem(IDC_APPLY),TRUE);
  66.         }
  67.         break;
  68.     case 2: // Flammability
  69.         GetDlgItemText(IDC_EDIT1, buf, getLen);
  70.         nVal = _tcstol(buf,&bufend,10);
  71.         if( nVal != m_nFlammability )
  72.         {
  73.             m_nFlammability = nVal;
  74.             ::EnableWindow(GetDlgItem(IDC_APPLY),TRUE);
  75.         }
  76.         break;
  77.     case 3: // Maximum Heat
  78.         GetDlgItemText(IDC_EDIT1, buf, getLen);
  79.         nVal = _tcstol(buf,&bufend,10);
  80.         if( nVal != m_nMaxHeat )
  81.         {
  82.             m_nMaxHeat = nVal;
  83.             ::EnableWindow(GetDlgItem(IDC_APPLY),TRUE);
  84.         }
  85.         break;
  86.     case 4: // Spread Rate
  87.         GetDlgItemText(IDC_EDIT1, buf, getLen);
  88.         nVal = _tcstol(buf,&bufend,10);
  89.         if( nVal != m_nSpreadRate )
  90.         {
  91.             m_nSpreadRate = nVal;
  92.             ::EnableWindow(GetDlgItem(IDC_APPLY),TRUE);
  93.         }
  94.         break;
  95.     case 5: // Size
  96.         GetDlgItemText(IDC_EDIT1, buf, getLen);
  97.         nVal = _tcstol(buf,&bufend,10);
  98.         if( nVal != m_nSize )
  99.         {
  100.             m_nSize = nVal;
  101.             ::EnableWindow(GetDlgItem(IDC_APPLY),TRUE);
  102.         }
  103.         break;
  104.     case 6: // Smoothness
  105.         GetDlgItemText(IDC_EDIT1, buf, getLen);
  106.         nVal = _tcstol(buf,&bufend,10);
  107.         if( nVal != m_nSmoothness )
  108.         {
  109.             m_nSmoothness = nVal;
  110.             ::EnableWindow(GetDlgItem(IDC_APPLY),TRUE);
  111.         }
  112.         break;
  113.     case 7: // Distribution
  114.         GetDlgItemText(IDC_EDIT1, buf, getLen);
  115.         nVal = _tcstol(buf,&bufend,10);
  116.         if( nVal != m_nDistribution )
  117.         {
  118.             m_nDistribution = nVal;
  119.             ::EnableWindow(GetDlgItem(IDC_APPLY),TRUE);
  120.         }
  121.         break;
  122.     case 8: // Chaos
  123.         GetDlgItemText(IDC_EDIT1, buf, getLen);
  124.         nVal = _tcstol(buf,&bufend,10);
  125.         if( nVal != m_nChaos )
  126.         {
  127.             m_nChaos = nVal;
  128.             ::EnableWindow(GetDlgItem(IDC_APPLY),TRUE);
  129.         }
  130.         break;
  131.     }
  132.     return 0;
  133. }
  134.  
  135. LRESULT CPropDlg::OnSelChanged(int idCtrl, LPNMHDR pnmh, BOOL& bHandled)
  136. {
  137.     ATLTRACE(_T("CPropDlg::OnSelChanged()\n"));
  138.     NM_TREEVIEW* pNMTreeView = (NM_TREEVIEW*)pnmh;
  139.     TCHAR buf[128] = _T("");
  140.     ::EnableWindow(GetDlgItem(IDC_APPLY), FALSE);
  141.  
  142.     m_nCurSel = pNMTreeView->itemNew.lParam;
  143.  
  144.     switch(m_nCurSel)
  145.     {
  146.     case 0: // Fire
  147.         SetDlgItemText(IDC_EDIT1,_T(""));
  148.         ::EnableWindow(m_hSetting,FALSE);
  149.         ::EnableWindow(m_hSettingCtl,FALSE);
  150.         break;
  151.     case 1: // Decay
  152.         _itot(m_nDecay,buf,10);
  153.         SetDlgItemText(IDC_EDIT1,buf);
  154.         ::SendMessage(m_hSettingCtl,UDM_SETRANGE, 0, MAKELONG(1,100));
  155.         ::EnableWindow(m_hSettingCtl,TRUE);
  156.         ::EnableWindow(m_hSetting,TRUE);
  157.         break;
  158.     case 2: // Flammability
  159.         _itot(m_nFlammability,buf,10);
  160.         SetDlgItemText(IDC_EDIT1,buf);
  161.         ::SendMessage(m_hSettingCtl,UDM_SETRANGE, 0, MAKELONG(1,399));
  162.         ::EnableWindow(m_hSettingCtl,TRUE);
  163.         ::EnableWindow(m_hSetting,TRUE);
  164.         break;
  165.     case 3: // Maximum Heat
  166.         _itot(m_nMaxHeat,buf,10);
  167.         SetDlgItemText(IDC_EDIT1,buf);
  168.         ::SendMessage(m_hSettingCtl,UDM_SETRANGE, 0, MAKELONG(0,223));
  169.         ::EnableWindow(m_hSettingCtl,TRUE);
  170.         ::EnableWindow(m_hSetting,TRUE);
  171.         break;
  172.     case 4: // Spread Rate
  173.         _itot(m_nSpreadRate,buf,10);
  174.         SetDlgItemText(IDC_EDIT1,buf);
  175.         ::SendMessage(m_hSettingCtl,UDM_SETRANGE, 0, MAKELONG(1,100));
  176.         ::EnableWindow(m_hSettingCtl,TRUE);
  177.         ::EnableWindow(m_hSetting,TRUE);
  178.         break;
  179.     case 5: // Size
  180.         _itot(m_nSize,buf,10);
  181.         SetDlgItemText(IDC_EDIT1,buf);
  182.         ::SendMessage(m_hSettingCtl,UDM_SETRANGE, 0, MAKELONG(1,m_Display->bmSize.cx - 1));
  183.         ::EnableWindow(m_hSettingCtl,TRUE);
  184.         ::EnableWindow(m_hSetting,TRUE);
  185.         break;
  186.     case 6: // Smoothness
  187.         _itot(m_nSmoothness,buf,10);
  188.         SetDlgItemText(IDC_EDIT1,buf);
  189.         ::SendMessage(m_hSettingCtl,UDM_SETRANGE, 0, MAKELONG(0,5));
  190.         ::EnableWindow(m_hSettingCtl,TRUE);
  191.         ::EnableWindow(m_hSetting,TRUE);
  192.         break;
  193.     case 7: // Distribution
  194.         _itot(m_nDistribution,buf,10);
  195.         SetDlgItemText(IDC_EDIT1,buf);
  196.         ::SendMessage(m_hSettingCtl,UDM_SETRANGE, 0, MAKELONG(0,10));
  197.         ::EnableWindow(m_hSettingCtl,TRUE);
  198.         ::EnableWindow(m_hSetting,TRUE);
  199.         break;
  200.     case 8: // Chaos
  201.         _itot(m_nChaos,buf,10);
  202.         SetDlgItemText(IDC_EDIT1,buf);
  203.         ::SendMessage(m_hSettingCtl,UDM_SETRANGE, 0, MAKELONG(1,100));
  204.         ::EnableWindow(m_hSettingCtl,TRUE);
  205.         ::EnableWindow(m_hSetting,TRUE);
  206.         break;
  207.     }
  208.  
  209.     return 0;
  210. }
  211.  
  212. LRESULT CPropDlg::OnInitDialog(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
  213. {
  214.     m_nDecay        = m_Display->m_nDecay;
  215.     m_nFlammability = m_Display->m_nFlammability;
  216.     m_nMaxHeat      = m_Display->m_nMaxHeat;
  217.     m_nSpreadRate   = m_Display->m_nSpreadRate;
  218.     m_nSize         = m_Display->m_nSize;
  219.     m_nSmoothness   = m_Display->m_nSmoothness;
  220.     m_nDistribution = m_Display->m_nDistribution;
  221.     m_nChaos        = m_Display->m_nChaos;
  222.  
  223.     m_hTreeViewCtl = GetDlgItem(IDC_TREE1);
  224.     m_hSettingCtl = GetDlgItem(IDC_SPIN1);
  225.     m_hSetting = GetDlgItem(IDC_EDIT1);
  226.  
  227.     TV_INSERTSTRUCT TreeCtrlItem;
  228.  
  229.     TreeCtrlItem.hParent = TVI_ROOT;
  230.     TreeCtrlItem.hInsertAfter = TVI_LAST;
  231.     TreeCtrlItem.item.mask = TVIF_TEXT | TVIF_PARAM;
  232.     TreeCtrlItem.item.pszText = _T("Fire");
  233.     TreeCtrlItem.item.lParam = 0;
  234.     HTREEITEM hTreeItem1 = TreeView_InsertItem(m_hTreeViewCtl, &TreeCtrlItem);
  235.  
  236.  
  237.     TreeCtrlItem.hParent = hTreeItem1;
  238.     TreeCtrlItem.item.pszText = _T("Decay");
  239.     TreeCtrlItem.item.lParam = 1;
  240.     TreeView_InsertItem(m_hTreeViewCtl, &TreeCtrlItem);
  241.  
  242.     TreeCtrlItem.item.pszText = _T("Flammability");
  243.     TreeCtrlItem.item.lParam = 2;
  244.     TreeView_InsertItem(m_hTreeViewCtl, &TreeCtrlItem);
  245.  
  246.     TreeCtrlItem.item.pszText = _T("Maximum Heat");
  247.     TreeCtrlItem.item.lParam = 3;
  248.     TreeView_InsertItem(m_hTreeViewCtl, &TreeCtrlItem);
  249.  
  250.     TreeCtrlItem.item.pszText = _T("Spread Rate");
  251.     TreeCtrlItem.item.lParam = 4;
  252.     TreeView_InsertItem(m_hTreeViewCtl, &TreeCtrlItem);
  253.  
  254.     TreeCtrlItem.item.pszText = _T("Size");
  255.     TreeCtrlItem.item.lParam = 5;
  256.     TreeView_InsertItem(m_hTreeViewCtl, &TreeCtrlItem);
  257.  
  258.     TreeCtrlItem.hParent = TVI_ROOT;
  259.     TreeCtrlItem.item.pszText = _T("Render");
  260.     TreeCtrlItem.item.lParam = 0;
  261.     HTREEITEM hTreeItem2 = TreeView_InsertItem(m_hTreeViewCtl, &TreeCtrlItem);
  262.  
  263.     TreeCtrlItem.hParent = hTreeItem2;
  264.     TreeCtrlItem.item.pszText = _T("Smoothness");
  265.     TreeCtrlItem.item.lParam = 6;
  266.     TreeView_InsertItem(m_hTreeViewCtl, &TreeCtrlItem);
  267.  
  268.     TreeCtrlItem.item.pszText = _T("Distribution");
  269.     TreeCtrlItem.item.lParam = 7;
  270.     TreeView_InsertItem(m_hTreeViewCtl, &TreeCtrlItem);
  271.  
  272.     TreeCtrlItem.item.pszText = _T("Chaos");
  273.     TreeCtrlItem.item.lParam = 8;
  274.     TreeView_InsertItem(m_hTreeViewCtl, &TreeCtrlItem);
  275.  
  276.     TreeView_Expand(m_hTreeViewCtl, hTreeItem1,TVE_EXPAND);
  277.     TreeView_Expand(m_hTreeViewCtl, hTreeItem2,TVE_EXPAND);
  278.  
  279.     return 1;  // Let the system set the focus
  280. }
  281.  
  282. LRESULT CPropDlg::OnOK(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled)
  283. {
  284.     Apply();
  285.     EndDialog(wID);
  286.     return 0;
  287. }
  288.  
  289. LRESULT CPropDlg::OnCancel(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled)
  290. {
  291.     EndDialog(wID);
  292.     return 0;
  293. }
  294.  
  295. LRESULT CPropDlg::OnApply(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled)
  296. {
  297.     Apply();
  298.     return 0;
  299. }
  300.  
  301. void CPropDlg::Apply()
  302. {
  303.     m_Display->m_nDecay         = m_nDecay;
  304.     m_Display->m_nFlammability  = m_nFlammability;
  305.     m_Display->m_nMaxHeat       = m_nMaxHeat;
  306.     m_Display->m_nSpreadRate    = m_nSpreadRate;
  307.     m_Display->m_nSize          = m_nSize;
  308.     m_Display->m_nSmoothness    = m_nSmoothness;
  309.     m_Display->m_nDistribution  = m_nDistribution;
  310.     m_Display->m_nChaos         = m_nChaos;
  311.  
  312.     ::EnableWindow(GetDlgItem(IDC_APPLY), FALSE);
  313. }
  314.