Usage and differences of Shell and ShellExecute functions in VB

Source: Internet
Author: User

Write a VBProgramTo integrate the original programs of VB and VC. Is to use shell functions. The results show that the VC program can be properly displayed, but the VB program is minimized when it is written. I checked the following carefully:ArticleThe default display mode of the original shell function is windowstyle, which is equal to vbminimizedfocus. Then add a vbnormalfocus directly. Everything is OK!

Usage of Shell functions in VB:

Function: Execute an executable file and return a variant (double). If it succeeds, it indicates the task ID of the program. If it fails, it returns 0.

Syntax: Shell (pathname [, windowstyle])

The syntax of the shell function contains the following naming parameters:

Required pathname parameters. Variant (string), the name of the program to be executed, and any required parameters or command line variables, may also include directories or folders, and drives.

Optional. Variant (integer) indicates the window style when the program is running. If windowstyle is omitted, the program runs in a minimized window with focus.

ShellExecute Function:
Its usage is complicated, but its functions are more powerful.

Hinstance ShellExecute (
Hwnd, 'parent window handle
Lpctstr lpoperation, 'Operation or open method "edit", "lead E", "open", "find", "print", "null"
Lptstr lpfile, 'file name. The preceding path can be added.
Lptstr lpparameters, 'Parameter
Lpctstr lpdirectory, 'default folder
Int nshowcmd' Display Mode
);

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. Shell functions are relatively weak in this aspect,

In most cases, ShellExecute is more used,
 
LR = ShellExecute (Me. hwnd, "open", sfile, "", "", vbnormalfocus)
If (LR <0) or (LR> 32) then
'Success
Else
Msgbox "cannot open '" & sfile & "'", vbinformation
End if

Appendix:
This function can also be used to connect to a webpage. Just write it as follows:
ShellExecute 0 &, vbnullstring, "http://coolbasic.yeah.net", vbnullstring, vbnullstring, vbnormalfocus

Or write it like this to send an email:
ShellExecute me. hwnd, "open", "mailto: vbcode@vbcode.com", vbnullstring, vbnullstring, sw_show

In addition, the alternative use of ShellExecute is simpler and more practical. You can use a shell without using APIs!

Connect to the webpage:
Shell "rundll32.exe URL. dll, fileprotocolhandler http://www.online.sh.cn"
Open the file:
Shell "rundll32.exe URL. dll, fileprotocolhandler" & App. Path & "shelltst. txt"

 

Related Article

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.