Solved

Webbrowser popup menu

Posted on 2001-06-11
9
247 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
  • 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
 
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
Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

 
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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

760 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

21 Experts available now in Live!

Get 1:1 Help Now