oledlgs2.cpp 4.5 KB

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