如何查找和检测应用程序(在我的情况下为MS EXCEL)是否处于活动状态? [英] How to find and detect if an application( in my case, MS EXCEL ) is ACTIVE?

查看:110
本文介绍了如何查找和检测应用程序(在我的情况下为MS EXCEL)是否处于活动状态?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用MFC Visual C ++ 4.2.

我已经在我的应用程序中嵌入了MS Excel自动化过程.

在过去的1个月中,我的产品运行良好.

我的应用每次执行自动化过程时,都会创建一个新的Excel调度应用,如下所示:

if(!app.CreateDispatch(" Excel.应用程序'')){
消息框(``应用程序创建失败'',``查询工具'',MB_TOPMOST | MB_ICONERROR); ,此过程将花费很多时间并减慢系统速度.

因此,现在我正在考虑如何处理用户已运行Excel应用程序并且他们也运行我的应用程序以执行Excel自动化的情况.

我的想法是检查系统是否运行了1个Excel应用程序,我只需要创建/打开一个NEW WORKBOOK,而不是创建一个花费很多时间的NEW EXCEL应用程序对象.

因此,为了避免系统运行缓慢,如果尚未打开任何MS Excel应用程序,我将创建一个新的EXCEL应用程序对象.

如何检查MS Excel应用程序是否存在/已运行?

可以使用FindWindow做到吗?

谢谢.

I use MFC Visual C++ 4.2.

I have embedded a MS Excel automation process in my application.

I have it working well for the last 1 month.

Everytime my app do the automation process, it creates a new Excel dispatch app like this:

    if( !app.CreateDispatch( "Excel.Application" ) ){
            MessageBox( "Application Creation Failed", "Inquiry Tool", MB_TOPMOST | MB_ICONERROR );
            return FALSE;
        }

My opinion, this process will take much time and slowing down the system.

So now I am thinking of how to handle if users have an Excel app ran and they also ran my application to do Excel automation.

I have the idea to check if the system has 1 Excel application ran, I just need to create / open a NEW WORKBOOK instead of creating a NEW EXCEL APPLICATION OBJECT that takes much time.

So to avoid system being slow down, I will just create a NEW EXCEL APPLICATION OBJECT if there HAS NOT BEEN any MS Excel app opened.

How to check if the MS Excel app has exist / ran?

Can I do it by using FindWindow?

Thank you.

推荐答案

Hello Christiawan,

Hello Christiawan,

要枚举所有窗口,请使用EnumWindows()或EnumDesktopWindows().但是,如果当前正在将Excel实例作为自动化服务器运行,则不确定是否将与之关联的任何窗口.

To enumerate the all windows, use EnumWindows() or EnumDesktopWindows(). However, if an instance of Excel is currently being run as an automation server, I'm not sure if there will be any windows associated with it. 

祝你好运,
-Bio.

Best of luck,
- Bio.


这篇关于如何查找和检测应用程序(在我的情况下为MS EXCEL)是否处于活动状态?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆