markoj
asked on
Printing from IExplorer 4.0
I would like to print a frame from IE 4.0 when user clicks the print button. How would I do this? Using a ActiveX component. If so - which one? If possible I'd like to do it without any programming. I've some code, but I don't know how to use it from IE.
void CAboutDlg::OnPrint()
{
CWnd* pWnd = GetFocus ();
m_ctlWebBrowser.SetFocus ();
// send Ctrl-P
keybd_event (VK_CONTROL, 0, 0, 0);
keybd_event ('P', 0, 0, 0);
// set focus to control that previously had focus
if (pWnd);
pWnd->SetFocus ();
}
Telling me how to use this code would answer my question as well.
void CAboutDlg::OnPrint()
{
CWnd* pWnd = GetFocus ();
m_ctlWebBrowser.SetFocus ();
// send Ctrl-P
keybd_event (VK_CONTROL, 0, 0, 0);
keybd_event ('P', 0, 0, 0);
// set focus to control that previously had focus
if (pWnd);
pWnd->SetFocus ();
}
Telling me how to use this code would answer my question as well.
ASKER
As I can see, the printer friendly version of news.com is just the version of the same text, designed it better looks when printed. But you still have to do printing via menus. I want to enable printing from my page itself. I want to have a big colorful button on it with "Print" written all over it. When the user will click it, I want the page to be printed without any questions.
with Netscape 4.x, you can use windowreference.print()
Maybe this works for IE4, as well
Maybe this works for IE4, as well
The given code is part of a C++ Class, and it does the following three steps:
1. Remember where the windows caret is active before hitting Ctrl-P.
2. Send a CTRL-P keyboard event, which should be handled else where.
3. Reset the Windows Caret to it's previously active control
In many Windows applications, the Ctrl-P is a shortcut for Print, so hitting Ctrl-P is the best answer to your question.
Christian Wenz is right about the Netscape 4.0, but this is vendor dependent. There's no standard for doing the trick you want.
1. Remember where the windows caret is active before hitting Ctrl-P.
2. Send a CTRL-P keyboard event, which should be handled else where.
3. Reset the Windows Caret to it's previously active control
In many Windows applications, the Ctrl-P is a shortcut for Print, so hitting Ctrl-P is the best answer to your question.
Christian Wenz is right about the Netscape 4.0, but this is vendor dependent. There's no standard for doing the trick you want.
ASKER
I sure understand what the code above does. With the print button I mean a GIF on the page.
At this point I simply use the ActiveX IE component to perform the task.
At this point I simply use the ActiveX IE component to perform the task.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
This will work from IE 4.0 (I've tested it)
Basically, it uses VBscript to access the IE 4 object and send it a command to print.
IE 3.0 is a bit different. Do you by any chance know how to do it in IE 3.0?
<html>
<script LANGUAGE="VBScript">
sub Print
const OLECMDID_PRINT = 6
const OLECMDEXECOPT_DONTPROMPTUS ER = 2
const OLECMDEXECOPT_PROMPTUSER = 1
Webbrowser1.ExecWB OLECMDID_PRINT, OLECMDEXECOPT_PROMPTUSER
end sub
</script>
<object ID="WebBrowser1" WIDTH="0" HEIGHT="0"
CLASSID="CLSID:8856F961-34 0A-11D0-A9 6B-00C04FD 705A2">
</object>
<head>
<title></title>
</head>
<body>
<p><script LANGUAGE="VBScript">
<!--
Sub PrintMe_Click()
call Print()
end sub
-->
</script> </p>
<form ACTION="--WEBBOT-SELF--" METHOD="POST">
<!--webbot bot="SaveResults" startspan U-File="_private/form_resu lts.txt"
S-Format="TEXT/CSV" S-Label-Fields="TRUE" --><!--webbot bot="SaveResults" endspan --><p><input
LANGUAGE="VBScript" TYPE="button" VALUE="PrintMe" ONCLICK="call Print()" NAME="btnPrint"> </p>
</form>
</body>
</html>
Basically, it uses VBscript to access the IE 4 object and send it a command to print.
IE 3.0 is a bit different. Do you by any chance know how to do it in IE 3.0?
<html>
<script LANGUAGE="VBScript">
sub Print
const OLECMDID_PRINT = 6
const OLECMDEXECOPT_DONTPROMPTUS
const OLECMDEXECOPT_PROMPTUSER = 1
Webbrowser1.ExecWB OLECMDID_PRINT, OLECMDEXECOPT_PROMPTUSER
end sub
</script>
<object ID="WebBrowser1" WIDTH="0" HEIGHT="0"
CLASSID="CLSID:8856F961-34
</object>
<head>
<title></title>
</head>
<body>
<p><script LANGUAGE="VBScript">
<!--
Sub PrintMe_Click()
call Print()
end sub
-->
</script> </p>
<form ACTION="--WEBBOT-SELF--" METHOD="POST">
<!--webbot bot="SaveResults" startspan U-File="_private/form_resu
S-Format="TEXT/CSV" S-Label-Fields="TRUE" --><!--webbot bot="SaveResults" endspan --><p><input
LANGUAGE="VBScript" TYPE="button" VALUE="PrintMe" ONCLICK="call Print()" NAME="btnPrint"> </p>
</form>
</body>
</html>
ASKER
That's the solution I've already used.
Have a 'printer safe' version of your web page like what
News.com (http://www.news.com) has.
Read one of their articles and you will see on the top right
they have a printer friendly link.