Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 1998-09-16
4
Medium Priority
?
212 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 1000 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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
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…
Suggested Courses

715 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