home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Windows Gam…ming Gurus (2nd Edition) / Disc2.iso / common / msdev98 / bin / ide / statbar.dll / TEXTCODE / 146
Text File  |  1998-06-18  |  10KB  |  279 lines

  1. ###############################################################
  2. ## This file contains the code fragments that are included in
  3. ## the users' code.  There are numerous constraints.
  4. ##   o  ## lines are processed.
  5. ##     o  Keywords such as:- (in all upper case!)
  6. ##          access    = [public | private | protected | dontcare]
  7. ##          placement = [begin  | end ]
  8. ##          start  <-- beginning of code
  9. ##          stop   <-- end of code
  10. ##   o  First line of code should be the prototype
  11. ##   o  Code completion should be with ## end
  12. ##   o  All other ## lines are discarded.
  13. ##   o  All lines outside of start/stop are discarded
  14. ###############################################################
  15.  
  16.  
  17. ###############################################################
  18. ## PROTECTED
  19. ## BEGIN
  20. ## START  *-*-*-* OnMenuSelect *-*-*-*
  21. afx_msg void %s::OnMenuSelect(UINT nItemID, UINT nFlags, HMENU hSysMenu)
  22. BH    %s::OnMenuSelect(nItemID, nFlags, hSysMenu);
  23. BH
  24.     // CG: The following block was inserted by 'Status Bar' component.
  25.     {
  26.         // Restore first pane of the statusbar?
  27.         if (nFlags == 0xFFFF && hSysMenu == 0 && m_nStatusPane1Width != -1)
  28.         {
  29.             m_bMenuSelect = FALSE;
  30.             m_wndStatusBar.SetPaneInfo(0, 
  31.                 m_nStatusPane1ID, m_nStatusPane1Style, m_nStatusPane1Width);
  32.             m_nStatusPane1Width = -1;   // Set it to illegal value
  33.         }
  34.         else 
  35.         {
  36.             m_bMenuSelect = TRUE;
  37.         }
  38.     }
  39. ## STOP   *-*-*-* OnMenuSelect *-*-*-*
  40. ##-------------------------------------------------------------
  41. ## PROTECTED
  42. ## BEGIN
  43. ## START  *-*-*-* OnMenuSelect *-*-*-*
  44. afx_msg void %s::OnMenuSelect(UINT nItemID, UINT nFlags, HMENU hSysMenu)
  45. BH    CMDIChildWnd::OnMenuSelect(nItemID, nFlags, hSysMenu);
  46. BH
  47.     // CG: The following block was inserted by 'Status Bar' component.
  48.     {
  49.         static BOOL bMenuActive = FALSE;
  50.         if (bMenuActive || hSysMenu != NULL)
  51.         {
  52.             GetParentFrame()->PostMessage(WM_MENUSELECT, 
  53.                 MAKELONG(nItemID, nFlags), (LPARAM)hSysMenu);
  54.         }
  55.         bMenuActive = hSysMenu != NULL;
  56.     }
  57. ## STOP   *-*-*-* OnMenuSelect *-*-*-*
  58. ###############################################################
  59.  
  60.  
  61. ###############################################################
  62. ## PROTECTED
  63. ## BEGIN
  64. ## START  *-*-*-* OnInitMenuPopup *-*-*-* 
  65. afx_msg void %s::OnInitMenuPopup(CMenu* pPopupMenu, UINT nIndex, BOOL bSysMenu)
  66. BH    %s::OnInitMenuPopup(pPopupMenu, nIndex, bSysMenu);
  67. BH
  68.     // CG: The following block was inserted by 'Status Bar' component.
  69.     {
  70.         // store width of first pane and its style
  71.         if (m_nStatusPane1Width == -1 && m_bMenuSelect)
  72.         {
  73.             m_wndStatusBar.GetPaneInfo(0, m_nStatusPane1ID, 
  74.                 m_nStatusPane1Style, m_nStatusPane1Width);
  75.             m_wndStatusBar.SetPaneInfo(0, m_nStatusPane1ID, 
  76.                 SBPS_NOBORDERS|SBPS_STRETCH, 16384);
  77.         }
  78.     }
  79. ## STOP   *-*-*-* OnInitMenuPopup *-*-*-* 
  80. ##-------------------------------------------------------------
  81. ## PROTECTED
  82. ## BEGIN
  83. ## START  *-*-*-* OnInitMenuPopup *-*-*-* 
  84. afx_msg void %s::OnInitMenuPopup(CMenu* pPopupMenu, UINT nIndex, BOOL bSysMenu)
  85. BH    CMDIChildWnd::OnInitMenuPopup(pPopupMenu, nIndex, bSysMenu);
  86. BH
  87.     // CG: The following block was inserted by 'Status Bar' component.
  88.     {
  89.         GetParentFrame()->PostMessage(WM_INITMENUPOPUP,
  90.             (WPARAM)pPopupMenu->GetSafeHmenu(), MAKELONG(nIndex, bSysMenu));
  91.     }
  92. ## STOP   *-*-*-* OnInitMenuPopup *-*-*-* 
  93. ###############################################################
  94.  
  95.  
  96. ###############################################################
  97. ## PUBLIC
  98. ## BEGIN
  99. ## START  *-*-*-* Constructor *-*-*-* 
  100. %s::%s()
  101.     // CG: The following block was inserted by 'Status Bar' component.
  102.     {
  103.         m_nStatusPane1Width = -1;
  104.         m_bMenuSelect = FALSE;
  105.     }
  106. ## STOP   *-*-*-* Constructor *-*-*-* 
  107. ###############################################################
  108.  
  109. ###############################################################
  110. ## PUBLIC
  111. ## BEGIN
  112. ## START  *-*-*-* InitInstance *-*-*-* 
  113. BOOL %s::InitInstance()
  114.     // CG: The following block was inserted by 'Status Bar' component.
  115.     {
  116.         //Set up date and time defaults so they're the same as system defaults
  117.         setlocale(LC_ALL, "");
  118.     }
  119. ## STOP   *-*-*-* InitInstance *-*-*-* 
  120. ###############################################################
  121.  
  122.  
  123. ###############################################################
  124. ## PROTECTED
  125. ## END
  126. ## START  *-*-*-* OnCreate *-*-*-*
  127. afx_msg int %s::OnCreate(LPCREATESTRUCT lpCreateStruct)
  128.     // CG: The following block was inserted by 'Status Bar' component.
  129.     {
  130.         // Find out the size of the static variable 'indicators' defined
  131.         // by AppWizard and copy it
  132.         int nOrigSize = sizeof(indicators) / sizeof(UINT);
  133.  
  134.         UINT* pIndicators = new UINT[nOrigSize + 2];
  135.         memcpy(pIndicators, indicators, sizeof(indicators));
  136.  
  137.         // Call the Status Bar Component's status bar creation function
  138.         if (!InitStatusBar(pIndicators, nOrigSize, 60))
  139.         {
  140.             TRACE0("Failed to initialize Status Bar\n");
  141.             return -1;
  142.         }
  143.         delete[] pIndicators;
  144.     }
  145. ## STOP   *-*-*-* OnCreate *-*-*-*
  146. ##-------------------------------------------------------------
  147. ## PROTECTED
  148. ## END
  149. ## START  *-*-*-* OnCreate *-*-*-*
  150. afx_msg int %s::OnCreate(LPCREATESTRUCT lpCreateStruct)
  151.     // CG: The following block was inserted by 'Status Bar' component.
  152.     {    
  153.         // Create an array for status bar indicators
  154.         UINT pIndicators[3] = { ID_SEPARATOR };
  155.         if (!m_wndStatusBar.Create(this) ||
  156.             !InitStatusBar(pIndicators, 1, 60))
  157.         {
  158.             TRACE0("Failed to create Status Bar\n");
  159.             return -1;
  160.         }
  161.  
  162.         // TODO: If you have a call to EnableDocking() and DockControlBar()
  163.         // before this line, move them to right after this comment.  This
  164.         // insures that the docking area remains above the status bar.
  165.     }
  166. ## STOP   *-*-*-* OnCreate *-*-*-*
  167. ###############################################################
  168.  
  169. ###############################################################
  170. ## PROTECTED
  171. ## BEGIN
  172. ## START  *-*-*-* OnUpdateDate *-*-*-*
  173. afx_msg void %s::OnUpdateDate(CCmdUI* pCmdUI)
  174.     // CG: This function was inserted by 'Status Bar' component.
  175.  
  176.     // Get current date and format it
  177.     CTime time = CTime::GetCurrentTime();
  178.     CString strDate = time.Format(%s);
  179.  
  180.     // BLOCK: compute the width of the date string
  181.     CSize size;
  182.     {
  183.         HGDIOBJ hOldFont = NULL;
  184.         HFONT hFont = (HFONT)m_wndStatusBar.SendMessage(WM_GETFONT);
  185.         CClientDC dc(NULL);
  186.         if (hFont != NULL) 
  187.             hOldFont = dc.SelectObject(hFont);
  188.         size = dc.GetTextExtent(strDate);
  189.         if (hOldFont != NULL) 
  190.             dc.SelectObject(hOldFont);
  191.     }
  192.  
  193.     // Update the pane to reflect the current date
  194.     UINT nID, nStyle;
  195.     int nWidth;
  196.     m_wndStatusBar.GetPaneInfo(m_nDatePaneNo, nID, nStyle, nWidth);
  197.     m_wndStatusBar.SetPaneInfo(m_nDatePaneNo, nID, nStyle, size.cx);
  198.     pCmdUI->SetText(strDate);
  199.     pCmdUI->Enable(TRUE);
  200. ## STOP   *-*-*-* OnUpdateDate *-*-*-*
  201. ###############################################################
  202.  
  203.  
  204. ###############################################################
  205. ## PROTECTED
  206. ## BEGIN
  207. ## START  *-*-*-* OnUpdateTime *-*-*-*
  208. afx_msg void %s::OnUpdateTime(CCmdUI* pCmdUI)
  209.     // CG: This function was inserted by 'Status Bar' component.
  210.  
  211.     // Get current date and format it
  212.     CTime time = CTime::GetCurrentTime();
  213.     CString strTime = time.Format(%s);%s
  214.  
  215.     // BLOCK: compute the width of the date string
  216.     CSize size;
  217.     {
  218.         HGDIOBJ hOldFont = NULL;
  219.         HFONT hFont = (HFONT)m_wndStatusBar.SendMessage(WM_GETFONT);
  220.         CClientDC dc(NULL);
  221.         if (hFont != NULL) 
  222.             hOldFont = dc.SelectObject(hFont);
  223.         size = dc.GetTextExtent(strTime);
  224.         if (hOldFont != NULL) 
  225.             dc.SelectObject(hOldFont);
  226.     }
  227.  
  228.     // Update the pane to reflect the current time
  229.     UINT nID, nStyle;
  230.     int nWidth;
  231.     m_wndStatusBar.GetPaneInfo(m_nTimePaneNo, nID, nStyle, nWidth);
  232.     m_wndStatusBar.SetPaneInfo(m_nTimePaneNo, nID, nStyle, size.cx);
  233.     pCmdUI->SetText(strTime);
  234.     pCmdUI->Enable(TRUE);
  235. ## STOP   *-*-*-* OnUpdateTime *-*-*-*
  236. ###############################################################
  237.  
  238.  
  239. ###############################################################
  240. ## PRIVATE
  241. ## BEGIN
  242. ## START  *-*-*-* InitStatusBar *-*-*-*
  243. BOOL %s::InitStatusBar(UINT *pIndicators, int nSize, int nSeconds)
  244.     // CG: This function was inserted by 'Status Bar' component.
  245.  
  246. ## STOP   *-*-*-* InitStatusBar *-*-*-*
  247. ###############################################################
  248. ## PRIVATE
  249. ## BEGIN
  250. ## START  *-*-*-* InitStatusBar *-*-*-*
  251. BOOL %s::InitStatusBar(UINT *pIndicators, int nSize, int nSeconds)
  252.     // Create an index for the DATE pane
  253.     m_nDatePaneNo = nSize++;
  254.     pIndicators[m_nDatePaneNo] = ID_INDICATOR_DATE;
  255. ## STOP   *-*-*-* InitStatusBar *-*-*-*
  256. ##-------------------------------------------------------------
  257. ## PRIVATE
  258. ## BEGIN
  259. ## START  *-*-*-* InitStatusBar *-*-*-*
  260. BOOL %s::InitStatusBar(UINT *pIndicators, int nSize, int nSeconds)
  261.     // Create an index for the TIME pane
  262.     m_nTimePaneNo = nSize++;
  263.     nSeconds = %s;
  264.     pIndicators[m_nTimePaneNo] = ID_INDICATOR_TIME;
  265. ## STOP   *-*-*-* InitStatusBar *-*-*-*
  266. ##-------------------------------------------------------------
  267. ## PRIVATE
  268. ## BEGIN
  269. ## START  *-*-*-* InitStatusBar *-*-*-*
  270. BOOL %s::InitStatusBar(UINT *pIndicators, int nSize, int nSeconds)
  271.  
  272.     // TODO: Select an appropriate time interval for updating
  273.     // the status bar when idling.
  274.     m_wndStatusBar.SetTimer(0x1000, nSeconds * 1000, NULL);
  275.  
  276.     return m_wndStatusBar.SetIndicators(pIndicators, nSize);
  277. ## STOP   *-*-*-* InitStatusBar *-*-*-*
  278. ############################################################### `  
  279.