Source code of Windows XP (NT5)
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.

115 lines
3.3 KiB

  1. // Copyright (C) 1996-1997 Microsoft Corporation. All rights reserved.
  2. #include "header.h"
  3. #ifdef _DEBUG
  4. #undef THIS_FILE
  5. static const char THIS_FILE[] = __FILE__;
  6. #endif
  7. #define DLG_CLASS 0x00008002
  8. HHOOK g_hHook = NULL; // Handle to the WH_CALLWNDPROC hook.
  9. HHOOK g_hCBTHook = NULL; // Handle to the WH_CBT hook.
  10. BOOL g_bPrintDlgDisplayed = FALSE; // Flag that's set when the WebBrowser print dialog has been displayed once.
  11. BOOL g_bCancel = FALSE; // Flag that's set when a dialog's cancel button has been clicked.
  12. // This is the hook procedure for the WH_CALLWNDPROC hook.
  13. LRESULT CALLBACK CHTMLPrintDlg::HookProc(int code, WPARAM wParam, LPARAM lParam)
  14. {
  15. // Call the next hook if code is less than 0. (Standard hook stuff.)
  16. if (code < 0)
  17. return ::CallNextHookEx(g_hHook, code, wParam, lParam);
  18. LPCWPSTRUCT lpMsg = (LPCWPSTRUCT) lParam;
  19. switch (lpMsg->message)
  20. {
  21. // Watch for the WebBrowser's print dialog to be initialized.
  22. case WM_INITDIALOG:
  23. {
  24. // If the print dialog has been displayed once,
  25. // simulate a click on the OK button. The CBT hook procedure
  26. // will move the dialog off of the screen, so the user
  27. // won't be able to click it.
  28. if (g_bPrintDlgDisplayed)
  29. {
  30. // Get the window handle for the OK button.
  31. HWND hOKButton = ::GetDlgItem(lpMsg->hwnd, IDOK);
  32. // Post a message to the OK button to make it
  33. // think it's been clicked.
  34. if (hOKButton != NULL)
  35. {
  36. ::PostMessage(hOKButton, WM_LBUTTONDOWN, 0, 0);
  37. ::PostMessage(hOKButton, WM_LBUTTONUP, 0, 0);
  38. }
  39. }
  40. else
  41. // If this is the first time the print dialog is being
  42. // displayed (g_bPrintDlgDisplayed == FALSE), don't simulate
  43. // the button click. The CBT hook procedure won't move the
  44. // dialog off the screen. Now that the dialog has been displayed
  45. // once, set g_bPrintDlgDisplayed to TRUE.
  46. g_bPrintDlgDisplayed = TRUE;
  47. }
  48. break;
  49. case WM_COMMAND:
  50. // If g_bPrintDlgDisplayed is TRUE (the user can see the print dialog),
  51. // watch for a click on the Cancel button. The control should stop
  52. // printing if the user clicks cancel.
  53. if (HIWORD(lpMsg->wParam) == BN_CLICKED && LOWORD(lpMsg->wParam) == IDCANCEL)
  54. g_bCancel = TRUE;
  55. }
  56. return 0;
  57. }
  58. // This is the hook procedure for the WH_CBT hook.
  59. LRESULT CALLBACK CHTMLPrintDlg::CBTHookProc(int code, WPARAM wParam, LPARAM lParam)
  60. {
  61. // Call the next hook if code is less than 0. (Standard hook stuff.)
  62. if (code < 0)
  63. return ::CallNextHookEx(g_hCBTHook, code, wParam, lParam);
  64. // Watch for the WebBrowser print dialog to be created.
  65. if (code == HCBT_CREATEWND)
  66. {
  67. LPCBT_CREATEWND lpcbtcw = (LPCBT_CREATEWND) lParam;
  68. // Make sure that it's a dialog box that's being created.
  69. // The only dialog that should be hooked is the print dialog
  70. // because the hook is installed after the main dialog and
  71. // the progress dialog have been created. Of course, if
  72. // the WebBrowser displays a message box, this would probably
  73. // hook it, so that could be a problem.
  74. if ((DWORD)lpcbtcw->lpcs->lpszClass == DLG_CLASS)
  75. {
  76. // Move the dialog off of the screen unless it's being
  77. // displayed for the first time.
  78. // BUGBUG: 13-Oct-1997 [ralphw] Check the window name to be
  79. // sure we have the right dialog box.
  80. if (g_bPrintDlgDisplayed)
  81. lpcbtcw->lpcs->x = -(lpcbtcw->lpcs->cx);
  82. }
  83. }
  84. return 0;
  85. }