home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Windows Gam…ming Gurus (2nd Edition) / Disc2.iso / vc98 / mfc / src / oledlgs2.cpp < prev    next >
C/C++ Source or Header  |  1998-06-16  |  5KB  |  173 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_OLE2_SEG
  14. #pragma code_seg(AFX_OLE2_SEG)
  15. #endif
  16.  
  17. #ifdef _DEBUG
  18. #undef THIS_FILE
  19. static char THIS_FILE[] = __FILE__;
  20. #endif
  21.  
  22. #define new DEBUG_NEW
  23.  
  24. /////////////////////////////////////////////////////////////////////////////
  25. // Common code for all OLE UI dialogs
  26.  
  27. UINT CALLBACK
  28. AfxOleHookProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
  29. {
  30.     if (message == WM_INITDIALOG)
  31.         return (UINT)AfxDlgProc(hWnd, message, wParam, lParam);
  32.  
  33.     if (message == WM_COMMAND && LOWORD(wParam) == IDC_OLEUIHELP)
  34.     {
  35.         // just translate the message into the AFX standard help command.
  36.         SendMessage(hWnd, WM_COMMAND, ID_HELP, 0);
  37.         return TRUE;
  38.     }
  39.     return 0;
  40. }
  41.  
  42. /////////////////////////////////////////////////////////////////////////////
  43.  
  44. COleDialog::COleDialog(CWnd* pParentWnd) : CCommonDialog(pParentWnd)
  45. {
  46.     m_nLastError = (UINT)-1;       // no error
  47. }
  48.  
  49. int COleDialog::MapResult(UINT nResult)
  50. {
  51.     // store it for GetLastError()
  52.     m_nLastError = nResult;
  53.  
  54.     // map OLEUI_OK & OLEUI_CANCEL to IDOK & IDCANCEL
  55.     if (nResult == OLEUI_OK)
  56.         return IDOK;
  57.     if (nResult == OLEUI_CANCEL)
  58.         return IDCANCEL;
  59.  
  60.     // otherwise, some sort of error
  61.     return -1;
  62. }
  63.  
  64. /////////////////////////////////////////////////////////////////////////////
  65. // COleDialog diagnostics
  66.  
  67. #ifdef _DEBUG
  68. void COleDialog::Dump(CDumpContext& dc) const
  69. {
  70.     CDialog::Dump(dc);
  71.  
  72.     dc << "m_nLastError = " << m_nLastError;
  73.     dc << "\n";
  74. }
  75. #endif //_DEBUG
  76.  
  77. /////////////////////////////////////////////////////////////////////////////
  78. // COleBusyDialog implementation
  79.  
  80. COleBusyDialog::COleBusyDialog(HTASK htaskBlocking, BOOL bNotResponding,
  81.     DWORD dwFlags, CWnd* pParentWnd) : COleDialog(pParentWnd)
  82. {
  83.     memset(&m_bz, 0, sizeof(m_bz)); // initialize structure to 0/NULL
  84.  
  85.     // fill in common part
  86.     m_bz.cbStruct = sizeof(m_bz);
  87.     m_bz.dwFlags = dwFlags;
  88.     if (bNotResponding)
  89.         m_bz.dwFlags |= BZ_NOTRESPONDINGDIALOG;
  90.     m_bz.lpfnHook = AfxOleHookProc;
  91.  
  92.     // specific for this dialog
  93.     m_bz.hTask = htaskBlocking;
  94.  
  95.     ASSERT_VALID(this);
  96. }
  97.  
  98. COleBusyDialog::~COleBusyDialog()
  99. {
  100. }
  101.  
  102. int COleBusyDialog::DoModal()
  103. {
  104.     // Note: we don't call EnableModeless because that in itself implies
  105.     //  outgoing calls.  This dialog is normally brought up when an outgoing
  106.     //  call cannot be made.
  107.  
  108.     // find parent HWND
  109.     HWND hWndTop;
  110.     HWND hParent = CWnd::GetSafeOwner_(m_pParentWnd->GetSafeHwnd(), &hWndTop);
  111.     m_bz.hWndOwner = hParent;
  112.  
  113.     // run the dialog
  114.     AfxHookWindowCreate(this);
  115.     int iResult = ::OleUIBusy(&m_bz);
  116.     AfxUnhookWindowCreate();   // just in case
  117.     Detach();   // just in case
  118.  
  119.     // enable top level window
  120.     if (hWndTop != NULL)
  121.         ::EnableWindow(hWndTop, TRUE);
  122.  
  123.     // map the result
  124.     if (iResult == OLEUI_CANCEL)
  125.         return IDCANCEL;
  126.  
  127.     if (iResult == OLEUI_BZ_SWITCHTOSELECTED)
  128.         m_selection = switchTo;
  129.     else if (iResult == OLEUI_BZ_RETRYSELECTED)
  130.         m_selection = retry;
  131.     else if (iResult == OLEUI_BZ_CALLUNBLOCKED)
  132.         m_selection = callUnblocked;
  133.     else
  134.         m_selection = (Selection)MapResult(iResult);
  135.  
  136.     return IDOK;
  137. }
  138.  
  139. /////////////////////////////////////////////////////////////////////////////
  140. // COleBusyDialog diagnostics
  141.  
  142. #ifdef _DEBUG
  143. void COleBusyDialog::Dump(CDumpContext& dc) const
  144. {
  145.     COleDialog::Dump(dc);
  146.  
  147.     dc << "m_bz.cbStruct = " << m_bz.cbStruct;
  148.     dc << "\nm_bz.dwFlags = " << (LPVOID)m_bz.dwFlags;
  149.     dc << "\nm_bz.hWndOwner = " << (UINT)m_bz.hWndOwner;
  150.     dc << "\nm_bz.lpszCaption = " << m_bz.lpszCaption;
  151.     dc << "\nm_bz.lCustData = " << (LPVOID)m_bz.lCustData;
  152.     dc << "\nm_bz.hInstance = " << (UINT)m_bz.hInstance;
  153.     dc << "\nm_bz.lpszTemplate = " << (LPVOID)m_bz.lpszTemplate;
  154.     dc << "\nm_bz.hResource = " << (UINT)m_bz.hResource;
  155.     if (m_bz.lpfnHook == AfxOleHookProc)
  156.         dc << "\nhook function set to standard MFC hook function";
  157.     else
  158.         dc << "\nhook function set to non-standard hook function";
  159.     dc << "\nm_bz.hTask = " << (UINT)m_bz.hTask;
  160.  
  161.     dc << "\n";
  162. }
  163. #endif
  164.  
  165. #ifdef AFX_INIT_SEG
  166. #pragma code_seg(AFX_INIT_SEG)
  167. #endif
  168.  
  169. IMPLEMENT_DYNAMIC(COleDialog, CDialog)
  170. IMPLEMENT_DYNAMIC(COleBusyDialog, COleDialog)
  171.  
  172. /////////////////////////////////////////////////////////////////////////////
  173.