-
October 24th, 2005, 08:58 AM
#1
open web using label control
Can i able to open a particular website on clicking the label control in VB?
How to do it? Please give me the code.
-
October 24th, 2005, 09:10 AM
#2
Re: open web using label control
Code:
'general declarations
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 Declare Function FindExecutable Lib "shell32.dll" Alias _
"FindExecutableA" (ByVal lpFile As String, ByVal lpDirectory As _
String, ByVal lpResult As String) As Long
Private Sub Label1_Click()
Dim FileName, Dummy As String
Dim BrowserExec As String * 255
Dim RetVal As Long
Dim FileNumber As Integer
' First, create a known, temporary HTML file
BrowserExec = Space(255)
FileName = "C:\temphtm.HTM"
FileNumber = FreeFile ' Get unused file number
Open FileName For Output As #FileNumber ' Create temp HTML file
Write #FileNumber, "<HTML> <\HTML>" ' Output text
Close #FileNumber ' Close file
' Then find the application associated with it
RetVal = FindExecutable(FileName, Dummy, BrowserExec)
BrowserExec = Trim(BrowserExec)
' If an application is found, launch it!
If RetVal <= 32 Or IsEmpty(BrowserExec) Then ' Error
MsgBox "Could not find associated Browser", vbExclamation, _
"Browser Not Found"
Else
RetVal = ShellExecute(Me.hwnd, "open", BrowserExec, _
"Websiteaddress/index.htm", Dummy, 3)
If RetVal <= 32 Then ' Error
MsgBox "Web Page not Opened", vbExclamation, "URL Failed"
End If
End If
Kill FileName ' delete temp HTML file
End Sub
This will open your browser with a specific web page
-
October 24th, 2005, 09:59 AM
#3
Re: open web using label control
Originally Posted by baskarelango
Can i able to open a particular website on clicking the label control in VB?
How to do it? Please give me the code.
How about trying it this way:
I assume you have a Label named Label1 on the Form.
Code:
'API Function declaration
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
'This constant can be changed to use Maximize also
Const SW_SHOWNORMAL = 1
Private Sub Label1_Click()
'set the caption of the Label (Just for an example)
Label1.Caption = "http://msdn.microsoft.com"
'This will launch the default web-browser
ShellExecute Me.hwnd, vbNullString, Label1.Caption, vbNullString, "C:\", SW_SHOWNORMAL
End Sub
This should be enough to launch a URL in the Browser.
-
October 24th, 2005, 10:24 AM
#4
Re: open web using label control
Well, if you are happy to use IE at all times (not the default browser, which may or may not be IE) then:
Code:
Shell "explorer http:\\www.mylink.com"
does the trick.
BTW: Don't forget to change the mouse cursor when moved over the label to provide a more "hyperlink-like" feel.
Mike
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|