Solved

Implementing Find (on this page) in WebBrowser Control

Posted on 1999-01-06
4
235 Views
Last Modified: 2006-11-17
Hello I need to implement the find dialog box for the webbrowser control.
0
Comment
Question by:cavacasp
  • 2
4 Comments
 
LVL 13

Expert Comment

by:Mirkwood
ID: 1454292


FILE: Invoke Find, View Source, Options dialogs for WebBrowser
Last reviewed: January 19, 1998
Article ID: Q175513  
The information in this article applies to:
Microsoft Internet Explorer (Programming), versions 3.0, 3.01, 3.02, 4.0, 4.01
ActiveX SDK, version 1.0
Internet Client SDK, versions 4.0, 4.01


SUMMARY
This article illustrates how to invoke the Internet Explorer Find, Internet Options, and View Source dialog boxes from within an application that is hosting the WebBrowser control.

The following file is available for download from the Microsoft Software Library:


 ~ wbsampl.exe (size: 47557 bytes)

MORE INFORMATION
WARNING: This sample uses an undocumented command group GUID that is subject to change in the future. Although this sample has been tested to work correctly with Internet Explorer 3.0 and 4.0, there is no guarantee that these techniques will continue to work successfully in future versions. Please use caution when adding this code to an application.

The WBSampl example is a mini-browser application that illustrates how to create an application in Microsoft Visual C++ that uses the WebBrowser control. This example provides code to invoke the Find, Internet Options, and View Source items that are part of the WebBrowser control but are not exposed as methods.

In order to implement the items listed above, the following steps should be followed.


Define the command group GUID for the WebBrowser control as follows:


      DEFINE_GUID(CGID_IWebBrowser,0xED016940L,0xBD5B,0x11cf,0xBA,
      0x4E,0x00,0xC0,0x4F,0xD7,0x08,0x16);

Define the CommandTarget ids for menu driving as follows:


      #define HTMLID_FIND 1
      #define HTMLID_VIEWSOURCE 2
      #define HTMLID_OPTIONS 3

Execute a CommandTarget id as follows:


      HRESULT CMainFrame::ExecCmdTarget(DWORD nCmdID)
      {
         LPDISPATCH lpDispatch = NULL;
         LPOLECOMMANDTARGET lpOleCommandTarget = NULL;

         lpDispatch =
            ((CWebSurferView*)GetActiveView())->m_webBrowser.GetDocument();
         ASSERT(lpDispatch);

         // Get an IDispatch pointer for the IOleCommandTarget interface.
         lpDispatch->QueryInterface(IID_IOleCommandTarget,
      (void**)&lpOleCommandTarget);
         ASSERT(lpOleCommandTarget);

         lpDispatch->Release();

         // Invoke the given command id for the WebBrowser control
         return lpOleCommandTarget->Exec(CGID_IWebBrowser, nCmdID, 0,
                                         NULL, NULL);
      }

Note that m_webBrowser is an instance of the WebBrowser control and is defined in the CView-derived class for this project. Also, nCmdID is one of the IDs defined in step 2.
(c) Microsoft Corporation 1997, All Rights Reserved. Contributions by Scott Roberts, Microsoft Corporation

 


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

Additional query words: WebBrowser WBSampl Find Source Options Internet
Explorer IE
Keywords : AXSDKWebBrowser
Technology : kbInetDev kbole
Version : WINDOWS:3.0,3.01,3.02,4.0,4.01
Platform : WINDOWS
Issue type : kbfile
Solution Type : kbsample


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: January 19, 1998
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.
 


0
 

Author Comment

by:cavacasp
ID: 1454293
You wanna try that in VB.  Since that is what this group is about.
0
 
LVL 1

Accepted Solution

by:
visual_b earned 30 total points
ID: 1454294
Place a CommandButton on the form and 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 "^f"  
      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


0
 

Author Comment

by:cavacasp
ID: 1454295
Thank You that works great
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Use Multiple Forms 4 38
VB6 add a minute to the date time value 8 47
VBA error replacing data 6 35
Add a task in Outlook from access 11 32
I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…

747 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

13 Experts available now in Live!

Get 1:1 Help Now