Implement website links and send emails in programs

Source: Internet
Author: User
Tags microsoft outlook

More and moreProgramMembers prefer to writeProgramAdd a link to the website or email address. You only need to click the mouse to automatically open the browser and link to the specified URL address, or open the mail customerProgramOr even the recipient, email subject, and email body can be filled in for the user.
If you want to download updates and patches from your websiteProgram, Or introduce the latest product information to the user, you canProgramAdding a link to a website is much more convenient than enabling users to open their own browsers and then enter the website, which can also stimulate users' interest. IfProgramAdd a link to the email address, so that the user can directlyProgramResearchers send emails, which not only provide users with better technical support and after-sales services, but also facilitate user surveys and other activities.
This document uses Delphi as an example to describe how to useProgramLink to the specified site or send an email.
Working Principle
ManyProgramWe all know that the Windows API function ShellExecute can be used for execution.Program, Open a file or folder, but use this function to browse the URL address or send a new email, I am afraid there will not be much to undo. Because Windows HelpDocumentThis usage is not mentioned in win32.hlp.
1. Standard usage
The meanings of the parameters and prototype of the ShellExecute Function are as follows:
Function ShellExecute (hwnd: hwnd; operation, filename, parameters, directory: pchar; showcmd: integer): hinst; stdcall;
● Hwnd: Specifies the parent window handle. When an error occurs during a function call, it is used as the parent window of the Windows message window. For example, you can set it as an application.ProgramThe main window handle, that is, application. Handle, can also be set as a desktop window handle (obtained using the getdesktopwindow function ).
● Operation: Specifies the operation to be performed. The "open" operation indicates that the file specified by the filename parameter is executed.ProgramOr open a file or folder specified by the filename parameter. The "print" operation indicates printing the file specified by the filename parameter. The "Browse e" operation indicates browsing the folder specified by the filename parameter. If the parameter is set to nil, the default operation "open" is executed ".
● Filename: used to specify the name of the file to be opened and the name of the file to be executedProgramFile name or the name of the folder to be browsed.
● Parameters: If the filename parameter is executableProgramOtherwise, this parameter should be nil or pchar (0 ).
● Directory: used to specify the default directory.
● Showcmd: If the filename parameter is executableProgram, This parameter specifiesProgramThe initial display mode of the window. Otherwise, this parameter should be set to 0.
If the ShellExecute Function is successfully called, the returned value is executed.ProgramInstance handle. If the returned value is smaller than 32, an error occurs.
The above is only the standard usage of the ShellExecute Function. The following describes its special usage.
2. Special usage
If you set the filename parameter to the "http:" protocol format, this function opens the default browser and links to the specified URL address. If multiple browsers are installed on the user's machine, the function is processed according to the HTTP protocol in the Windows 9x/NT Registry.Program(Protocols handler) to determine which browser to start.
Format 1: http: // website domain name.
Example: ShellExecute (handle, 'open', 'HTTP ://
Www.neu.edu.cn ', nil, nil, sw_shownormal );
Format 2: http: // website domain name/Webpage file name.
Example: ShellExecute (handle, 'open', 'HTTP ://
Www.neu.edu.cn/default.htm', nil,nil,
Sw_shownormal );
If you set the filename parameter to the "mailto:" protocol format, this function will start the default mail customerProgramSuch as Microsoft Outlook (also including Microsoft Outlook Express) or Netscape Messanger. If multiple email clients are installed on the user machineProgramThe function is processed according to the mailto protocol in the Windows 9x/NT Registry.ProgramTo determine which mail customer to start.Program.
Format 1: mailto:
For example, ShellExecute (handle, 'open', 'mailto: ', nil, nil, sw_shownormal); opens the new mail window.
Format 2: mailto: User Account @ email server address
Example: ShellExecute (handle, 'open', 'mailto: who@mail.neu.edu.cn ', nil, nil, sw_shownormal); open the new mail window and automatically fill in the recipient address. If multiple recipient addresses are specified, the recipient addresses must be separated by semicolons or commas (, the same below ).
Format 3: mailto: User Account @ email server address? Subject = Email Subject & Body = Email body
Example: ShellExecute (handle, 'open', 'mailto: who@mail.neu.edu.cn? Subject = Hello & Body = This is a test ', nil, nil, sw_shownormal); opens the new mail window and automatically fills in the recipient address, mail subject, and mail body. If the mail body contains multiple lines of text, you must add the line feed escape character % 0a between each line of text.
Implementation Method
Create a New Delphi project and add two labels to the main formWidgetHttplabel and mailtolabel. LabelWidgetFont. set the color attribute to clblue and font. the style attribute is set to blank, the cursor attribute is set to crhandpoint, And the caption attribute is set to "Welcome to patronize our website" and "send to us" respectively ".
To simulate the hyperlink effect, firstWidgetIn the mousemove eventWidgetThe font. Color Attribute of is set to clred, and the style attribute is set to fsunderline.
Procedure tform1.httplabelmousemove (Sender: tobject; shift: tshiftstate; X, Y: integer );
Begin
Httplabel. Font. Color: = clred;
Httplabel. Font. Style: = [fsunderline];
End;
Procedure tform1.mailtolabelmousemove (Sender: tobject; shift: tshiftstate; X, Y: integer );
Begin
Mailtolabel. Font. Color: = clred;
Mailtolabel. Font. Style: = [fsunderline];
End;
Then, in the mousemove event of the main form, set the labelWidgetThe font. Color Attribute of is set to clblue, And the font. Style attribute is set to blank so that the mouse can exit the label.WidgetTime tagWidgetRestore the original display status.
Procedure tform1.formmousemove (Sender: tobject; shift: tshiftstate; X, Y: integer );
Begin
Httplabel. Font. Color: = clblue;
Httplabel. Font. Style: = [];
Mailtolabel. Font. Color: = clblue;
Mailtolabel. Font. Style: = [];
End;
FinallyWidgetIn The onclick eventProgramCode.
Procedure tform1.httplabelclick (Sender: tobject );
Begin
If ShellExecute (handle,
'Open ',
'Http: // www.neu.edu.cn ',
Nil,
Nil,
Sw_shownormal) <= 32 then
Showmessage ('network error occurred! ');
End;
Procedure tform1.mailtolabelclick (Sender: tobject );
Begin
If ShellExecute (handle,
'Open ',
'Mailto: who@mail.neu.edu.cn ',
Nil,
Nil,
Sw_shownormal) <= 32 then
Showmessage ('postal error occurred! ');
End;
Note: Because the ShellExecute Function is declared in the shellapi. Pas unit, you must add a reference to the shellapi. Pas unit:
Uses
Shellapi;
Of course, you can also create a hyperlink by yourself.WidgetFor ease of use.

 

This article from: http://www.programbbs.com/doc/2094.htm

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.