I have a CHtmlView
derived class. My menu has a Print Preview
menu item. That event handler creates a special print preview derived document, and then it gets displayed:
void CChristianLifeMinistryHtmlView::DoPrintPreview()
{
HWND HWND_PP, HWND_FG ;
TCHAR szClassName[256] ;
ULONGLONG t1, t2 ;
RECT workArea;
ExecWB(OLECMDID_PRINTPREVIEW, OLECMDEXECOPT_PROMPTUSER, nullptr, nullptr);
HWND_PP = nullptr ;
t1 = ::GetTickCount64();
t2 = ::GetTickCount64(); // Extra line required for 'while' rearrangement.
while (HWND_PP == nullptr && t2 - t1 <= 6000) // if found or Timeout reached...
{
HWND_FG = ::GetForegroundWindow(); // Get the ForeGroundWindow
if (HWND_FG != nullptr)
{
::GetClassName(HWND_FG, szClassName, 256 );
if (lstrcmp(szClassName, IE_PPREVIEWCLASS) == 0) // Check for Print Preview Dialog
HWND_PP = HWND_FG ;
}
theApp.PumpMessage();
t2 = ::GetTickCount64();
}
if (HWND_PP != nullptr)
{
// AJT V3.01 BUG Fix - showing maximized crops bottom of preview dialog
::SystemParametersInfo( SPI_GETWORKAREA, 0, &workArea, 0 );
::MoveWindow(HWND_PP, workArea.left, workArea.top,
workArea.right - workArea.left, workArea.bottom - workArea.top, TRUE);
}
}
This works fine. I have zero problems with it. The problem is if the user right-clicks the actual view and chooses print from there:
I don't know how to intercept this menu entry. Ideally it needs to redirect the action back to my main dialog so it can do the print preview correctly.
I don't want to disable the context menu because it has other choices there that are useful, like, view source. But I would like to add my own behaviour for the context menu print and print preview actions.
Is this possible?
Just wondered if anyone else has had success with this?
This question relates to: