Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Hyperlink in VB4
#1
Umm how do you create a button when pressed links you to a website
his world has been connected...
Tied to the darkness.
Soon to be completely eclipsed.
There is so very much to learn...
You understand so little.
A meaningless effort.
One who knows nothing can understand nothing.
-Ansem Bringer of darkness and creator of the heartless
Reply
#2
Hi!

Try this code:

Code:
Private Declare Function GetShortPathName Lib "kernel32" Alias _
"GetShortPathNameA" ( _
    ByVal lpszLongPath As String, ByVal lpszShortPath As String, _
    ByVal cchBuffer As Long) As Long
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

Private Sub Command1_Click()
Dim path As String
OPEN App.path+"\~temp.url" FOR OUTPUT AS #1
PRINT #1, "[InternetShortcut]"
PRINT #1, "URL=http://forum.qbasicnews.com"
CLOSE #1
path = Space(260&)
Call GetShortPathName(App.path + "\~temp.url", path, 260&)
Call ShellExecute(Me.hwnd, "Open", path, "", "", 1)
t!=TIMER
DO
DOEVENTS
LOOP UNTIL TIMER>t!+0.5
Kill "~temp.url"
End Sub

...should be correct. Wink
[Image: f.jpg]
Reply
#3
hmm didnt know that you could make an url like that
isnt there any easyer way somthin like chain or somthing
his world has been connected...
Tied to the darkness.
Soon to be completely eclipsed.
There is so very much to learn...
You understand so little.
A meaningless effort.
One who knows nothing can understand nothing.
-Ansem Bringer of darkness and creator of the heartless
Reply
#4
Quote:hmm didnt know that you could make an url like that
Yes, it's so easy. Big Grin Open an URL file with notepad and you'll see the simple construction.

Quote:isnt there any easyer way somthin like chain or somthing
Yes, there's an easier way but it's not as professional as the code above... Wink
Code:
URL$ = "http://forum.qbasicnews.com"
IE$ = "c:\progra~1\intern~1\iexplore.exe"
SHELL IE$ + " " + URL$, vbNormalFocus
My code above will load the page using your default browser. This code here just uses IE and crashes if it's not stored in that folder.
[Image: f.jpg]
Reply
#5
Should'nt you just be able to do like in FB or even QB
Code:
SHELL "CALL temp.url"
his world has been connected...
Tied to the darkness.
Soon to be completely eclipsed.
There is so very much to learn...
You understand so little.
A meaningless effort.
One who knows nothing can understand nothing.
-Ansem Bringer of darkness and creator of the heartless
Reply
#6
You can also use ShellExecute to directly go to a website without needing a .url file:

Code:
ShellExecute form.hWnd, vbNullString, "http://www.yousmelllikeoldpants.com/", vbNullString, App.Path, SW_SHOWNORMAL

This will load your URL with your default browser regardless of where it is. "form" is the name of a form in your application, usually the one you're calling the function from (although I believe it can be any legal form name). So if you've got "frmAbout", you would use that in the first argument, passing its hWnd to the function. Also, note the SW_SHOWNORMAL; that's a constant, you can find its value in the API viewer utility (actually I'm not sure if VB4 comes with it or not but if you don't have it, you can also find it online very very easily).
\__/)
(='.'=) Copy bunny into your signature to
(")_(") help him gain world domination.
Reply
#7
Yes, use the declaration of ShellExecute above to try that. Smile
[Image: f.jpg]
Reply
#8
Don't use buttons to link to websites. End of story.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)