找到一个消息框在一个特定的应用程序? [英] Finding a MessageBox in a specific app?

查看:151
本文介绍了找到一个消息框在一个特定的应用程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们实现了一个解决方案,让我们的内部用户,他们需要重新部署我们的应用程序唠叨消息。我们正在使用的文件系统的专家以监控网络,寻找其中一直行之有效的特定文件的变化。大部分的功能​​已在大部分的我们的应用程序的形式继承基窗体类中实现。一个新的消息框将显示每五分钟,直到重新部署应用程序。它唠叨他们足够的,它有效地让他们重新部署,但让他们完成了不管他们做的,如果他们需要。

We have implemented a solution to give our internal users a nag message that they need to redeploy our application. We are using the filesystem watcher to monitor the network and look for a change in a specific file which has worked very well. Most of the functionality has been implemented in a base form class that most of the forms of our application inherit from. A new message box will be displayed every five minutes until the redeploy the app. It nags them enough that its effective in getting them to redeploy but lets them finish up whatever their doing if they need to.

这个问题正在运行到如果用户离开办公桌,他们可能有20多,当他们返回消息框。所以,我们现在要做的就是找​​出他们是否解雇消息框与否。如果他们没有解雇任何理由显示另外一个。

The problem were running into if the user is away from their desk they might have 20+ message boxes when they return. So what we're trying to do is figure out if they have dismissed the message box or not. If they haven't dismissed no reason to display another one.

它们不仅可以具有运行实现此功能,他们还可以有多个非常相同的应用程序的运行刚连接到不同的环境中的多我们的不同的应用。

They not only can have multiple our different applications running that implement this functionality they also can have multiple of the very same app running just connected to a different environment.

我成功地找到与FindWindow函数的消息框,但我不知道哪个应用程序的哪个特定实例,它属于,所以我不能只是假设它属于当前实例。我希望FindWindowEx工作由刚好路过的消息框的所有者的手柄插入API调用,但我一直没成功。它总是返回零。

I was successful in finding the message boxes with FindWindow but i didn't know which specific instance of which application it belongs to so i can't just assume it belongs to the current instance. I was hoping FindWindowEx work by just passing the handle of the owner of the message box into the api call but i haven't been successful. It always returns zero.

在codeI将显示在vb.net,但我熟练使用C#和放大器; vb.net所以也无所谓什么形式的解决方案的原因。

The code i will be showing is in vb.net but i'm proficient in both c# & vb.net so it doesn't matter what form the solution comes in.

反正这里是出code抛出了通知:

Anyways here is out code that throws up the notification:

Private Sub InitDeploymentCheck()
    moDeploymentCheck = New TRS.Deployment.TRSDeploymentCheck(EnvironmentVariables.Environment, AppDomain.CurrentDomain.BaseDirectory.Contains("bin"), MDIMain)
    AddHandler moDeploymentCheck.DeploymentNeeded,
        Sub()
            moTimer = New Timer()
            moTimer.Interval = 300000 '5 minutes
            moTimer.Enabled = True
            AddHandler moTimer.Tick,
                Sub()
                    'check to see if the message box exist or not before throwing up a new one
                    MessageBox.Show(MDIMain, "There is a recent critical deployment, please re-deploy STAR to get latest changes.", "Critical Deployment", MessageBoxButtons.OK, MessageBoxIcon.Warning)
                End Sub
            MessageBox.Show(MDIMain, "There is a recent critical deployment, please re-deploy STAR to get latest changes.", "Critical Deployment", MessageBoxButtons.OK, MessageBoxIcon.Warning)
        End Sub

我能找到的窗口:

I was able to find the window:

Dim handle As IntPtr = FindWindow(Nothing, "Critical Deployment")

这我我如何试图找到FindWindowEX窗口:

This i how i tried to find the window with FindWindowEX:

Dim t As IntPtr = FindWindowEx(200398, IntPtr.Zero, "Form", "Critical Deployment")

200398是从mdimain上述手柄

200398 is the handle from mdimain above.

推荐答案

一旦你的 HWND 处理到一个窗口,你可以使用 GetWindowLong (GWL_HINSTANCE) GetWindowThreadProcessId()来检查哪些应用程序实例窗口属于。使用 EnumWindows的()来枚举所有顶级窗口,在这里你的回调函数检查每个报告窗口的标题和流程实例,直到你找到你正在寻找一个匹配。

Once you have the HWND handle to a window, you can use GetWindowLong(GWL_HINSTANCE) or GetWindowThreadProcessId() to check which application instance the window belongs to. Use EnumWindows() to enumerate all top-level windows, where your callback function checks the title and process instance of each reported window until you find a match you are looking for.

这篇关于找到一个消息框在一个特定的应用程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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