Results 1 to 18 of 18

Thread: ShellExecute: Opening URLs (not easy)

  1. #1

    Thread Starter
    Junior Member NGE's Avatar
    Join Date
    Feb 2001
    Location
    Neo-Tokyo 3
    Posts
    26

    ShellExecute: Opening URLs (not easy)

    Hello, I use this code to open URLs in the default browser:

    VB Code:
    1. ShellExecute 0, "open", URL, "", "", 1

    The problem is that he URL is being opened in the current browser window. Instead it should start a new browser, like if target was "_blank"

    So my question: How can I pass the target frame when opening a URL?

    Thanks,

    NGE

  2. #2
    Member dark.journey's Avatar
    Join Date
    Nov 2002
    Location
    somewhere between Hell and back
    Posts
    36
    I have no idea with shellexecute, but you can pass the target frame using the webbrowser control

    (WebBrowser.Navigate Url as String, [flags],[targetframename],[postdata],[headers])
    *follow the white rabbit neo*

    .¸¸.·´¯`·.¸.·>dark journey<·.¸¸.·´¯`·.¸.

    To accomplish great things, we must dream as well as act.
    Anatole France (1844 - 1924)

  3. #3

    Thread Starter
    Junior Member NGE's Avatar
    Join Date
    Feb 2001
    Location
    Neo-Tokyo 3
    Posts
    26
    Phew, I don't want to blow up my code by using that control..

    Is there probably a way to pass DDE commands to a program?

  4. #4
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    there are many parameters in this link , maybe one can solve your problem?

    http://www.allapi.net/apilist/ShellExecute.shtml

  5. #5

    Thread Starter
    Junior Member NGE's Avatar
    Join Date
    Feb 2001
    Location
    Neo-Tokyo 3
    Posts
    26
    Well there are things I just don't know and that's why I'm posting here I don't know if there's a special syntax to pass the frame name to the browser. I hoped somebody knew it...

  6. #6
    Frenzied Member Shawn N's Avatar
    Join Date
    Dec 2001
    Location
    Houston
    Posts
    1,631

  7. #7

    Thread Starter
    Junior Member NGE's Avatar
    Join Date
    Feb 2001
    Location
    Neo-Tokyo 3
    Posts
    26
    Thanks, the idea was great but it doesn't work, still launches the site in a already opened IE (I also tried to put the URL in "").

  8. #8
    Frenzied Member Shawn N's Avatar
    Join Date
    Dec 2001
    Location
    Houston
    Posts
    1,631
    VB Code:
    1. Option Explicit
    2.  
    3. Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hwnd As Long, ByVal lpOperation As String, ByVal lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long
    4.  
    5. Const SW_SHOWNORMAL = 1
    6.  
    7.  
    8. Private Sub Form_Load()
    9.  
    10. Dim lngFile As Long
    11. lngFile = FreeFile
    12.  
    13. 'delete the file if it's alive
    14. If Len(Dir("C:\temp.url")) Then Kill "C:\temp.url"
    15.  
    16. Open "C:\temp.url" For Append As lngFile
    17.     Print #lngFile, "[Default]"
    18.     Print #lngFile, "BASEURL=http://vbforums.com/showthread.php?s=&threadid=221262"
    19.     Print #lngFile, ""
    20.     Print #lngFile, "[InternetShortcut]"
    21.     Print #lngFile, "URL=http://vbforums.com/showthread.php?s=&threadid=221262"
    22. Close lngFile
    23.  
    24.    
    25. ShellExecute Me.hwnd, vbNullString, "C:\temp.url", vbNullString, "C:\", SW_SHOWNORMAL
    26.  
    27. Kill "C:\temp.url"
    28.    
    29. End Sub

  9. #9

    Thread Starter
    Junior Member NGE's Avatar
    Join Date
    Feb 2001
    Location
    Neo-Tokyo 3
    Posts
    26
    Thanks, this gives me a new idea how to solve the problem! (for your interest: the code you gave me still opens the site in a existing window - but now I can search for parameters)

  10. #10
    Frenzied Member Shawn N's Avatar
    Join Date
    Dec 2001
    Location
    Houston
    Posts
    1,631
    On my work computer, this actually solved your problem. Now that I try it at home on XP it doesn't.

    Mind letting me know how you solve the problem when you do?

  11. #11

    Thread Starter
    Junior Member NGE's Avatar
    Join Date
    Feb 2001
    Location
    Neo-Tokyo 3
    Posts
    26
    Well I already solved one special case of the problem - the one I need actually. The following code opens a new window first and then the URL in it:

    VB Code:
    1. Public Sub OpenURL(iURL As String)
    2.     'Open URL in new window
    3.     ShellExecute 0, "open", "about[b][/b]:[b][/b]blank", "", "", 1
    4.     ShellExecute 0, "open", iURL, "", "", 1
    5. End Sub

    That's not a target frame but at least _blank

  12. #12
    Frenzied Member Shawn N's Avatar
    Join Date
    Dec 2001
    Location
    Houston
    Posts
    1,631
    Works. Cool.

  13. #13

    Thread Starter
    Junior Member NGE's Avatar
    Join Date
    Feb 2001
    Location
    Neo-Tokyo 3
    Posts
    26
    Not perfectly, as I said before.. Put the code into a button and click it 3 times.. the first window will open in a new explorer, the other 2 calls will open a new window but open the URL in window #1...

  14. #14
    Frenzied Member Shawn N's Avatar
    Join Date
    Dec 2001
    Location
    Houston
    Posts
    1,631
    Only other thing I can think of is using DDE.

    http://support.microsoft.com/default...b;EN-US;160957

  15. #15

    Thread Starter
    Junior Member NGE's Avatar
    Join Date
    Feb 2001
    Location
    Neo-Tokyo 3
    Posts
    26
    Yes, that's exactly what I need. But I don't know how to use DDE in VB.. and searching MSDN wasn't that successful...

  16. #16
    Frenzied Member Shawn N's Avatar
    Join Date
    Dec 2001
    Location
    Houston
    Posts
    1,631
    This works for me. I used late-binding so it won't bloat your application.

    VB Code:
    1. Option Explicit
    2.  
    3. Private Sub Form_Load()
    4.  
    5.     Dim objIE As Object
    6.     Set objIE = CreateObject("InternetExplorer.Application")
    7.    
    8.     objIE.Navigate2 "http://www.vbforums.com/showthread.php?s=&postid=1308704#post1308704"
    9.     objIE.Visible = True
    10.    
    11.     Set objIE = Nothing
    12.  
    13. End Sub

  17. #17

    Thread Starter
    Junior Member NGE's Avatar
    Join Date
    Feb 2001
    Location
    Neo-Tokyo 3
    Posts
    26
    Very nice, a thousand thanks!

  18. #18
    Frenzied Member Shawn N's Avatar
    Join Date
    Dec 2001
    Location
    Houston
    Posts
    1,631

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width