ShellExecute-默认的PDF阅读器? [英] ShellExecute -- default PDF reader?

查看:380
本文介绍了ShellExecute-默认的PDF阅读器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这对我有效,没有任何错误:

ShellExecute(NULL, _T("open"), _T("C:\\Program Files\\...."), NULL, NULL, SW_SHOW);

我在这里打开的文件是PDF文件,并且工作正常.我们知道ShellExecute将使用与PDF文件关联的任何查看器打开文件.但是我有一个问题,

1.)如果用户没有关联的PDF查看器,在这种情况下,ShellExecute将选择默认的PDF阅读器打开PDF?

2.)如果用户未安装任何acrobat或PDF阅读器或PDF查看器(他从来没有打开PDF文件的内容)怎么办?

This has worked for me without any errors:

ShellExecute(NULL, _T("open"), _T("C:\\Program Files\\...."), NULL, NULL, SW_SHOW);

The file i am opening here is a PDF file and its working fine. We know ShellExecute will open the file with whatever viewer the PDF file is associated with. But i am having a question,

1.) What if the user doesn''t have an associated viewer for the PDF, In this case what would be the default PDF reader the ShellExecute will pick to open the PDF?

2.) What if the user doesn''t have any acrobat or PDF reader or PDF viewer installed (he never has anything to open a PDF file)? How do i handle this case?

推荐答案

如果.pdf文件扩展名未与任何程序关联,则ShellExecute将返回SE_ERR_NOASSOC.

如果发生这种情况,一种很好的处理方法是在以下命令行上执行新的ShellExecute:
rundll32.exe shell32.dll,OpenAs_RunDLL,后跟您的.pdf文件的名称.这将向用户显示Windows的打开方式"对话框,该对话框允许将程序与此扩展名关联.

您也可以决定做其他事情,例如给出一个带有URL的MessageBox来下载Acrobat Reader.
If the .pdf file extension is not associated with any program, ShellExecute will return with SE_ERR_NOASSOC.

If this happens, a nice way to handle it would be to do a new ShellExecute on the following command line:
rundll32.exe shell32.dll,OpenAs_RunDLL, followed by the name of your .pdf file. This will present the user with the Windows ''Open with'' dialog, which allows to associate a program with this extension.

You could decide to do something else too though, f.e. give a MessageBox with the URL to download Acrobat Reader.


ShellExecute返回几个错误.在您的情况下,您将得到SE_ERR_NOASSOC.请参阅文档以获取完整的错误列表. http://msdn.microsoft.com/en-us/library/bb762153 (v = vs.85).aspx [
ShellExecute returns several errors. In your case you will get SE_ERR_NOASSOC. See the documentation for comeplete error list. http://msdn.microsoft.com/en-us/library/bb762153(v=vs.85).aspx[^]


这篇关于ShellExecute-默认的PDF阅读器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆