Solved

Netscape and Visual Basic

Posted on 2000-05-07
5
193 Views
Last Modified: 2013-11-25
I would like to know if I can control Netscape from my VB app.  In my meanderings, I found the netscape.tlb file and made a refernce to it.  I was then able to use the Object Browser and view the netscape type library.  I decalred a variable as one of the class', and was able to set the variable to that class.  And when I type the variable and hit the . button, a the list of events, methods, and properties came up.  So it worked, right?  But when I ran the app, it said "Argument Not Optional".  I know that Netscape is written in C++, but so is Internet Explorer and I can access IE from VB.  All I really want my app to do is get the current URL of Netscape.  So is there a way to communicate with Netscape from VB?  

Thanks in advance
0
Comment
Question by:mkjsmr
  • 2
  • 2
5 Comments
 
LVL 6

Expert Comment

by:Marine
ID: 2785706
If you could tell me the name of that file so i can reference it and see if i can try to do it. Can you please tell me that ? Thanks. I think you can get what you want though API's.
0
 
LVL 28

Expert Comment

by:AzraSound
ID: 2785821
if you are interested i wrote this code to get the url that netscape is showing



Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function SetActiveWindow Lib "user32" Alias "SetForegroundWindow" (ByVal hwnd As Long) As Long
Private Declare Function ShowWindow Lib "user32" (ByVal hwnd As Long, ByVal nCmdShow As Long) As Long
Private Declare Function GetWindow Lib "user32" (ByVal hwnd As Long, ByVal wCmd As Long) As Long
Private Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String, ByVal cch As Long) As Long
Private Declare Function GetParent Lib "user32" (ByVal hwnd As Long) As Long
Private Declare Function IsIconic Lib "user32" (ByVal hwnd As Long) As Long
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Long) As Long
Private Declare Function SendMessageByString Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As String) As Long

Const SW_RESTORE = 9
Const GW_HWNDNEXT = 2
Const FWP_STARTSWITH = 0
Const FWP_CONTAINS = 1
Const WM_GETTEXT = &HD
Const WM_GETTEXTLENGTH = &HE

Function GetNetscapeURL()
    On Error GoTo Errhandler
    Dim hwnd As Long
    Dim urlText As String
    Dim TextLength As Long
    Dim buffer As String
    hwnd = FindWindowPartial("Netscape", FWP_CONTAINS)
    TextLength = SendMessage(hwnd, WM_GETTEXTLENGTH, 0&, 0&)
    buffer = String(TextLength, 0&)
    Call SendMessageByString(hwnd, WM_GETTEXT, TextLength& + 1, buffer$)
    MsgBox buffer
    Exit Function
Errhandler:
    MsgBox Err.Description
    Err.Clear
End Function

Function FindWindowPartial(TitleStart As String, Method As Integer) As Long
   Dim hWndTmp
   Dim nRet
   Dim TitleTmp As String

   hWndTmp = FindWindow(vbNullString, vbNullString)
   Do Until hWndTmp = 0
     
      ' Make sure the window has no parent
     
      If GetParent(hWndTmp) = 0 Then
         
         ' Get the window caption
         
         TitleTmp = Space(256)
         nRet = GetWindowText(hWndTmp, TitleTmp, Len(TitleTmp))
         If nRet Then
           
            ' Clean up return string, preparing for
            ' case-insensitive comparison.
           
            TitleTmp = UCase(Left(TitleTmp, nRet))

            If InStr(TitleTmp, UCase(TitleStart)) Then
                FindWindowPartial = hWndTmp
                Exit Do
            End If
         End If
      End If
     
      ' Get next window in master window list and continue
     
      hWndTmp = GetWindow(hWndTmp, GW_HWNDNEXT)
   Loop
End Function

Private Sub Command1_Click()
    Call GetNetscapeURL
End Sub
0
 

Author Comment

by:mkjsmr
ID: 2788504
To Marine:  The file is "netscape.tlb" and it is found in the "ProgramFiles/Netscape/Communicator/Program" folder.  There are 4 classes: CNetworkCX, COleRegistry, CTalkSMServ, and Help.  The CNetworkCX is the only one that seems worth anything, as the others don't seem to have anything to do with the internet.  But if you know more than me (which, of course you do), then you may be able to figure out how to manipulate them.

To AzraSound:  The code that you showed me works, but it only gives you the Title of the current page, not the URL.  And if you have Messenger open, it gives you the title of the email you are reading regardless of whick window is on top.  I'm not complaining mind you, it's alot more than I had 2 days ago.  But what I really want is the URL.  I think I might be able to figure out how, but I don't know that much about the Windows API and I might make my computer blow up if I "tried" too much :-)  Thanks again
0
 
LVL 28

Accepted Solution

by:
AzraSound earned 200 total points
ID: 2788928
hmm youre right...use this instead:

****MODULE CODE****

Option Explicit

Public Type ProcData
    AppHwnd As Long
    title As String
    Placement As String
    Left As Long
    Top As Long
    Right As Long
    Bottom As Long
End Type

Private Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String, ByVal cch As Long) As Long

Private Declare Function GetWindow Lib "user32" (ByVal hwnd As Long, ByVal wCmd As Long) As Long
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function GetClassName Lib "user32" Alias "GetClassNameA" (ByVal hwnd As Long, ByVal lpClassName As String, ByVal nMaxCount As Long) As Long
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long

Private Const WM_GETTEXT = &HD
Private Const WM_GETTEXTLENGTH = &HE

Private Const GW_CHILD = 5
Private Const GW_HWNDNEXT = 2
Private Const GW_HWNDFIRST = 0

Public Function EditInfo(window_hwnd As Long) As String
    Dim txt As String
    Dim buf As String
    Dim buflen As Long
    Dim child_hwnd As Long
    Dim children() As Long
    Dim num_children As Integer
    Dim i As Integer

    ' Get the class name.
    buflen = 256
    buf = Space$(buflen - 1)
    buflen = GetClassName(window_hwnd, buf, buflen)
    buf = Left$(buf, buflen)
   
    ' See if we found an Edit object.
    If buf = "Edit" Then
        EditInfo = WindowText(window_hwnd)
        Exit Function
    End If
   
    ' It's not an Edit object. Search the children.
    ' Make a list of the child windows.
    num_children = 0
    child_hwnd = GetWindow(window_hwnd, GW_CHILD)
    Do While child_hwnd <> 0
        num_children = num_children + 1
        ReDim Preserve children(1 To num_children)
        children(num_children) = child_hwnd
       
        child_hwnd = GetWindow(child_hwnd, GW_HWNDNEXT)
    Loop
   
    ' Get information on the child windows.
    For i = 1 To num_children
        txt = EditInfo(children(i))
        If txt <> "" Then Exit For
    Next i

    EditInfo = txt
End Function
' ************************************************
' Return the text associated with the window.
' ************************************************
Public Function WindowText(window_hwnd As Long) As String
    Dim txtlen As Long
    Dim txt As String

    WindowText = ""
    If window_hwnd = 0 Then Exit Function
   
    txtlen = SendMessage(window_hwnd, WM_GETTEXTLENGTH, 0, 0)
    If txtlen = 0 Then Exit Function
   
    txtlen = txtlen + 1
    txt = Space$(txtlen)
    txtlen = SendMessage(window_hwnd, WM_GETTEXT, txtlen, ByVal txt)
    WindowText = Left$(txt, txtlen)
End Function


Public Function EnumProc(ByVal app_hwnd As Long, ByVal lParam As Long) As Boolean
    Dim buf As String * 1024
    Dim title As String
    Dim length As Long

    ' Get the window's title.
    length = GetWindowText(app_hwnd, buf, Len(buf))
    title = Left$(buf, length)

    ' See if the title ends with " - Netscape".
    If Right$(title, 11) = " - Netscape" Then
        ' This is it. Find the ComboBox information.
        frmWindowList.Label1 = EditInfo(app_hwnd)

        ' Stop searching.
        EnumProc = 0
    Else
        ' Continue searching til find it.
        EnumProc = 1
    End If
End Function



****FORM CODE****


Option Explicit

Private Declare Function EnumWindows Lib "user32" (ByVal lpEnumFunc As Any, ByVal lParam As Long) As Long

Private Sub Command1_Click()
    Label1.Caption = ""
    EnumWindows AddressOf EnumProc, 0
End Sub




0
 

Author Comment

by:mkjsmr
ID: 2792000
Thanks alot AzraSound.  Code works great.  Except for some reason, the label is showing "200" when I was viewing this page???  No big deal; it worked everywhere else I went.  And I even figured out how to add IE to the code so that I can monitor both IE and Netscape without having two different threads running.  Thanks again.

0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
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…
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…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…

759 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

18 Experts available now in Live!

Get 1:1 Help Now