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