Wndows shell programming-call "open method ..." Dialog Box to open the document

Source: Internet
Author: User
Example:
Add a shellapi unit to use

VaR
Filepath: string;
Shellreturn: integer;
Begin
Filepath: = file path + file name
If filepath <> ''then
Begin
Shellreturn: = ShellExecute (handle, pchar ('open'), pchar (filepath), nil, nil, 1 );
If shellreturn <= 32 then
Case shellreturn
0: MessageBox (handle, 'the system resource is insufficient. An error occurred while opening the file! ', 'Failed', mb_ OK + mb_iconstop );
Se_err_associncomplete: MessageBox (handle, 'the specified file name does not comply with the Windows normal', 'failed', mb_ OK + mb_iconerror );
Se_err_fnf: MessageBox (handle, 'the specified file is not found', 'failed', mb_ OK + mb_iconerror );
Se_err_oom: MessageBox (handle, 'There is not enough memory to complete the operation. Opening the file failed! ', 'Failed', mb_ OK + mb_iconstop );
Se_err_pnf: MessageBox (handle, 'not found in the specified directory', 'failed', mb_ OK + mb_iconerror );
{When the returned value indicates that this type of file is not registered in the system, the system 'open method... 'dialog box is called}
Se_err_noassoc: winexec (pchar ('rundll32 shell32, openas_rundll '+ filepath), sw_showdefault );
Else
MessageBox (handle, 'file opening failed', 'failed', mb_ OK + mb_iconerror );
End;
End;
End;

Here:
ShellExecute (handle, pchar ('open'), pchar (filepath), nil, nil, 1); used to directly open registered files (or web pages, Program )

Winexec (pchar ('rundll32 shell32, openas_rundll '+ filepath), sw_showdefault); used to call the 'open method...' dialog box to open the file
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.