Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 263
  • Last Modified:

Webbrowser popup menu

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
clylv
Asked:
clylv
  • 4
  • 3
  • 2
1 Solution
 
clylvAuthor Commented:
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
 
AzraSoundCommented:
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
 
clylvAuthor Commented:
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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
AzraSoundCommented:
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
 
Richie_SimonettiCommented:
0
 
clylvAuthor Commented:
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
 
clylvAuthor Commented:
Richie_Simonetti

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

regards
Claes
0
 
Richie_SimonettiCommented:
You are welcome.
0
 
AzraSoundCommented:
glad i could help  :-)
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

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.

  • 4
  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now