appui1.cpp 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  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_CORE3_SEG
  12. #pragma code_seg(AFX_CORE3_SEG)
  13. #endif
  14. #ifdef _DEBUG
  15. #undef THIS_FILE
  16. static char THIS_FILE[] = __FILE__;
  17. #endif
  18. /////////////////////////////////////////////////////////////////////////////
  19. // CWinApp UI related functions
  20. void CWinApp::EnableModeless(BOOL bEnable)
  21. {
  22. #ifdef _AFX_NO_OLE_SUPPORT
  23. UNUSED(bEnable);
  24. #endif
  25. // no-op if main window is NULL or not a CFrameWnd
  26. CWnd* pMainWnd = AfxGetMainWnd();
  27. if (pMainWnd == NULL || !pMainWnd->IsFrameWnd())
  28. return;
  29. #ifndef _AFX_NO_OLE_SUPPORT
  30. /*// check if notify hook installed
  31. ASSERT_KINDOF(CFrameWnd, pMainWnd);
  32. CFrameWnd* pFrameWnd = (CFrameWnd*)pMainWnd;
  33. if (pFrameWnd->m_pNotifyHook != NULL)
  34. pFrameWnd->m_pNotifyHook->OnEnableModeless(bEnable);*/
  35. #endif
  36. }
  37. int CWinApp::DoMessageBox(LPCTSTR lpszPrompt, UINT nType, UINT nIDPrompt)
  38. {
  39. // disable windows for modal dialog
  40. EnableModeless(FALSE);
  41. HWND hWndTop;
  42. HWND hWnd = CWnd::GetSafeOwner_(NULL, &hWndTop);
  43. // set help context if possible
  44. DWORD* pdwContext = NULL;
  45. if (hWnd != NULL)
  46. {
  47. // use app-level context or frame level context
  48. LRESULT lResult = ::SendMessage(hWndTop, WM_HELPPROMPTADDR, 0, 0);
  49. if (lResult != 0)
  50. pdwContext = (DWORD*)lResult;
  51. }
  52. // for backward compatibility use app context if possible
  53. if (pdwContext == NULL && this != NULL)
  54. pdwContext = &m_dwPromptContext;
  55. DWORD dwOldPromptContext = 0;
  56. if (pdwContext != NULL)
  57. {
  58. // save old prompt context for restoration later
  59. dwOldPromptContext = *pdwContext;
  60. if (nIDPrompt != 0)
  61. *pdwContext = HID_BASE_PROMPT+nIDPrompt;
  62. }
  63. // determine icon based on type specified
  64. if ((nType & MB_ICONMASK) == 0)
  65. {
  66. switch (nType & MB_TYPEMASK)
  67. {
  68. case MB_OK:
  69. case MB_OKCANCEL:
  70. nType |= MB_ICONEXCLAMATION;
  71. break;
  72. case MB_YESNO:
  73. case MB_YESNOCANCEL:
  74. nType |= MB_ICONEXCLAMATION;
  75. break;
  76. case MB_ABORTRETRYIGNORE:
  77. case MB_RETRYCANCEL:
  78. // No default icon for these types, since they are rarely used.
  79. // The caller should specify the icon.
  80. break;
  81. }
  82. }
  83. #ifdef _DEBUG
  84. if ((nType & MB_ICONMASK) == 0)
  85. TRACE0("Warning: no icon specified for message box.\n");
  86. #endif
  87. TCHAR szAppName[_MAX_PATH];
  88. LPCTSTR pszAppName;
  89. if (this != NULL)
  90. pszAppName = m_pszAppName;
  91. else
  92. {
  93. pszAppName = szAppName;
  94. GetModuleFileName(NULL, szAppName, _MAX_PATH);
  95. }
  96. int nResult =
  97. ::MessageBox(hWnd, lpszPrompt, pszAppName, nType);
  98. // restore prompt context if possible
  99. if (pdwContext != NULL)
  100. *pdwContext = dwOldPromptContext;
  101. // re-enable windows
  102. if (hWndTop != NULL)
  103. ::EnableWindow(hWndTop, TRUE);
  104. EnableModeless(TRUE);
  105. return nResult;
  106. }
  107. int AFXAPI AfxMessageBox(LPCTSTR lpszText, UINT nType, UINT nIDHelp)
  108. {
  109. CWinApp* pApp = AfxGetApp();
  110. if (pApp != NULL)
  111. return pApp->DoMessageBox(lpszText, nType, nIDHelp);
  112. else
  113. return pApp->CWinApp::DoMessageBox(lpszText, nType, nIDHelp);
  114. }
  115. int AFXAPI AfxMessageBox(UINT nIDPrompt, UINT nType, UINT nIDHelp)
  116. {
  117. CString string;
  118. if (!string.LoadString(nIDPrompt))
  119. {
  120. TRACE1("Error: failed to load message box prompt string 0x%04x.\n",
  121. nIDPrompt);
  122. ASSERT(FALSE);
  123. }
  124. if (nIDHelp == (UINT)-1)
  125. nIDHelp = nIDPrompt;
  126. return AfxMessageBox(string, nType, nIDHelp);
  127. }
  128. ////////////////////////////////////////////////////////////////////////////
  129. // UI related CWnd functions
  130. HWND PASCAL CWnd::GetSafeOwner_(HWND hParent, HWND* pWndTop)
  131. {
  132. // get window to start with
  133. HWND hWnd = hParent;
  134. /*if (hWnd == NULL)
  135. {
  136. CFrameWnd* pFrame = CCmdTarget::GetRoutingFrame_();
  137. if (pFrame != NULL)
  138. hWnd = pFrame->GetSafeHwnd();
  139. else
  140. hWnd = AfxGetMainWnd()->GetSafeHwnd();
  141. }*/
  142. // a popup window cannot be owned by a child window
  143. while (hWnd != NULL && (::GetWindowLong(hWnd, GWL_STYLE) & WS_CHILD))
  144. hWnd = ::GetParent(hWnd);
  145. // determine toplevel window to disable as well
  146. HWND hWndTop = hWnd, hWndTemp = hWnd;
  147. for (;;)
  148. {
  149. if (hWndTemp == NULL)
  150. break;
  151. else
  152. hWndTop = hWndTemp;
  153. hWndTemp = ::GetParent(hWndTop);
  154. }
  155. // get last active popup of first non-child that was found
  156. if (hParent == NULL && hWnd != NULL)
  157. hWnd = ::GetLastActivePopup(hWnd);
  158. // disable and store top level parent window if specified
  159. if (pWndTop != NULL)
  160. {
  161. if (hWndTop != NULL && ::IsWindowEnabled(hWndTop) && hWndTop != hWnd)
  162. {
  163. *pWndTop = hWndTop;
  164. ::EnableWindow(hWndTop, FALSE);
  165. }
  166. else
  167. *pWndTop = NULL;
  168. }
  169. return hWnd; // return the owner as HWND
  170. }
  171. /////////////////////////////////////////////////////////////////////////////
  172. // UI related CCmdTarget functions
  173. CView* PASCAL CCmdTarget::GetRoutingView_()
  174. {
  175. CView* pView = AfxGetThreadState()->m_pRoutingView;
  176. if (pView != NULL)
  177. ASSERT_VALID(pView);
  178. return pView;
  179. }
  180. CFrameWnd* PASCAL CCmdTarget::GetRoutingFrame_()
  181. {
  182. /*CFrameWnd* pFrame = AfxGetThreadState()->m_pRoutingFrame;
  183. if (pFrame != NULL)
  184. ASSERT_VALID(pFrame);
  185. return pFrame;*/
  186. return NULL;
  187. }
  188. /////////////////////////////////////////////////////////////////////////////