【发布时间】:2014-11-18 20:21:23
【问题描述】:
这似乎是一项简单的任务,但我似乎无法产生寻找的结果。
目前我有这个代码
Dim folderpath As String
Private Sub Button4_Click(sender As Object, e As EventArgs) Handles Button4.Click
folderpath = "C:\epds\WIP"
Process.Start("explorer.exe", folderpath)
End Sub
这很好,它会按指示打开我的文件夹路径,但是,如果该文件夹的实例已经在资源管理器中打开,我该如何使该窗口成为当前窗口而不是打开新的窗口资源管理器?
编辑:这似乎可以解决问题,感谢@Okuma.Scott 为我指明正确的方向
<DllImport("user32.dll", SetLastError:=True, CharSet:=CharSet.Auto)> _
Private Shared Function FindWindow( _
ByVal lpClassName As String, _
ByVal lpWindowName As String) As IntPtr
End Function
<DllImport("user32.dll", EntryPoint:="FindWindow", SetLastError:=True, CharSet:=CharSet.Auto)> _
Private Shared Function FindWindowByClass( _
ByVal lpClassName As String, _
ByVal zero As IntPtr) As IntPtr
End Function
<DllImport("user32.dll", EntryPoint:="FindWindow", SetLastError:=True, CharSet:=CharSet.Auto)> _
Private Shared Function FindWindowByCaption( _
ByVal zero As IntPtr, _
ByVal lpWindowName As String) As IntPtr
End Function
Dim folderpath As String
Private Sub Button4_Click(sender As Object, e As EventArgs) Handles Button4.Click
folderpath = "C:\epds\WIP"
'Process.Start("explorer.exe", folderpath)
Dim nWnd As IntPtr
Dim ceroIntPtr As New IntPtr(0)
Dim Wnd_name As String
Wnd_name = "WIP"
nWnd = FindWindow(Nothing, Wnd_name)
'show the info
If nWnd.Equals(ceroIntPtr) Then
Process.Start("explorer.exe", folderpath)
Else
AppActivate(Wnd_name)
SendKeys.SendWait("~")
End If
End Sub
【问题讨论】:
-
我想打开 C:\epds\WIP 或者如果它已打开我想将其显示为当前窗口,明白吗? vb 不是 c#,我知道有转换器,但这不是我要找的。span>
-
我明白了。首先,您查看资源管理器是否已打开。如果是,请检查它浏览到的文件夹(我提供的链接)。如果它在您想要的地方,只需activate 即可。如果没有,请打开一个新的。
-
好的,谢谢。不过我想知道,是否总是至少有一个 explorer.exe 实例,而不一定是有问题的那个?只是想知道这是否会引起冲突。我会看看我能不能得到你链接到工作的东西。再次感谢您。
-
如果资源管理器没有打开,它就没有窗口。我的第一个猜测是使用findwindow 或者你可以使用try this。
标签: vb.net visual-studio