Solved

Webbrowser popup menu

Posted on 2001-06-11
9
248 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Problem to skip loop 6 54
VB6 Compile Compatibility Issue 4 88
SLMGR Switches Are Not Working On KMS Host 3 67
Child Form in front 4 37
When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
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…
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…

912 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

16 Experts available now in Live!

Get 1:1 Help Now