home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Windows Gam…ming Gurus (2nd Edition) / Disc2.iso / vc98 / mfc / src / appui.cpp < prev    next >
C/C++ Source or Header  |  1998-06-16  |  4KB  |  147 lines

  1. // This is a part of the Microsoft Foundation Classes C++ library.
  2. // Copyright (C) 1992-1998 Microsoft Corporation
  3. // All rights reserved.
  4. //
  5. // This source code is only intended as a supplement to the
  6. // Microsoft Foundation Classes Reference and related
  7. // electronic documentation provided with the library.
  8. // See these sources for detailed information regarding the
  9. // Microsoft Foundation Classes product.
  10.  
  11. #include "stdafx.h"
  12.  
  13. #ifdef AFX_CORE2_SEG
  14. #pragma code_seg(AFX_CORE2_SEG)
  15. #endif
  16.  
  17. #ifdef _DEBUG
  18. #undef THIS_FILE
  19. static char THIS_FILE[] = __FILE__;
  20. #endif
  21.  
  22. /////////////////////////////////////////////////////////////////////////////
  23. // CWinApp User Interface Extensions
  24.  
  25. void CWinApp::OnAppExit()
  26. {
  27.     // same as double-clicking on main window close box
  28.     ASSERT(m_pMainWnd != NULL);
  29.     m_pMainWnd->SendMessage(WM_CLOSE);
  30. }
  31.  
  32. #ifdef AFX_CORE3_SEG
  33. #pragma code_seg(AFX_CORE3_SEG)
  34. #endif
  35.  
  36. void CWinApp::HideApplication()
  37. {
  38.     ASSERT_VALID(m_pMainWnd);
  39.  
  40.     // hide the application's windows before closing all the documents
  41.     m_pMainWnd->ShowWindow(SW_HIDE);
  42.     m_pMainWnd->ShowOwnedPopups(FALSE);
  43.  
  44.     // put the window at the bottom of zorder, so it isn't activated
  45.     m_pMainWnd->SetWindowPos(&CWnd::wndBottom, 0, 0, 0, 0,
  46.         SWP_NOMOVE|SWP_NOSIZE|SWP_NOACTIVATE);
  47. }
  48.  
  49. void CWinApp::DoWaitCursor(int nCode)
  50. {
  51.     // 0 => restore, 1=> begin, -1=> end
  52.     ASSERT(nCode == 0 || nCode == 1 || nCode == -1);
  53.     ASSERT(afxData.hcurWait != NULL);
  54.     AfxLockGlobals(CRIT_WAITCURSOR);
  55.     m_nWaitCursorCount += nCode;
  56.     if (m_nWaitCursorCount > 0)
  57.     {
  58.         HCURSOR hcurPrev = ::SetCursor(afxData.hcurWait);
  59.         if (nCode > 0 && m_nWaitCursorCount == 1)
  60.             m_hcurWaitCursorRestore = hcurPrev;
  61.     }
  62.     else
  63.     {
  64.         // turn everything off
  65.         m_nWaitCursorCount = 0;     // prevent underflow
  66.         ::SetCursor(m_hcurWaitCursorRestore);
  67.     }
  68.     AfxUnlockGlobals(CRIT_WAITCURSOR);
  69. }
  70.  
  71.  
  72. BOOL CWinApp::SaveAllModified()
  73. {
  74.     if (m_pDocManager != NULL)
  75.         return m_pDocManager->SaveAllModified();
  76.     return TRUE;
  77. }
  78.  
  79. void CWinApp::AddToRecentFileList(LPCTSTR lpszPathName)
  80. {
  81.     ASSERT_VALID(this);
  82.     ASSERT(lpszPathName != NULL);
  83.     ASSERT(AfxIsValidString(lpszPathName));
  84.  
  85.     if (m_pRecentFileList != NULL)
  86.         m_pRecentFileList->Add(lpszPathName);
  87. }
  88.  
  89. CDocument* CWinApp::OpenDocumentFile(LPCTSTR lpszFileName)
  90. {
  91.     ASSERT(m_pDocManager != NULL);
  92.     return m_pDocManager->OpenDocumentFile(lpszFileName);
  93. }
  94.  
  95. void CWinApp::CloseAllDocuments(BOOL bEndSession)
  96. {
  97.     if (m_pDocManager != NULL)
  98.         m_pDocManager->CloseAllDocuments(bEndSession);
  99. }
  100.  
  101. /////////////////////////////////////////////////////////////////////////////
  102. // MRU file list default implementation
  103.  
  104. void CWinApp::OnUpdateRecentFileMenu(CCmdUI* pCmdUI)
  105. {
  106.     ASSERT_VALID(this);
  107.     if (m_pRecentFileList == NULL) // no MRU files
  108.         pCmdUI->Enable(FALSE);
  109.     else
  110.         m_pRecentFileList->UpdateMenu(pCmdUI);
  111. }
  112.  
  113. /////////////////////////////////////////////////////////////////////////////
  114. // DDE and ShellExecute support
  115.  
  116. BOOL CWinApp::OnDDECommand(LPTSTR lpszCommand)
  117. {
  118.     if (m_pDocManager != NULL)
  119.         return m_pDocManager->OnDDECommand(lpszCommand);
  120.     else
  121.         return FALSE;
  122. }
  123.  
  124. /////////////////////////////////////////////////////////////////////////////
  125. // MRU file list default implementation
  126.  
  127. BOOL CWinApp::OnOpenRecentFile(UINT nID)
  128. {
  129.     ASSERT_VALID(this);
  130.     ASSERT(m_pRecentFileList != NULL);
  131.  
  132.     ASSERT(nID >= ID_FILE_MRU_FILE1);
  133.     ASSERT(nID < ID_FILE_MRU_FILE1 + (UINT)m_pRecentFileList->GetSize());
  134.     int nIndex = nID - ID_FILE_MRU_FILE1;
  135.     ASSERT((*m_pRecentFileList)[nIndex].GetLength() != 0);
  136.  
  137.     TRACE2("MRU: open file (%d) '%s'.\n", (nIndex) + 1,
  138.             (LPCTSTR)(*m_pRecentFileList)[nIndex]);
  139.  
  140.     if (OpenDocumentFile((*m_pRecentFileList)[nIndex]) == NULL)
  141.         m_pRecentFileList->Remove(nIndex);
  142.  
  143.     return TRUE;
  144. }
  145.  
  146. /////////////////////////////////////////////////////////////////////////////
  147.