gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-03 15:41:01 24 4
gpt4 key购买 nike

我想打开一个 *.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;

但是什么也没发生。那么我应该改变什么?

最佳答案

How do I open a file with the default text editor?

您需要使用ShellExecuteEx并使用SHELLEXECUTEINFOlpClass成员指定您要将文件视为文本文件。像这样:

procedure OpenAsTextFile(const FileName: string);
var
sei: TShellExecuteInfo;
begin
ZeroMemory(@sei, SizeOf(sei));
sei.cbSize := SizeOf(sei);
sei.fMask := SEE_MASK_CLASSNAME;
sei.lpFile := PChar(FileName);
sei.lpClass := '.txt';
sei.nShow := SW_SHOWNORMAL;
ShellExecuteEx(@sei);
end;

将文件的完整路径作为 FileName 传递。

关于delphi - 如何使用默认文本编辑器打开文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16941455/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com