Solved

Webbrowser popup menu

Posted on 2001-06-11
9
258 Views
Last Modified: 2010-05-02
God morning all!

My problem is this:

I have a program, and I'd like to implement an internal webbrowser for it. It should work as internet explorer so I am using the webbrowser component. But I want to change som features in the popup menu (adding new menuitems to it) this is my first problem, how can I override the default popup menu? Secondly how can I know whats under the mousepointer? a link (and if so what that link points to, ie image, or html doc ....) I cant find a mousedown event for the borwser component.
Is it at all possible to do this with the webbrowser component, if not what are my options? is there any freeware component out there that incorporates functionality such as plugins?

For a good ansewer I will raise the points

Thank you for your time

//Claes
0
Comment
Question by:clylv
[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
  • 4
  • 3
  • 2
9 Comments
 

Author Comment

by:clylv
ID: 6176722
Ive sorted out the replacing bit :

Public Declare Function CallWindowProc Lib "user32" Alias "CallWindowProcA" (ByVal lpPrevWndFunc As Long, ByVal hwnd As Long, ByVal Msg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Public Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (hpvDest As Any, hpvSource As Any, ByVal cbCopy As Long)
Public Declare Function GetClassName Lib "user32" Alias "GetClassNameA" (ByVal hwnd As Long, ByVal lpClassName As String, ByVal nMaxCount As Long) As Long
Public Declare Function GetWindow Lib "user32" (ByVal hwnd As Long, ByVal wCmd As Long) As Long
Public Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long

Public Const GWL_WNDPROC = (-4)

Public Const GW_HWNDNEXT = 2
Public Const GW_CHILD = 5
   
Public Const WM_MOUSEACTIVATE = &H21
Public Const WM_CONTEXTMENU = &H7B
Public Const WM_RBUTTONDOWN = &H204

Public origWndProc As Long

Public Function AppWndProc(ByVal hwnd As Long, ByVal Msg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
    Select Case Msg
        Case WM_MOUSEACTIVATE
            Dim C As Integer
            Call CopyMemory(C, ByVal VarPtr(lParam) + 2, 2)
            If C = WM_RBUTTONDOWN Then
                Form1.PopupMenu Form1.mnuBrowser
                SendKeys "{ESC}"
            End If
        Case WM_CONTEXTMENU
            Form1.PopupMenu Form1.mnuBrowser
            SendKeys "{ESC}"
    End Select
    AppWndProc = CallWindowProc(origWndProc, hwnd, Msg, wParam, lParam)
End Function

Private Sub Form_Load()
    Dim h As Long, aClass As String, k As Long
    h = GetWindow(hwnd, GW_CHILD)
    aClass = Space$(128)
    Do While h
        k = GetClassName(h, aClass, 128)
        If Left$(aClass, k) = "Shell Embedding" Then hw = h: Exit Do
        h = GetWindow(h, GW_HWNDNEXT)
    Loop

    WebBrowser1.Navigate ""
    origWndProc = SetWindowLong(hw, GWL_WNDPROC, AddressOf AppWndProc)
End Sub


STILL need help with whats under the mouse pointer when popup appears...
0
 
LVL 28

Expert Comment

by:AzraSound
ID: 6177313
you can use the webbrowser's StatusText property.  you are notified of its change when the OnStatusTextChange event fires.  of course, webpage scripting allows web developers to alter this property...essentially you see what IE sees in its statusbar when you view webpages.

if you want a lot of control and notifications over a page, use the DOM.  go to project -> references and select Microsoft HTML Object Library.  here is how you might cancel the default context menu using this object model as opposed to subclassing techniques used in your above snippet:


Private WithEvents htmlDoc As HTMLDocument

Private Sub WebBrowser_DocumentComplete(...)
   If (pDisp Is WebBrowser.Object) Then
      Set htmlDoc = WebBrowser.Document
   End If
End Sub

Private Sub htmlDoc_oncontextmenu() As Boolean
   'cancel the default context menu
   htmlDoc_oncontextmenu = False

   'replace with your own popup menu here
   Popupmenu mnuMain
End Sub


if you are familiar with DHTML and scripting as a web developer, you will catch on to how to use this object model fairly quickly.  otherwise, youll need to do some digging into the Object Browsre to become familiar with all of classes and functionality exposed via the HTML Object Library.
0
 

Author Comment

by:clylv
ID: 6177582
Tnx AzraSound,

Your solution is a better one, do you have any sugestions on how to know what the user is clicking on? the OnStatusTextChange event do not work properly on images and such...

regards
Claes
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 28

Accepted Solution

by:
AzraSound earned 150 total points
ID: 6177965
if you create an HTMLWindow object, you can trap global events occurring on the page if they "bubble".  to use this, you would use something similar to my above snippet by adding:

Private WithEvents htmlWin As HTMLWindow

'-- add to documentcomplete event
Set htmlWin = webBrowser.Document.parentWindow


now, events that "bubble" are those that occur, on say, the clicking of a button.  first, the button receives the event, and performs any actions that should occur then (as defined in the webpage itself for example).  then this event begins to "bubble", or move up, the object hierarchy of the page.  so, perhaps this event can then be handled by the form in which the image resides, and then the document containing that form, and then finally the window object (the top element in the DOM hierarchy).

if the event does bubble, you can access the element that triggered it and then use that to get the information you need.  this can be found through the HTMLWindow object's "event" attribute/property.   i am not on a development machine at this time to offer any concrete code, nor do i really have the time to build a sample.  however, perhaps later this evening (US time) or later this week i can put something together if you are still struggling with the implementation.
0
 
LVL 16

Expert Comment

by:Richie_Simonetti
ID: 6178235
0
 

Author Comment

by:clylv
ID: 6180112
SUPER!

Works like a charm greate tnx AzraSound! U r extreamly good at explaining. Giving u an extra 50p for your time an additional sampel is not nessessary for me.

once again thankyou
//Claes
0
 

Author Comment

by:clylv
ID: 6180130
Richie_Simonetti

Thanyou for your example that will work as well very nice!

regards
Claes
0
 
LVL 16

Expert Comment

by:Richie_Simonetti
ID: 6181113
You are welcome.
0
 
LVL 28

Expert Comment

by:AzraSound
ID: 6181345
glad i could help  :-)
0

Featured Post

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

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

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
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.
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…

734 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