Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Printing from IE3 control

Posted on 1999-07-13
2
Medium Priority
?
153 Views
Last Modified: 2010-05-02
All help at MSDN etc. refer to ExecWB. My control does not have this method.

I've got:
VB5 (SP3)
NT4 (SP3)
IE 3.02 (4.70.1300)
0
Comment
Question by:dogma
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
2 Comments
 
LVL 13

Accepted Solution

by:
Mirkwood earned 400 total points
ID: 1524157
webbrowser1.setfocus
sendkeys "^p"
0
 
LVL 13

Expert Comment

by:Mirkwood
ID: 1524158


HOWTO: Print the WebBrowser Control
Last reviewed: May 7, 1998
Article ID: Q176400
 


--------------------------------------------------------------------------------

The information in this article applies to:
Microsoft Visual Basic Control Creation, Learning, Professional, and Enterprise Editions for Windows, version 5.0
Microsoft Visual Basic Standard, Professional, and Enterprise Editions, 32-bit only, for Windows, version 4.0


SUMMARY
Microsoft Internet Explorer 3.0 includes a custom ActiveX control called WebBrowser. The WebBrowser control does not include a Print method that can be directly called from Visual Basic. Tto print the contents of the WebBrowser Control in Visual Basic, you must set the focus to the content portion of the control and a CTRL-P keystroke sequence must be sent to the control.

The difficulty with this is that the WebBrowser window is actually made up of more than one window. The window that needs to have the focus to print is the one with a class name of "HTML_Internet Explorer," and the SetFocus method sets the focus to the "SHELL DocObject View" window. Before sending a CTRL-P keystroke sequence to the WebBrowser control, the proper child window of the control must have the focus.



MORE INFORMATION
To print the control, simply follow the steps below to set focus to the correct window and initiate the SendKeys function:


Start a new standard Exe project in Visual Basic. Form1 is created by default.

Add the "Microsoft Internet Controls" (shdocvw.dll) to the project.

Place the WebBrowser control on the default form (Form1).

Add the following code to load the default page:


      Private Sub Form_Load()
          WebBrowser1.Navigate "http://www.microsoft.com"
      End Sub


Place a CommandButton on the form and change its caption to "Print." Add the following code to the Click event of the button:


      Private Sub Command1_Click()
          Dim hwnd As Long
          WebBrowser1.SetFocus
          hwnd = GetFocus
          SetFocusToBrowser (hwnd)
          SendKeys "^P"   'Control-P to print
      End Sub


Add a module to the project, and then add the following code to it:


      Option Explicit


      Declare Function GetWindow Lib "user32" (ByVal hwnd As Long, _
          ByVal wCmd As Long) As Long

      Declare Function GetWindowLong Lib "user32" _
          Alias "GetWindowLongA" (ByVal hwnd As Long, _
          ByVal nIndex As Long) As Long

      Declare Function SetFocusAPI Lib "user32" _
          Alias "SetFocus" (ByVal hwnd As Long) As Long

      Declare Function GetFocus Lib "user32" () As Long

      Declare Function SendMessage Lib "user32" _
          Alias "SendMessageA" (ByVal hwnd As Long, _
          ByVal wMsg As Long, ByVal wParam As Long, _
          lParam As Long) As Long

      'GetWindow constants
      Public Const GW_CHILD = 5
      'GetWindowLong constants
      Public Const GWL_STYLE = (-16)
      Public Const WS_VSCROLL = &H200000

      Sub SetFocusToBrowser(hBrowserHwnd As Long)
          Dim lStyle As Long
          Dim lResult As Long
          Dim hwnd As Long
          hwnd = hBrowserHwnd
          While (lResult = 0) And (hwnd <> 0)
              hwnd = GetWindow(hwnd, GW_CHILD)
              lStyle = GetWindowLong(hwnd, GWL_STYLE)
              lResult = lStyle And WS_VSCROLL
          Wend
          SetFocusAPI (hwnd)
      End Sub


Run the project, and click Print.

REFERENCES
For additional information, please see the following articles in the Microsoft Knowledge Base:


   ARTICLE-ID: Q162719
   TITLE     : HOWTO: Use the WebBrowser Control from Visual Basic 5.0

   ARTICLE-ID: Q155969
   TITLE     : HOWTO: Distribute the WebBrowser Control
 



--------------------------------------------------------------------------------
Additional query words:
Keywords : vb432 VB4WIN vb5all vb5howto kbVBp400 kbVBp500
Version : WINDOWS:4.0,5.0
Platform : WINDOWS
Issue type : kbhowto


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.  

Last reviewed: May 7, 1998
) 1998 Microsoft Corporation. All rights reserved. Terms of Use.


0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses

705 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