Solved

Dropping a URL from IE onto a VB app - How to?

Posted on 1998-09-16
4
201 Views
Last Modified: 2010-04-30
Hi,
I need to be able to grab a URL from either Netscape or IE and drop it onto my App (either straight on the form or on an object within...doesn't matter which). I can't even get the app to accept anything being dropped on it from an application other than itself! I really want an answer with some code I can use, or a pretty detailed description of how to do it, because I can't even get a start at the moment. I have a reasonable knowledge of VB, so I'm not a beginner, just haven't come across a need for this before!! Any help greatly appreciated!
0
Comment
Question by:jupes
  • 2
4 Comments
 
LVL 13

Expert Comment

by:Mirkwood
ID: 1435178
It sounds stupid. But have you tried it on another machine. I have  two computers here. One that allows drag drop between two applications  and the other does not. I'm sure it has something with DLL versions.

Just to be sure. You have put OleDropMode to Automatic. Now you will receive the OleDragOver event.
0
 
LVL 2

Accepted Solution

by:
wj7ster earned 500 total points
ID: 1435179
I hope this is what you are after:

1. Set the OLEDropMode property of the Form to Manual, (1)
2. Place a textbox (Text1) onto the form
3. Copy and paste the following code into the general declaration section of the form:

' ================START OF CODE================
Private Sub Form_OLEDragDrop(Data As DataObject, Effect As Long, Button As Integer, Shift As Integer, X As Single, Y As Single)
   
    If Data.GetFormat(vbCFText) Then
        Text1.Text = Data.GetData(vbCFText)
    End If
   
End Sub
' ================END OF CODE================

I haven't tested this with NetScape (because I don't have it installed :-), but imagine that it should work.

Once you have the URL you can do lots with it.  You can also start another procedure instead of populating the Textbox and store the URL in a variable.  The possibilities are endless.

Good luck.


Willem Sevenster
willem@sevenster.co.nz
0
 
LVL 13

Expert Comment

by:Mirkwood
ID: 1435180
So it was the easy answer.
0
 
LVL 9

Expert Comment

by:Dalin
ID: 1435181
Here is another way if you don't play drag/drop.




    'Assumption:
    'Using Netscape with caption start with  "Netscape", can be adjusted
    ' form1 has a label named lblAddress and a cmdFindAddress

    Code in form1:
    Option Explicit

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

    ' Start the enumeration.
    Private Sub cmdFindAddress_Click()
        lblAddress.Caption = ""
        EnumWindows AddressOf EnumProc, 0
    End Sub

    'Code in a Module:
    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

    ' ***********************************************
    ' If this window is of the Edit class, return
    ' its contents. Otherwise search its children
    ' for an Edit object.
    ' ***********************************************
    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 Left$(title, 8) = "Netscape" Then
            ' This is it. Find the ComboBox information.
            frmWindowList.lblAddress = EditInfo(app_hwnd)

            ' Stop searching.
            EnumProc = 0
        Else
            ' Continue searching til find it.
            EnumProc = 1
        End If
    End Function
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

Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
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…
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…
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…

747 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

11 Experts available now in Live!

Get 1:1 Help Now