相关疑难解决方法(0)

如何使用Delphi从文件扩展名获取图标和描述?

基本上我有一个TcxGrid,它将列出各种文件名,我想根据文件扩展名给出更多细节,特别是它的描述(例如.PDF它的"Adobe Acrobat文档")和它的相关图标.

我注意到有一个非常类似的问题,但它与C#有关,我想要一些基于Delphi的东西.

关于在哪里查找这种信息的建议是好的,如果有一个类似于上面的C#帖子中提到的类(显然在Delphi中),这将是很好的.

windows delphi icons file-association

13
推荐指数
1
解决办法
2万
查看次数

应用程序是否与给定的扩展相关联?

有时需要让您的应用程序打开文件的默认应用程序.例如,要打开PDF文件,您可以使用:

System.Diagnostics.Process.Start("Filename.pdf");
Run Code Online (Sandbox Code Playgroud)


要打开图像,您只需使用具有不同文件名的相同代码:

System.Diagnostics.Process.Start("Filename.gif");
Run Code Online (Sandbox Code Playgroud)


一些扩展(例如.gif)几乎总是有一个默认的处理程序,即使在基本的Windows安装中也是如此.但是,某些扩展(例如.pdf)通常没有安装应用程序来处理它们.

在这些情况下,在调用Process.Start(fileName)之前,最好确定应用程序是否与要打开的文件的扩展名相关联.

我想知道如何最好地实现这样的事情:

static bool ApplicationAssociated(string extension)
{
    var extensionHasAssociatedApplication = false;

    var condition = // Determine if there is an application installed that is associated with the provided file extension.;
    if (condition)
    {
        extensionHasAssociatedApplication = true;
    }

    return extensionHasAssociatedApplication;
}
Run Code Online (Sandbox Code Playgroud)

c# file-extension

13
推荐指数
3
解决办法
9308
查看次数

将Chrome检测为与Windows中的html文件关联的浏览器

我们提供使用我们的应用程序安装在本地(Windows)硬盘上的Flash教程视频.我们的应用程序使用ShellExecute打开嵌入它们的html文件(在任何与html文件相关联的浏览器中).

显然,Chrome最新的Flash播放器中存在一个错误,无法播放本地文件(但网络上的文件很好.)

(坦率地说,我很惊讶谷歌没有修复这个错误.对我来说似乎是一个很大的问题......但也许没有多少人从网络以外的地方玩Flash?)

关于Chrome中的about:plugins屏幕有一个解决方法,但我们不能要求我们的用户这样做.以下是对解决方法的讨论:http://techsmith.custhelp.com/app/answers/detail/a_id/3518

我想为我的用户提供打开我们的HTML文件IE的选项. 如果Chrome是他们的默认浏览器,那么我会显示一个复选框,上面写着"如果我们的教程视频无法播放",请选中此复选框以在IE中试用它们.

这个XE2代码(两年前在SO:link上)是否仍然合理?

if pos('CHROME', UpperCase(GetAssociation('C:\Path\File.html')) > 0 then
  // Chrome is the default browser

function GetAssociation(const DocFileName: string): string;
var
  FileClass: string;
  Reg: TRegistry;
begin
  Result := '';
  Reg := TRegistry.Create(KEY_EXECUTE);
  Reg.RootKey := HKEY_CLASSES_ROOT;
  FileClass := '';
  if Reg.OpenKeyReadOnly(ExtractFileExt(DocFileName)) then
  begin
    FileClass := Reg.ReadString('');
    Reg.CloseKey;
  end;
  if FileClass <> '' then begin
    if Reg.OpenKeyReadOnly(FileClass + '\Shell\Open\Command') then
    begin
      Result := Reg.ReadString('');
      Reg.CloseKey;
    end;
  end;
  Reg.Free;
end;
Run Code Online (Sandbox Code Playgroud)

delphi google-chrome file-association

6
推荐指数
1
解决办法
1425
查看次数

如何使用默认文本编辑器打开文件?

我想打开一个*.conf文件.我想用标准Windows编辑器(例如,notepad.exe)打开此文件.

我目前有这个ShellExecute代码:

var
  sPath, conf: String;
begin
  try
  sPath := GetCurrentDir + '\conf\';
  conf := 'nginx.conf';
ShellExecute(Application.Handle, 'open', PChar(conf), '', Pchar(sPath+conf), SW_SHOW);
  except
    ShowMessage('Invalid config path.');
  end;
end; 
Run Code Online (Sandbox Code Playgroud)

但没有任何反应.那么我应该改变什么呢?

delphi shellexecute configuration-files

2
推荐指数
1
解决办法
9288
查看次数