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

后端 未结 3 1182
盖世英雄少女心
盖世英雄少女心 2020-12-18 13:11

I want to open a *.conf file. I want to open this file with the standard Windows editor (e.g., notepad.exe).

I currently have this ShellExecute code:



        
3条回答
  •  轮回少年
    2020-12-18 13:33

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

    You need to use ShellExecuteEx and use the lpClass member of SHELLEXECUTEINFO to specify that you want to treat the file as a text file. Like this:

    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;
    

    Pass the full path to the file as FileName.

提交回复
热议问题