EDN Admin
Well-known member
I am trying to move a Windows application from a XP machine with IE7 to a Windows 7 machine with IE 9. Application was recently rebuild using VS 2008 sp1 with framework 3.5. (Originally developed on VS 2003 with .net 1.1) The Print project of the application
uses IWebBrowser2 for the purpose of printing html documents. Basic flow is to Initialize the control, navigate to about:blank, keep window invisible, navigate to actual html page in windows temp folder that needs to be printed. Call ExecWB on browser
to print. Works fine on XP/IE7 but porting application to Win 7/IE9 breaks printing functionality. First issue noticed is when calling Navigate to html document (2nd call to Navigate, first to about:blank is fine), instead of being invisible the document appears
on screen. I can make it invisible again but the real issue is once <span style="font-size:small
browser->ExecWB is called the content of the html document is not sent to printer. I get the header and footer from the templae but the rest of the html document is empty. Some code snippets below. Any help would be greatly appreciated. thx. Serge
private: void Init()<br/>
{<br/>
this->m_browser->put_RegisterAsBrowser(VARIANT_FALSE);<br/>
this->m_browser->put_RegisterAsDropTarget(VARIANT_FALSE);<br/>
this->m_browser->put_Silent(VARIANT_FALSE);
this->m_browser->put_AddressBar(VARIANT_FALSE);<br/>
this->m_browser->put_MenuBar(VARIANT_FALSE);<br/>
this->m_browser->put_ToolBar(VARIANT_FALSE);<br/>
this->m_browser->put_Visible(VARIANT_FALSE);
this->DecorateBrowserWindow();<br/>
this->NavigateInternal(__gc new System::Uri(S"about:blank"));<br/>
}
private: void DecorateBrowserWindow()<br/>
{<br/>
HWND hWnd = this->GetBrowserWindowHandle();<br/>
::SetWindowLong(hWnd, GWL_EXSTYLE, WS_EX_TOOLWINDOW);<br/>
::SetWindowPos(hWnd, HWND_BOTTOM, 0, 0, 0, 0, SWP_HIDEWINDOW);<br/>
}
private: void NavigateInternal(System::Uri __gc *uri)<br/>
{<br/>
Logger::Append(uri->AbsoluteUri);<br/>
BSTR bstrUri = NativeTypes::ConvertToBSTR(uri->AbsoluteUri);
HRESULT hr = ::EY_Navigate(this->m_browser, &bstrUri);<br/>
NativeTypes::Release(bstrUri);<br/>
this->Wait();
if(hr == S_OK)<br/>
{<br/>
::Sleep(100);<br/>
}<br/>
}
HRESULT EY_Navigate(IWebBrowser2 *browser, BSTR *uri)<br/>
{<br/>
VARIANT var;<br/>
::VariantInit(&var);
HRESULT hr = browser->Navigate<br/>
(<br/>
*uri,<br/>
&var,<br/>
&var,<br/>
&var,<br/>
&var<br/>
);
return hr;<br/>
}
<br/>
private: void MyPrintInternal(System::Uri __gc *uri, System::IO::FileInfo __gc *printTemplate, OLECMDID commandId)<br/>
{<br/>
this->NavigateInternal(uri);
VARIANT *v = NativeTypes::ConvertToVariant(printTemplate->FullName);<br/>
::EY_Print(this->m_browser, commandId, *v);<br/>
NativeTypes::Release(v);<br/>
}
HRESULT EY_Print(IWebBrowser2 *browser, OLECMDID commandId, VARIANT pvaIn)<br/>
{<br/>
VARIANT var;<br/>
::VariantInit(&var);
HRESULT hr = browser->ExecWB<br/>
(<br/>
commandId,<br/>
OLECMDEXECOPT_DONTPROMPTUSER,<br/>
&pvaIn,<br/>
&var<br/>
);<br/>
return hr;<br/>
}
View the full article
uses IWebBrowser2 for the purpose of printing html documents. Basic flow is to Initialize the control, navigate to about:blank, keep window invisible, navigate to actual html page in windows temp folder that needs to be printed. Call ExecWB on browser
to print. Works fine on XP/IE7 but porting application to Win 7/IE9 breaks printing functionality. First issue noticed is when calling Navigate to html document (2nd call to Navigate, first to about:blank is fine), instead of being invisible the document appears
on screen. I can make it invisible again but the real issue is once <span style="font-size:small
browser->ExecWB is called the content of the html document is not sent to printer. I get the header and footer from the templae but the rest of the html document is empty. Some code snippets below. Any help would be greatly appreciated. thx. Serge
private: void Init()<br/>
{<br/>
this->m_browser->put_RegisterAsBrowser(VARIANT_FALSE);<br/>
this->m_browser->put_RegisterAsDropTarget(VARIANT_FALSE);<br/>
this->m_browser->put_Silent(VARIANT_FALSE);
this->m_browser->put_AddressBar(VARIANT_FALSE);<br/>
this->m_browser->put_MenuBar(VARIANT_FALSE);<br/>
this->m_browser->put_ToolBar(VARIANT_FALSE);<br/>
this->m_browser->put_Visible(VARIANT_FALSE);
this->DecorateBrowserWindow();<br/>
this->NavigateInternal(__gc new System::Uri(S"about:blank"));<br/>
}
private: void DecorateBrowserWindow()<br/>
{<br/>
HWND hWnd = this->GetBrowserWindowHandle();<br/>
::SetWindowLong(hWnd, GWL_EXSTYLE, WS_EX_TOOLWINDOW);<br/>
::SetWindowPos(hWnd, HWND_BOTTOM, 0, 0, 0, 0, SWP_HIDEWINDOW);<br/>
}
private: void NavigateInternal(System::Uri __gc *uri)<br/>
{<br/>
Logger::Append(uri->AbsoluteUri);<br/>
BSTR bstrUri = NativeTypes::ConvertToBSTR(uri->AbsoluteUri);
HRESULT hr = ::EY_Navigate(this->m_browser, &bstrUri);<br/>
NativeTypes::Release(bstrUri);<br/>
this->Wait();
if(hr == S_OK)<br/>
{<br/>
::Sleep(100);<br/>
}<br/>
}
HRESULT EY_Navigate(IWebBrowser2 *browser, BSTR *uri)<br/>
{<br/>
VARIANT var;<br/>
::VariantInit(&var);
HRESULT hr = browser->Navigate<br/>
(<br/>
*uri,<br/>
&var,<br/>
&var,<br/>
&var,<br/>
&var<br/>
);
return hr;<br/>
}
<br/>
private: void MyPrintInternal(System::Uri __gc *uri, System::IO::FileInfo __gc *printTemplate, OLECMDID commandId)<br/>
{<br/>
this->NavigateInternal(uri);
VARIANT *v = NativeTypes::ConvertToVariant(printTemplate->FullName);<br/>
::EY_Print(this->m_browser, commandId, *v);<br/>
NativeTypes::Release(v);<br/>
}
HRESULT EY_Print(IWebBrowser2 *browser, OLECMDID commandId, VARIANT pvaIn)<br/>
{<br/>
VARIANT var;<br/>
::VariantInit(&var);
HRESULT hr = browser->ExecWB<br/>
(<br/>
commandId,<br/>
OLECMDEXECOPT_DONTPROMPTUSER,<br/>
&pvaIn,<br/>
&var<br/>
);<br/>
return hr;<br/>
}
View the full article