jos*_*hlf 5 windows terminal editor
在 Unix 系统上,要求用户编辑一些足够复杂的文本的正常模式是打开 或VISUAL环境EDITOR变量中指定的编辑器,并将该编辑器指向一个用您希望用户编辑的内容初始化的临时文件。Windows 上是否有与此模式等效的东西?如果有,它是如何工作的?
如果您希望您的应用程序打开配置文件以供用户编辑,您可以这样做(C++):
if( (INT_PTR)ShellExecute( NULL, "open", "config.json", NULL, NULL, SW_SHOWDEFAULT) <= 32 )
if( (INT_PTR)ShellExecute( NULL, "open", "notepad.exe", "config.json", NULL, SW_SHOWDEFAULT) <= 32 ){
MessageBox( ourHwnd, "Fail to open editor. Please edit config.json", "Error", MB_ICONERROR );
}
Run Code Online (Sandbox Code Playgroud)
That will first attempt to open "config.json" like Windows will do if user would double click on it. I assume that if user have favorite text editor, he/she will associate that editor with *.json, *.txt, and other text files. If that fail, then lunch notepad with "config.json" as argument. That should not fail, but I once saw user removing notepad to have more space on hard disk, so it can fail, so if that fail then just display error message.
According to microsoft documentation ShellExecute can take "edit" as second argument. So it looks like functionality like this exists or was planed, but I'm not awere of any option for user to change what edit does in Windows. So I wouldn't use that.