在MFC中启动外部exe,如果已经打开,如何将exe置于前面?
我必须在 MFC 应用程序中打开一个外部程序,该程序可以工作,但如果我已经单击了按钮,我不希望它打开另一个实例,而只是将其放在前面。文档说 SW_SHOWNORMAL 参数可以做到这一点,但它对我不起作用。被调用的程序是否也必须为此进行设置?
ShellExecute(NULL, "open", "C:\Test\blahblah.exe", NULL, NULL, SW_SHOWNORMAL);
谢谢, CP
I have to open up a external program in my MFC application, which works but if I have already clicked button, I don't want it to open another instance but just bring it to front. The docs say the SW_SHOWNORMAL parameter does this, but it is not working for me. Does the called program have to setup for this also?
ShellExecute(NULL, "open", "C:\Test\blahblah.exe", NULL, NULL, SW_SHOWNORMAL);
Thanks,
CP
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
该文档有点不清楚,这可能让您感到困惑。当以可执行程序为目标时,
ShellExecute()
将始终启动一个新进程。当文档提到恢复最小化窗口时,它指的是如果您正在定位一个文档(如 Word 文档),并且注册用于显示该文档的应用程序已经在运行。最好的选择是:
FindWindow() 在 MFC 应用程序中尝试查找外部应用程序,然后仅在外部应用程序不存在时运行 ShellExecute()
,否则激活现有窗口。The documentation is a bit unclear, which might have been what confused you. When targetting an executable program,
ShellExecute()
will always launch a new process. What the documentation is referring to when it mentions restoring a minimized window is if you are targetting a document (like a Word doc), and the application registered to display the document is already running.Your best bet is to either:
FindWindow()
in your MFC application to try to locate the external application, and then only runShellExecute()
if it doesn't already exist, otherwise activating the existing window.