Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

220 lines
6.8 KiB

  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 <afx.h>
  11. #include <afxwin.h>
  12. #include <afxdisp.h>
  13. #include <afxole.h>
  14. #include <afxpriv.h>
  15. #include "afxprntx.h"
  16. #ifdef _DEBUG
  17. #undef THIS_FILE
  18. static char THIS_FILE[] = __FILE__;
  19. #endif
  20. #define new DEBUG_NEW
  21. INT_PTR CALLBACK AfxDlgProc(HWND, UINT, WPARAM, LPARAM);
  22. /////////////////////////////////////////////////////////////////////////////
  23. // Private class to support new NT5 printing user interface
  24. //
  25. // IPrintDialogCallback interface id used by PrintDlgEx.
  26. //
  27. // {5852A2C3-6530-11D1-B6A3-0000F8757BF9}
  28. //
  29. extern "C" const __declspec(selectany) IID IID_IPrintDialogCallback =
  30. {0x5852a2c3, 0x6530, 0x11d1, {0xb6, 0xa3, 0x0, 0x0, 0xf8, 0x75, 0x7b, 0xf9}};
  31. BEGIN_INTERFACE_MAP(C_PrintDialogEx, CPrintDialog)
  32. INTERFACE_PART(C_PrintDialogEx, IID_IPrintDialogCallback, PrintDialogCallback)
  33. END_INTERFACE_MAP()
  34. C_PrintDialogEx::C_PrintDialogEx(BOOL bPrintSetupOnly,
  35. DWORD dwFlags, CWnd* pParentWnd)
  36. : CPrintDialog(bPrintSetupOnly, dwFlags, pParentWnd)
  37. {
  38. memset(&m_pdex, 0, sizeof(m_pdex));
  39. m_pdex.lStructSize = sizeof(m_pdex);
  40. m_pdex.Flags = dwFlags;
  41. }
  42. INT_PTR C_PrintDialogEx::DoModal()
  43. {
  44. ASSERT_VALID(this);
  45. m_pd.hwndOwner = PreModal();
  46. AfxUnhookWindowCreate();
  47. // expand m_pd data into the PRINTDLGEX structure
  48. m_pdex.hwndOwner = m_pd.hwndOwner;
  49. m_pdex.hDevMode = m_pd.hDevMode;
  50. m_pdex.hDevNames = m_pd.hDevNames;
  51. m_pdex.hDC = m_pd.hDC;
  52. // m_pdex.Flags = (m_pd.Flags & ~(PD_ENABLEPRINTHOOK | PD_ENABLESETUPHOOK | PD_PRINTSETUP));
  53. m_pdex.nMinPage = m_pd.nMinPage;
  54. m_pdex.nMaxPage = m_pd.nMaxPage;
  55. m_pdex.hInstance = m_pd.hInstance;
  56. m_pdex.nStartPage = START_PAGE_GENERAL;
  57. m_pdex.nCopies = m_pd.nCopies;
  58. m_pdex.lpCallback = &m_xPrintDialogCallback;
  59. // initialize page ranges
  60. PRINTPAGERANGE ourPageRange;
  61. if (m_pdex.Flags & PD_NOPAGENUMS)
  62. {
  63. m_pdex.lpPageRanges = NULL;
  64. m_pdex.nPageRanges = 0;
  65. m_pdex.nMaxPageRanges = 0;
  66. }
  67. else
  68. {
  69. ourPageRange.nFromPage = m_pd.nFromPage;
  70. ourPageRange.nToPage = m_pd.nToPage;
  71. m_pdex.nPageRanges = 1;
  72. m_pdex.nMaxPageRanges = 1;
  73. m_pdex.lpPageRanges = &ourPageRange;
  74. }
  75. HMODULE hCommDlg = GetModuleHandleA("COMDLG32.DLL");
  76. HRESULT (STDAPICALLTYPE* pfn)(LPPRINTDLGEX);
  77. #ifdef UNICODE
  78. pfn = (HRESULT (STDAPICALLTYPE*)(LPPRINTDLGEX))
  79. GetProcAddress(hCommDlg, "PrintDlgExW");
  80. #else
  81. pfn = (HRESULT (STDAPICALLTYPE*)(LPPRINTDLGEX))
  82. GetProcAddress(hCommDlg, "PrintDlgExA");
  83. #endif
  84. HRESULT hResult = E_NOTIMPL;
  85. if (pfn != NULL)
  86. {
  87. _AFX_THREAD_STATE* pThreadState = AfxGetThreadState();
  88. ASSERT(pThreadState->m_pAlternateWndInit == NULL);
  89. pThreadState->m_pAlternateWndInit = this;
  90. hResult = pfn(&m_pdex);
  91. if (SUCCEEDED(hResult))
  92. ASSERT(pThreadState->m_pAlternateWndInit == NULL);
  93. pThreadState->m_pAlternateWndInit = NULL;
  94. }
  95. // pull data back...
  96. PostModal();
  97. if (!(m_pdex.Flags & PD_NOPAGENUMS))
  98. {
  99. m_pd.nToPage = (WORD) m_pdex.lpPageRanges->nToPage;
  100. m_pd.nFromPage = (WORD) m_pdex.lpPageRanges->nFromPage;
  101. m_pd.nMinPage = (WORD) m_pdex.nMinPage;
  102. m_pd.nMaxPage = (WORD) m_pdex.nMaxPage;
  103. }
  104. m_pd.hDevMode = m_pdex.hDevMode;
  105. m_pd.hDevNames = m_pdex.hDevNames;
  106. m_pd.hDC = m_pdex.hDC;
  107. m_pd.nCopies = (WORD)m_pdex.nCopies;
  108. // calculate return code
  109. int nResult = IDCANCEL;
  110. if (SUCCEEDED(hResult))
  111. {
  112. if (m_pdex.dwResultAction == PD_RESULT_PRINT)
  113. nResult = IDOK;
  114. }
  115. return nResult;
  116. }
  117. STDMETHODIMP_(ULONG) C_PrintDialogEx::XPrintDialogCallback::AddRef()
  118. {
  119. METHOD_PROLOGUE_EX_(C_PrintDialogEx, PrintDialogCallback)
  120. return (ULONG)pThis->ExternalAddRef();
  121. }
  122. STDMETHODIMP_(ULONG) C_PrintDialogEx::XPrintDialogCallback::Release()
  123. {
  124. METHOD_PROLOGUE_EX_(C_PrintDialogEx, PrintDialogCallback)
  125. return (ULONG)pThis->ExternalRelease();
  126. }
  127. STDMETHODIMP C_PrintDialogEx::XPrintDialogCallback::QueryInterface(
  128. REFIID iid, LPVOID* ppvObj)
  129. {
  130. METHOD_PROLOGUE_EX_(C_PrintDialogEx, PrintDialogCallback)
  131. return (HRESULT)pThis->ExternalQueryInterface(&iid, ppvObj);
  132. }
  133. STDMETHODIMP C_PrintDialogEx::XPrintDialogCallback::InitDone()
  134. {
  135. METHOD_PROLOGUE_EX(C_PrintDialogEx, PrintDialogCallback)
  136. return pThis->OnInitDone();
  137. }
  138. STDMETHODIMP C_PrintDialogEx::XPrintDialogCallback::SelectionChange()
  139. {
  140. METHOD_PROLOGUE_EX(C_PrintDialogEx, PrintDialogCallback)
  141. return pThis->OnSelectionChange();
  142. }
  143. STDMETHODIMP C_PrintDialogEx::XPrintDialogCallback::HandleMessage(HWND hDlg,
  144. UINT uMsg, WPARAM wParam, LPARAM lParam, LRESULT* pResult)
  145. {
  146. METHOD_PROLOGUE_EX(C_PrintDialogEx, PrintDialogCallback)
  147. return pThis->OnHandleMessage(hDlg, uMsg, wParam, lParam, pResult);
  148. }
  149. HRESULT C_PrintDialogEx::OnInitDone()
  150. {
  151. return S_FALSE;
  152. }
  153. HRESULT C_PrintDialogEx::OnSelectionChange()
  154. {
  155. return S_FALSE;
  156. }
  157. HRESULT C_PrintDialogEx::OnHandleMessage(HWND hDlg, UINT uMsg,
  158. WPARAM wParam, LPARAM lParam, LRESULT* pResult)
  159. {
  160. UNUSED_ALWAYS(hDlg);
  161. HRESULT hResult = S_FALSE;
  162. _AFX_THREAD_STATE* pThreadState = AfxGetThreadState();
  163. if (pThreadState->m_pAlternateWndInit != NULL)
  164. {
  165. ASSERT_KINDOF(C_PrintDialogEx, pThreadState->m_pAlternateWndInit);
  166. pThreadState->m_pAlternateWndInit->SubclassWindow(hDlg);
  167. pThreadState->m_pAlternateWndInit = NULL;
  168. }
  169. ASSERT(pThreadState->m_pAlternateWndInit == NULL);
  170. if (uMsg == WM_INITDIALOG)
  171. {
  172. *pResult = AfxDlgProc(hDlg, uMsg, wParam, lParam);
  173. hResult = S_FALSE;
  174. }
  175. return hResult;
  176. }
  177. IMPLEMENT_DYNAMIC(C_PrintDialogEx, CPrintDialog)