Open web page in VC

Source: Internet
Author: User
Tags microsoft outlook

The meanings of the parameters and prototype of the ShellExecute Function are as follows:

ShellExecute (

Hwnd, // parent window handle (such as null and handle)

Lpcstr lpoperation, // operation type (for example, "open") * double quotation marks must be added.

Lpstr lpfile, // file or path to be operated

Lpstr lpparameters, // when lpoperation is set to "too E", specify the parameter to be passed. It is usually set to null.

Lpstr lpdirectory, // specify the default directory, which is usually set to null

Int nshowcmd // specifies the mode in which the file is opened, which is usually maximized or minimized, and generally sw_shownormal.

)

Example:

// Call the Calculator

ShellExecute (null, "open", "calc.exe", null, null, sw_shownormal );

// Call notepad

ShellExecute (null, "open", "Notepad. EXE", null, null, sw_shownormal );

● 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 to the application Main Window handle, that is, application. Handle, or desktop window handle (obtained using the getdesktopwindow function ).

● Operation: Specifies the operation to be performed. The "open" operation indicates that the program specified by the filename parameter is executed, or the file or folder specified by the filename parameter is opened. The "print" operation indicates that the file specified by the filename parameter is printed; 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, the name of the program file to be executed, or the name of the folder to be browsed.

● Parameters: If the filename parameter is an executable program, this parameter specifies the command line parameter; otherwise, this parameter should be nil or pchar (0 ).

● Directory: used to specify the default directory.

● Showcmd: If the filename parameter is an executable program, this parameter specifies the initial display mode of the program window. Otherwise, this parameter should be set to 0.

If the ShellExecute Function is successfully called, the returned value is the instance handle of the executed program. 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 your machine, the function determines which browser to start based on the settings of the HTTP handler (Protocols handler) in Windows 9x/NT Registry.

Format 1: http: // website domain name.

Example: ShellExecute (handle, "open", http ://;

Www.neu.edu.cn ', null, null, sw_shownormal );

Format 2: http: // website domain name/Webpage file name.

Example: ShellExecute (handle, "open", http ://;

Www.neu.edu.cn/default.htm', null,null,

Sw_shownormal );

If you set the filename parameter to the "mailto:" protocol format, this function starts the default mail client program, such as Microsoft Outlook (including Microsoft Outlook Express) or Netscape Messanger. If multiple email client programs are installed on your machine, this function determines which email client program to start based on the settings of the mailto protocol handler in the Windows 9x/NT Registry.

Format 1: mailto:

For example, ShellExecute (handle, "open", "mailto:", null, null, 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", null, null, sw_shownormal); opens a new mail window and automatically fills 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.

Example (Delphi ):

Call c: \ project1.exe in an application;

ShellExecute (handle, 'open', 'c: \ project1.exe ', 'string content', nil, sw_shownormal );

In project1.exe, you can call:

Procedure tform1.formcreate (Sender: tobject );

VaR I: integer;

Begin

For I: = 1 to paramcount do

If paramstr (I) <> ''then showmessage (paramstr (I ));

End;

The last parameter specifies the visibility command for the window.

Use any of the following Constants

Sw_hide hides the window, and the activity status gives a window

Sw_minimize minimizes the window, and the active status gives a window

Sw_restore displays a window with the original size and position, and enables it to enter the active status.

Sw_show displays a window with the current size and position, and enables it to enter the active status.

Sw_showmaximized: Maximize the window and activate it.

Sw_showminimized minimizes the window and activates it.

Sw_showminnoactive minimizes a window without changing the activity window.

Sw_showna displays a window with the current size and position without changing the activity window.

Sw_shownoactivate displays a window with the latest size and position without changing the activity window.

Sw_shownormal is the same as sw_restore.

---

2. Access a Web page without the address bar, toolbar, and status bar of IE, And the buttons for minimization and maximization are provided.

# Include <urlmon. h>

# Include <tchar. h>

# Pragma comment (Lib, "urlmon ")

# Include <basetyps. h>

Typedef hresult stdapicalltype showhtmldialogfn (hwnd hwndparent,

Imoniker * PMK,

Variant * pvarargin,

Wchar * pchoptions,

Variant * pvarargout

);

Void ctesthtmldlgdlg: onok ()

{

// Todo: add extra validation here

Hmodule hmshtml = loadlibrary (text ("mshtml. dll "));

Bool fsuccess;

Wchar szurl [] = l "http://www.csdn.net ";

Imoniker * pmoniker = NULL;

Wchar szoptions [] = l "dialogheight: 179px; dialogwidth: 265px; dialogtop: 99px; dialogleft: 390px; edge: raised; center: Yes; help: Yes; resizable: yes; status: Yes ;";

Variant varreturn;

Variantinit (& varreturn );

Showhtmldialogfn * pfnshow;

If (! Hmshtml)

{

Fsuccess = false;

Goto cleanup;

}

Pfnshow = (showhtmldialogfn *) getprocaddress (hmshtml, text ("showhtmldialog "));

If (! Pfnshow)

{

Fsuccess = false;

Goto cleanup;

}

If (failed (createurlmoniker (null, szurl, & pmoniker )))

{

Fsuccess = false;

Goto cleanup;

}

(Pfnshow) (null, pmoniker, null, szoptions, & varreturn );

// (Pfnshow) (null, pmoniker, null, null, & varreturn );

//: MessageBox (null, "Show HTML dialog", "", mb_ OK );

Cleanup:

If (pmoniker)

Pmoniker-> release ();

If (hmshtml)

Freelibrary (hmshtml );

}

3. display HTML files in a dialog box

// Start with the header file or. cpp File
Contains the urlmon. h file and defines the function.
/////
# Include "urlmon. H"
Typedef hresult stdapicalltype showhtmldialogfn
(Hwnd hwndparent, imoniker
* PMK, variant * pvarargin, tchar * pchoptions,
Variant * pvargout );
//////

// Function display dialog box. If the function is displayed successfully, true is returned. If the function fails, false is returned.
Bool showhtml ()
{
Hinstance hinstmshtml = loadlibrary
(Text ("mshtml. dll"); // Load dynamic connections
Database Connection
Wchar URL [] = l "http: // www.ccw.com.cn ";
// This address name can be directly replaced by an HTML file name

If (hinstmshtml) // The dynamic Connection Library is loaded successfully.
{
Showhtmldialogfn * pfnshowhtmldialog;

Pfnshowhtmldialog = (showhtmldialogfn *)
Getprocaddress (hinstmshtml,
Text ("showhtmldialog "));

If (pfnshowhtmldialog)
{
Imoniker * moniker = NULL;

//
If (failed (createurlmoniker (null,
(Lpwstr) URL, & moniker )))
{
Freelibrary (hinstmshtml );
Return false;
}

// Call the showhtmldialog function to display the HTML file on the URL
Pfnshowhtmldialog (m_hwnd, moniker, null, null );

If (moniker! = NULL)
Moniker-> release ();

// Returns true if the display is successful.
Return true;

}
Else // getprocessaddress failed
Return false;

Freelibrary (hinstmshtml );
}
Else // failed to load the dynamic Connection Library
Return false;
}

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.