Link to home
Start Free TrialLog in
Avatar of mkjsmr
mkjsmr

asked on

Netscape and Visual Basic

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
Avatar of Marine
Marine

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.
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
Avatar of mkjsmr

ASKER

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
ASKER CERTIFIED SOLUTION
Avatar of AzraSound
AzraSound
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of mkjsmr

ASKER

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.