1
我的Outlook Express始终位于顶端,Google Chrome位于Outlook后面。如何使用Visual Basic在OutLook Express上运行谷歌浏览器?如何将外部应用程序窗口置于顶部?
以下打开一个新的应用程序,但我希望现有的谷歌浏览器顶部?
Shell("C:\Program Files (x86)\Google\Chrome\Application\chrome.exe", AppWinStyle.MaximizedFocus)
编辑:
Public Class Form1
Declare Auto Function FindWindow Lib "User32.dll" (ByVal lpClassName As String, ByVal lpWindowName As String) As IntPtr
Declare Auto Function SetForegroundWindow Lib "User32.dll" (ByVal Hwnd As IntPtr) As Long
'Private Declare Function SetForegroundWindow Lib "user32.dll" (ByVal hwnd As Int32) As Int32
Declare Auto Function FindWindowEx Lib "User32.dll" (ByVal hwndParent As IntPtr, ByVal hwndChildAfter As IntPtr, ByVal lpszClass As String, ByVal lpszWindow As String) As IntPtr
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
'Shell("C:\Program Files (x86)\Google\Chrome\Application\chrome.exe", AppWinStyle.MaximizedFocus)
Dim Handle As IntPtr = FindWindow("Notepad", Nothing)
If Handle.Equals(IntPtr.Zero) Then
End
End If
'Dim HandleChildOne As IntPtr = FindWindowEx(Handle, IntPtr.Zero, "Notepad", IntPtr.Zero)
'If HandleChildOne.Equals(IntPtr.Zero) Then
'End
'End If
Dim Result As Integer = SetForegroundWindow(Handle)
If Result.Equals(0) Then
End
Else
MsgBox("Above 0: success. https://msdn.microsoft.com/en-us/library/windows/desktop/ms633539(v=vs.85).aspx " & Result)
End If
End Sub
Private Sub Label1_Click(sender As Object, e As EventArgs) Handles Label1.Click
End
End Sub
End Class
不知道这是否是问题,但调用的是'SetForegroundWindow()'用小写字母“G” – AlanT
有Chrome的窗口位置/尺寸得到意外修改许多限制哪些进程可以设置前台窗口(https://msdn.microsoft.com/en-us/library/windows/desktop/ms633539(v=vs.85).aspx),所以它可能是你正在对其中一个犯规。首先,我会检查FindWindow()返回一个有效的句柄,然后检查SetForegroundWindow()的返回值。注意:其中一个限制是该进程无法被调试。 – AlanT
我不知道这是否是您的真实代码,因为您发布的第一个代码因为运行时错误而失败。您似乎也完全忽略了错误检查。为什么?你有没有想过调试? –