Solved

ActiveX control or Javascript for Printing

Posted on 1997-12-01
2
368 Views
Last Modified: 2013-12-25
I need a way to have a link within a fram trigger a print (of another frame) on the browser's printer. I don't think that there is a way to do this directly with HTML but am wondering if there is a simple way to do it using either an ActiveX control or a small Javascript.

This app is going into a controlled Intranet environment and will be running on IE3.


TIA
Marty
0
Comment
Question by:mravell
2 Comments
 
LVL 1

Accepted Solution

by:
lyon earned 250 total points
Comment Utility
One of the reasons I love searches on Microsofts Technical Support Site... Here are two suggestions for getting the results you want. However they dont seem to address the multiple frame idea but with a little modification you should be able to get shift focus to the frame you want to print with the code then implement the print function with either a link or, as suggested here, a button:

What you need to do is call the GetDocument() method that returns an IDispatch*. Using the IDispatch*, call QueryInterface() on IID_IOleCommandTarget. With the object pointer returned, call Exec(NULL, OLECMDID_PRINT, 0, NULL,NULL).

Examples
1)
 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 ();
   }

2)

#include <docobj.h> -- This comes with the Internet Client SDK

   void CAboutDlg::OnPrint()
   {
       LPDISPATCH lpDispatch = NULL;
       LPOLECOMMANDTARGET lpOleCommandTarget = NULL;

       lpDispatch = m_ctlWebBrowser.GetDocument();
       ASSERT(lpDispatch);

       lpDispatch->QueryInterface(IID_IOleCommandTarget,
                                  (void**)&lpOleCommandTarget);
       ASSERT(lpOleCommandTarget);

       lpDispatch->Release();

       // print contents of web browser control
       lpOleCommandTarget->Exec(NULL, OLECMDID_PRINT, 0, NULL,NULL);

       lpOleCommandTarget->Release();
   }

I have not tried this yet but it seems sound. Let me know how you make out

Regards
Lyon
0
 

Author Comment

by:mravell
Comment Utility
Understood, I will see what kind of information I can dig up this evening and get you something either before 12am EST tomorrow or first thing in the morning. In the meantime try to get at least a downloadable copy of a SDK from either Sun or Microsoft. They have demos that will work fine for what we are trying to accomplish and I will see if I can produce a script instead.
Regards
Lyon
0

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Although it can be difficult to imagine, someday your child will have a career of his or her own. He or she will likely start a family, buy a home and start having their own children. So, while being a kid is still extremely important, it’s also …
Any business that wants to seriously grow needs to keep the needs and desires of an international audience of their websites in mind. Making a website friendly to international users isn’t prohibitively expensive and can provide an incredible return…
This video teaches users how to migrate an existing Wordpress website to a new domain.
The viewer will learn how to count occurrences of each item in an array.

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

7 Experts available now in Live!

Get 1:1 Help Now