HOWTO: Print the Contents of WFC's HTMLControl

ID: Q222117


The information in this article applies to:


SUMMARY

WFC's HTMLControl is a convenient way to display HTML in a Visual J++ 6.0 application. Unfortunately, it does not provide a method for sending its contents to the printer. This article will explain how to do this.


MORE INFORMATION

The HTMLControl object is a WFC component that makes dealing with the IE browser control easy. Unfortunately, it doesn't provide an easy way to print a Web page. But you can send an OLE command to the underlying browser control to make it print.

If you want to include the browser control (or any ActiveX control) on your WFC Form, you would normally use "JActiveX.EXE" on the command line or "Add COM Wrapper..." from the menu in Visual J++ 6.0 to generate Java-callable methods for that control.

Included in this article is JActiveX-generated wrapper code for the browser control. Because the interfaces on COM objects cannot change, it is safe to just use this code instead of recreating it from scratch.

Add the following code to the import section of the Java class you want to print from:


import myole.IOleCommandTarget; 
Add the following code to the Java class that you want to print from. When you're done, you can just call this method to print from the specified HTMLControl:

private void HTMLControl_Print(HTMLControl hc) {
   final int OLECMDID_PRINT = 6;
   final int OLECMDEXECOPT_PRMOPTUSER = 1;
   final int OLECMDEXECOPT_DONTPROMPTUSER = 2;

   IOleCommandTarget cmdtarget = (IOleCommandTarget) hc.getDocument().getPeer();
   cmdtarget.Exec(null, OLECMDID_PRINT, OLECMDEXECOPT_DONTPROMPTUSER, null,null);
		
} 
IOleCommandTarget.java:

package myole;

import com.ms.com.*;
import com.ms.com.IUnknown;
import com.ms.com.Variant;

// VTable-only interface IOleCommandTarget
/** @com.interface(iid=B722BCCB-4E68-101B-A2BC-00AA00404770, thread=AUTO) */ 
public interface IOleCommandTarget extends IUnknown
{
 /** @com.method(vtoffset=0, addFlagsVtable=4)
     @com.parameters([in,type=PTR] pguidCmdGroup, [in,type=U4] cCmds, 
[in,out,type=PTR] prgCmds, [in,out,type=PTR] pCmdText) */ 
 public void QueryStatus(com.ms.com._Guid pguidCmdGroup, int cCmds, 
myole._tagOLECMD prgCmds, myole._tagOLECMDTEXT pCmdText);

 /** @com.method(vtoffset=1, addFlagsVtable=4)
     @com.parameters([in,type=PTR] pguidCmdGroup, [in,type=U4] nCmdID, 
[in,type=U4] nCmdexecopt, [in,type=PTR] pvaIn, [in,out,type=PTR] pvaOut) */ 
 public void Exec(com.ms.com._Guid pguidCmdGroup, int nCmdID, int nCmdexecopt, 
Variant pvaIn, Variant pvaOut);


 public static final com.ms.com._Guid iid = new 
com.ms.com._Guid((int)0xb722bccb, (short)0x4e68, (short)0x101b, (byte)0xa2, 
(byte)0xbc, (byte)0x0, (byte)0xaa,
     (byte)0x0, (byte)0x40, (byte)0x47, (byte)0x70);
} 
The following code comments are listed at the top of each of the remaining code listings. They are listed here as a reference and as a reminder. Feel free to add them to the code when you cut and paste or you can just leave them out.

// 
// Auto-generated using JActiveX.EXE 4.79.2337
//   (jactivex d.tlb)
// 
// WARNING: Do not remove the comments that include "@com" directives.
// This source file must be compiled by a @com-aware compiler.
// If you are using the Microsoft Visual J++ compiler, you must use
// version 1.02.3920 or later. Previous versions will not issue an error
// but will not generate COM-enabled class files.
//  
_tagOLECMD.java:

package myole;

import com.ms.com.*;
import com.ms.com.IUnknown;
import com.ms.com.Variant;

/** @com.struct(noAutoOffset) */ 


public final class _tagOLECMD
{
 /** @com.structmap([offset=0,type=U4] cmdID) */ 
 public int cmdID;

 /** @com.structmap([offset=4,type=U4] cmdf) */ 
 public int cmdf;

} 
_tagOLECMDTEXT.java:

package myole;

import com.ms.com.*;
import com.ms.com.IUnknown;
import com.ms.com.Variant;

/** @com.struct(noAutoOffset) */ 

public final class _tagOLECMDTEXT
{
 /** @com.structmap([offset=0,type=U4] cmdtextf) */ 
 public int cmdtextf;

 /** @com.structmap([offset=4,type=U4] cwActual) */ 
 public int cwActual;

 /** @com.structmap([offset=8,type=U4] cwBuf) */ 
 public int cwBuf;

// UNMAPPABLE: rgwz: Cannot be used as a structure field.
//   /** @com.structmap(UNMAPPABLE rgwz) */ 
//  public UNMAPPABLE rgwz;

} 


REFERENCES

For the latest Knowledge Base articles and other support information on Visual J++ and the SDK for Java, please see the following pages on the Microsoft Technical Support site:

http://support.microsoft.com/support/visualj/

http://support.microsoft.com/support/java/
(c) Microsoft Corporation 1999, All Rights Reserved. Contributions by Joseph B. Hall, Microsoft Corporation.

Additional query words:


Keywords          : kbActiveX kbCOMt kbJava kbSDKJava kbVJ kbWFC kbGrpJava 
Version           : WINDOWS:6.0
Platform          : WINDOWS 
Issue type        : kbhowto 

Last Reviewed: July 14, 1999