Thursday, August 19, 2010

Open a web URL in Visual Basic 6.0

"ShellExecute" : Without adding Active X/COM components to the project, the simplest way to achieve this by using Windows API call.


Add the following API declaration at the form level declaration section

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

Parameters :

hwnd [in, optional]

A handle to the owner window used for displaying a UI or error messages. This value can be NULL if the operation is not associated with a window.

lpOperation [in, optional]

A pointer to a null-terminated string, referred to in this case as a verb, that specifies the action to be performed:

"edit"         àLaunches an editor and opens the document for editing. If lpFile is not a document

file, the function will fail.

"explore"     à
Explores a folder specified by lpFile.

"find"         à
Initiates a search beginning in the directory specified by lpDirectory.

"open"     à
Opens the item specified by the lpFile parameter. The item can be a file or folder.

"print"         àPrints the file specified by lpFile. If lpFile is not a document file, the function fails.

"NULL"        à
Default

lpFile [in]

A pointer to a null-terminated string that specifies the file or object on which to execute the specified verb. To specify a Shell namespace object, pass the fully qualified parse name. Note that not all verbs are supported on all objects. For example, not all document types support the "print" verb. If a relative path is used for the lpDirectory parameter do not use a relative path for lpFile.

lpParameters [in, optional]

If lpFile specifies an executable file, this parameter is a pointer to a null-terminated string that specifies the parameters to be passed to the application. The format of this string is determined by the verb that is to be invoked. If lpFile specifies a document file, lpParameters should be NULL.

lpDirectory [in, optional]

A pointer to a null-terminated string that specifies the default (working) directory for the action. If this value is NULL, the current working directory is used. If a relative path is provided at lpFile, do not use a relative path for lpDirectory.

nShowCmd [in]

SW_SHOWNORMAL : Windows restores it to its original size and position.

SW_MAXIMIZE : Maximizes the specified window.

SW_MINIMIZE :Minimizes the specified window and activates the next top-level window in the z-order.

SW_SHOWMAXIMIZED : Activates the window and displays it as a maximized window.

SW_SHOWMINIMIZED : Activates the window and displays it as a minimized window.


 

For more information: Click HERE


 

Calling API function in Button_Click() event:

Private
Sub Command1_Click()


ShellExecute Me.hwnd, "open", "http://www.yahoo.com", vbNullString, "C:\", SW_SHOWNORMAL

End Sub


 

'Opens the specified URL in the Default WebBrowser.

ShellExecute 0, "open", "http://www.yahoo.com", vbNullString, vbNullString, SW_SHOWNORMAL


 

'Opens the specified URL in the specified WebBrowser.


ShellExecute 0, "open", "C:\Program Files\Mozilla Firefox\Firefox.exe", ", "http://www.yahoo.com", vbNullString, 1


 

No comments:

Post a Comment