VB Mania

Text Box: Previous Example
Text Box: Next Example
Text Box: VB-Mania Core

How to Email Someone

Information:

In your program, you may need to put your email so that users can contact you for feed back. One of the ways is to use ShellExecute to open Microsoft Outlook and fills in the "To:" field the required email address.

Illustration:

 

What You Need?:

1. One form named form1

2. One CommandButton named cmdEmail

3. One TextBox Named txtEmail

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 cmdMail_Click()

ShellExecute hWnd, "open", "mailto:" & txtEmail.Text, vbNullString, vbNullString, SW_SHOW

End Sub

Code:

 

Explanation:

With the parameter "Mailto:", ShellExecute let u launch the shell's email client utility and fill into the "To:" field the email address you want to send an E-Mail to. Here, we use txtEmail to be the input of the specific email address.

ShellExecute has many other useful uses as you will see in other examples

Hint:

See How to Open a Link or a Window for more uses of ShellExecute

VB-Pedia:

· Form: a member of VB Library which is a window or dialog box that makes up part of an application's user interface.

 

· CommandButton: a member of VB Library which looks like a push button and is used to begin, interrupt, or end a process.

 

· ShellExecute: a private function of the windows Library "shell32.dll". It performs an operation on a specified file.

Parameters

¨ hwnd

Handle to the owner window used for displaying a user interface (UI) or error messages. This value can be NULL if the operation is not associated with a window.

¨ lpOperation

Pointer to a null-terminated string, referred to in this case as a verb, that specifies the action to be performed. The set of available verbs depends on the particular file or folder. Generally, the actions available from an object's shortcut menu are available verbs.

¨ lpFile

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.

¨ lpParameters

If the lpFile parameter specifies an executable file, lpParameters 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.

¨ lpDirectory

Pointer to a null-terminated string that specifies the default directory.

¨ nShowCmd

Flags that specify how an application is to be displayed when it is opened.

* SW_SHOW: Activates the window and displays it in its current size and position.

Sponsored Links

Google
 
Web vbmania2006.brinkster.net
planet-source-code.com support.microsoft.com