appui.cpp 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  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. #include "stdafx.h"
  11. #ifdef AFX_CORE2_SEG
  12. #pragma code_seg(AFX_CORE2_SEG)
  13. #endif
  14. #ifdef _DEBUG
  15. #undef THIS_FILE
  16. static char THIS_FILE[] = __FILE__;
  17. #endif
  18. /////////////////////////////////////////////////////////////////////////////
  19. // CWinApp User Interface Extensions
  20. void CWinApp::OnAppExit()
  21. {
  22. // same as double-clicking on main window close box
  23. ASSERT(m_pMainWnd != NULL);
  24. m_pMainWnd->SendMessage(WM_CLOSE);
  25. }
  26. #ifdef AFX_CORE3_SEG
  27. #pragma code_seg(AFX_CORE3_SEG)
  28. #endif
  29. void CWinApp::HideApplication()
  30. {
  31. ASSERT_VALID(m_pMainWnd);
  32. // hide the application's windows before closing all the documents
  33. m_pMainWnd->ShowWindow(SW_HIDE);
  34. m_pMainWnd->ShowOwnedPopups(FALSE);
  35. // put the window at the bottom of zorder, so it isn't activated
  36. m_pMainWnd->SetWindowPos(&CWnd::wndBottom, 0, 0, 0, 0,
  37. SWP_NOMOVE|SWP_NOSIZE|SWP_NOACTIVATE);
  38. }
  39. void CWinApp::DoWaitCursor(int nCode)
  40. {
  41. // 0 => restore, 1=> begin, -1=> end
  42. ASSERT(nCode == 0 || nCode == 1 || nCode == -1);
  43. ASSERT(afxData.hcurWait != NULL);
  44. AfxLockGlobals(CRIT_WAITCURSOR);
  45. m_nWaitCursorCount += nCode;
  46. if (m_nWaitCursorCount > 0)
  47. {
  48. HCURSOR hcurPrev = ::SetCursor(afxData.hcurWait);
  49. if (nCode > 0 && m_nWaitCursorCount == 1)
  50. m_hcurWaitCursorRestore = hcurPrev;
  51. }
  52. else
  53. {
  54. // turn everything off
  55. m_nWaitCursorCount = 0; // prevent underflow
  56. ::SetCursor(m_hcurWaitCursorRestore);
  57. }
  58. AfxUnlockGlobals(CRIT_WAITCURSOR);
  59. }
  60. BOOL CWinApp::SaveAllModified()
  61. {
  62. if (m_pDocManager != NULL)
  63. return m_pDocManager->SaveAllModified();
  64. return TRUE;
  65. }
  66. void CWinApp::AddToRecentFileList(LPCTSTR lpszPathName)
  67. {
  68. ASSERT_VALID(this);
  69. ASSERT(lpszPathName != NULL);
  70. ASSERT(AfxIsValidString(lpszPathName));
  71. if (m_pRecentFileList != NULL)
  72. m_pRecentFileList->Add(lpszPathName);
  73. }
  74. CDocument* CWinApp::OpenDocumentFile(LPCTSTR lpszFileName)
  75. {
  76. ASSERT(m_pDocManager != NULL);
  77. return m_pDocManager->OpenDocumentFile(lpszFileName);
  78. }
  79. void CWinApp::CloseAllDocuments(BOOL bEndSession)
  80. {
  81. if (m_pDocManager != NULL)
  82. m_pDocManager->CloseAllDocuments(bEndSession);
  83. }
  84. /////////////////////////////////////////////////////////////////////////////
  85. // MRU file list default implementation
  86. void CWinApp::OnUpdateRecentFileMenu(CCmdUI* pCmdUI)
  87. {
  88. ASSERT_VALID(this);
  89. if (m_pRecentFileList == NULL) // no MRU files
  90. pCmdUI->Enable(FALSE);
  91. else
  92. m_pRecentFileList->UpdateMenu(pCmdUI);
  93. }
  94. /////////////////////////////////////////////////////////////////////////////
  95. // DDE and ShellExecute support
  96. BOOL CWinApp::OnDDECommand(LPTSTR lpszCommand)
  97. {
  98. if (m_pDocManager != NULL)
  99. return m_pDocManager->OnDDECommand(lpszCommand);
  100. else
  101. return FALSE;
  102. }
  103. /////////////////////////////////////////////////////////////////////////////
  104. // MRU file list default implementation
  105. BOOL CWinApp::OnOpenRecentFile(UINT nID)
  106. {
  107. ASSERT_VALID(this);
  108. ASSERT(m_pRecentFileList != NULL);
  109. ASSERT(nID >= ID_FILE_MRU_FILE1);
  110. ASSERT(nID < ID_FILE_MRU_FILE1 + (UINT)m_pRecentFileList->GetSize());
  111. int nIndex = nID - ID_FILE_MRU_FILE1;
  112. ASSERT((*m_pRecentFileList)[nIndex].GetLength() != 0);
  113. TRACE2("MRU: open file (%d) '%s'.\n", (nIndex) + 1,
  114. (LPCTSTR)(*m_pRecentFileList)[nIndex]);
  115. if (OpenDocumentFile((*m_pRecentFileList)[nIndex]) == NULL)
  116. m_pRecentFileList->Remove(nIndex);
  117. return TRUE;
  118. }
  119. /////////////////////////////////////////////////////////////////////////////