将已经运行的应用程序带到前面 [英] bring an already running app to the front

查看:54
本文介绍了将已经运行的应用程序带到前面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的程序会检查另一个程序是否已在运行,如果是这样的话

我希望它能够恢复因为windows把它放到了其他程序,所以它b / b
出现在屏幕上的其他任何内容之上。我知道如何检查

看看它是否正在运行


如果是UBound(System.Diagnostics.Process.GetProcessesByNa me(programX)) )> 1

然后


那么什么?如何让programX恢复?


谢谢

解决方案

我应该注意到我'使用VB2003


cj写道:

我的程序检查另一个程序是否已经运行,如果是的话
我想要它 ;恢复"因为Windows将其他程序放在屏幕上的其他任何程序上。我知道如何查看是否正在运行

如果UBound(System.Diagnostics.Process.GetProcessesByNa me(programX))> 1
那么什么呢?如何让programX恢复?

谢谢



Cj,


我以为是这个,
http://msdn2.microsoft.com/en-us/lib...ngtofront.aspx


还有一个最顶层的财产,但这很烦人,它永远不会回来。


我希望这会有所帮助,


Cor


" cj" < cj@nospam.nospam> schreef在bericht

新闻:uL ************** @ TK2MSFTNGP02.phx.gbl ...

我的程序检查看如果另一个程序已在运行,如果是,我希望它恢复因为Windows将其他程序放在屏幕上的其他任何程序之上。我知道如何查看它是否正在运行

如果UBound(System.Diagnostics.Process.GetProcessesByNa me(programX))> 1
那么什么呢?如何让programX恢复?

谢谢





cj写道:< blockquote class =post_quotes>我的程序检查另一个程序是否已在运行,如果是的话
我希望它恢复因为Windows将其他程序放在屏幕上的其他任何程序上。我知道如何查看是否正在运行

如果UBound(System.Diagnostics.Process.GetProcessesByNa me(programX))> 1
那么什么呢?如何让programX恢复?

谢谢



AFAIK,唯一的方法是使用Windows API调用:


私有声明函数ShowWindow Lib" user32" _

(ByVal hWnd As System.IntPtr,ByVal nCmdShow As Long)As Long


Private Const SW_RESTORE = 9


然后当你想恢复窗口时:


Dim procArray As System.Diagnostics.Process

Dim proc As System.Diagnostics.Process


procArray = System.Diagnostics.Process.GetProcessesByName(" pro gramX")

如果procArray.Length> 0然后

proc = procArray(0)

ShowWindow(proc.MainWindowHandle,SW_RESTORE)

结束如果


我几乎建议使用AppActivate(proc.Id)代替对ShowWindow()的

调用(AppActivate可以直接使用而不需要

Imports语句;它是Microsoft.VisualBasic.Interaction

名称空间的一部分),但是如果你在一个最小化的窗口上调用AppActivate,它实际上不会是
恢复窗口,它只是激活任务栏而没有

最小化它,这在我看来有点毫无意义。


Mike S


My program checks to see if another program is already running and if so
I want it to "restore" as windows puts it that other program so it
appears on top of anything else on the screen. I know how to check to
see if it''s running

If UBound(System.Diagnostics.Process.GetProcessesByNa me("programX")) > 1
then

then what? How do I get programX "restored"?

Thanks

解决方案

I should have noted I''m using VB2003

cj wrote:

My program checks to see if another program is already running and if so
I want it to "restore" as windows puts it that other program so it
appears on top of anything else on the screen. I know how to check to
see if it''s running

If UBound(System.Diagnostics.Process.GetProcessesByNa me("programX")) > 1
then

then what? How do I get programX "restored"?

Thanks



Cj,

I thought that it was this one,
http://msdn2.microsoft.com/en-us/lib...ngtofront.aspx

There is as well a topmost property but that is anoying, it never goes back.

I hope this helps,

Cor

"cj" <cj@nospam.nospam> schreef in bericht
news:uL**************@TK2MSFTNGP02.phx.gbl...

My program checks to see if another program is already running and if so I
want it to "restore" as windows puts it that other program so it appears
on top of anything else on the screen. I know how to check to see if it''s
running

If UBound(System.Diagnostics.Process.GetProcessesByNa me("programX")) > 1
then

then what? How do I get programX "restored"?

Thanks




cj wrote:

My program checks to see if another program is already running and if so
I want it to "restore" as windows puts it that other program so it
appears on top of anything else on the screen. I know how to check to
see if it''s running

If UBound(System.Diagnostics.Process.GetProcessesByNa me("programX")) > 1
then

then what? How do I get programX "restored"?

Thanks



AFAIK, the only way to do this is to use a Windows API call:

Private Declare Function ShowWindow Lib "user32" _
(ByVal hWnd As System.IntPtr, ByVal nCmdShow As Long) As Long

Private Const SW_RESTORE = 9

And then later when you want to restore the window:

Dim procArray As System.Diagnostics.Process
Dim proc As System.Diagnostics.Process

procArray = System.Diagnostics.Process.GetProcessesByName("pro gramX")
If procArray.Length > 0 Then
proc = procArray(0)
ShowWindow(proc.MainWindowHandle, SW_RESTORE)
End If

I was almost going to suggest using AppActivate(proc.Id) instead of the
call to the ShowWindow() (AppActivate can be used directly without an
Imports statement; it''s part of the Microsoft.VisualBasic.Interaction
namespace), but if you call AppActivate on a minimized window, it won''t
actually restore the window, it just activates it the taskbar without
unminimizing it, which is kinda pointless in my opinion.

Mike S


这篇关于将已经运行的应用程序带到前面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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