大橙子网站建设,新征程启航
为企业提供网站建设、域名注册、服务器等服务
FindWindowEx
目前创新互联公司已为1000多家的企业提供了网站建设、域名、虚拟空间、网站托管、服务器租用、企业网站设计、正阳网站维护等服务,公司将坚持客户导向、应用为本的策略,正道将秉承"和谐、参与、激情"的文化,与客户和合作伙伴齐心协力一起成长,共同发展。
VB声明
Declare Function FindWindowEx Lib "user32" Alias
"FindWindowExA" (ByVal hWnd1 As Long, ByVal hWnd2 As Long, ByVal lpsz1 As
String, ByVal lpsz2 As String) As Long
说明
在窗口列表中寻找与指定条件相符的第一个子窗口
返回值
Long,找到的窗口的句柄。如未找到相符窗口,则返回零。会设置GetLastError
参数表
参数
类型及说明
hWnd1
Long,在其中查找子的父窗口。如设为零,表示使用桌面窗口(通常说的顶级窗口都被认为是桌面的子窗口,所以也会对它们进行查找)
hWnd2
Long,从这个窗口后开始查找。这样便可利用对FindWindowEx的多次调用找到符合条件的所有子窗口。如设为零,表示从第一个子窗口开始搜索
lpsz1
String,欲搜索的类名。零表示忽略
lpsz2
String,欲搜索的类名。零表示忽略
获取方法,参考实例如下:
'获取路径名各部分:
如:
c:\dir1001\aaa.txt
'获取路径路径
c:\dir1001\
Public
Function
GetFileName(FilePathFileName
As
String)
As
String
'获取文件名
aaa.txt
On
Error
Resume
Next
Dim
i
As
Integer,
J
As
Integer
i
Len(FilePathFileName)
J
InStrRev(FilePathFileName,
"\")
GetFileName
Mid(FilePathFileName,
J
+
1,
i)
End
Function
''获取路径路径
c:\dir1001\
Public
Function
GetFilePath(FilePathFileName
As
String)
As
String
'获取路径路径
c:\dir1001\
On
Error
Resume
Next
Dim
J
As
Integer
J
InStrRev(FilePathFileName,
"\")
GetFilePath
Mid(FilePathFileName,
1,
J)
End
Function
'获取文件名但不包括扩展名
aaa
Public
Function
GetFileNameNoExt(FilePathFileName
As
String)
As
String
'获取文件名但不包括扩展名
aaa
On
Error
Resume
Next
Dim
i
As
Integer,
J
As
Integer,
k
As
Integer
i
Len(FilePathFileName)
J
InStrRev(FilePathFileName,
"\")
k
InStrRev(FilePathFileName,
".")
If
k
Then
GetFileNameNoExt
Mid(FilePathFileName,
J
+
1,
i
-
J)
Else
GetFileNameNoExt
Mid(FilePathFileName,
J
+
1,
k
-
J
-
1)
End
If
End
Function
'=====
'获取扩展名
.txt
Public
Function
GetFileExtName(FilePathFileName
As
String)
As
String
'获取扩展名
.txt
On
Error
Resume
Next
Dim
i
As
Integer,
J
As
Integer
i
Len(FilePathFileName)
J
InStrRev(FilePathFileName,
".")
If
J
Then
GetFileExtName
".txt"
Else
GetFileExtName
Mid(FilePathFileName,
J,
i)
End
If
End
Function
Imports System.Runtime.InteropServices
Module winapi
DllImport("User32.dll", CallingConvention:=CallingConvention.StdCall, EntryPoint:="GetWindowThreadProcessId") _
Function GetWindowThreadProcessId(ByVal hwnd As IntPtr, ByRef procId As UInt32) As UInt32
End Function
DllImport("kernel32.dll", CallingConvention:=CallingConvention.StdCall, EntryPoint:="OpenProcess") _
Function OpenProcess(ByVal access As UInt32, ByVal inherit As Boolean, ByVal procid As UInt32) As IntPtr
End Function
DllImport("kernel32.dll", CallingConvention:=CallingConvention.StdCall, EntryPoint:="CloseHandle") _
Function CloseHandle(ByVal handle As IntPtr) As Boolean
End Function
DllImport("psapi.dll", CallingConvention:=CallingConvention.StdCall, EntryPoint:="GetModuleFileNameExW", Charset:=CharSet.Unicode) _
Function GetModuleFileNameExW(ByVal hProc As IntPtr, ByVal hMod As IntPtr, ByVal arrName() As Char, ByVal arrSize As UInt32) As UInt32
End Function
End Module
Public Class Form1
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim procid As UInt32
GetWindowThreadProcessId(Me.Handle, procid)
Dim handle As IntPtr
handle = OpenProcess(1040, False, procid)
Dim name(65536) As Char
Dim nameSize As UInt32 = GetModuleFileNameExW(handle, IntPtr.Zero, name, 65536)
Dim strName As String = New String(name, 0, nameSize)
CloseHandle(handle)
MsgBox(strName)
End Sub
End Class
可恶……我不会vb……临时去七拼八凑查了点语法……尽力了
Dim FileProperties As FileVersionInfo =
FileVersionInfo.GetVersionInfo("C:\XXXX\XXX.exe")
dim str as string = FileProperties.ProductName