Windows Client development-browser connection through the ShellExecute Function

Source: Internet
Author: User

Windows Client development-browser connection through the ShellExecute Function

There are often some links in our client. After clicking, we hope to navigate to the link through the browser.

We implemented it through the ShellExecute Function.

The function of ShellExecute is to run an external program (or open a registered file, open a directory, print a file, etc.) and control the external program.

Note: To use this function, introduce the header file:

#include 
  

Look at the function prototype:

ShellExecute (hWnd: HWND; {specify parent window handle} Operation: PChar; {specify actions, such as open, runas, print, edit, e, find [2]} FileName: PChar; {specify the file or program to be opened} Parameters: PChar; {specify Parameters for the program to be opened; if the file is opened, it should be nil} Directory: PChar; {default directory} ShowCmd: Integer {open option })

You can use ShellExecute to open notepad, calculator, and so on in windows.

What we need here is to open a link, such as www.baidu.com

Further, how do we specify a browser to open www.baidu.com.

We should repeat the parameters of this function:
LpFile [in]
Type: LPCTSTR
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]
Type: LPCTSTR
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 shocould be NULL.

LpDirectory [in, optional]
Type: LPCTSTR
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.

Therefore, we can use:

# Include
   
    
# Include
    
     
# Include
     
      
Int main () {// open www.baidu.com ShellExecute (NULL, L "open", L "iexplore.exe", L "www.baidu.com", NULL, SW_MAXIMIZE) in IE browser ); // use the sogou browser to open www.baidu.com ShellExecute (NULL, L "open", L "SogouExplorer.exe", L "www.baidu.com", NULL, SW_MAXIMIZE); // open www.baidu.com in the default browser, chrome ShellExecute (NULL, L "Open", L "www.baidu.com", 0, 0, SW_SHOWNORMAL); return 0 ;}
     
    
   

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.