FindWindowEx

目前創(chuàng)新互聯(lián)公司已為1000多家的企業(yè)提供了網(wǎng)站建設(shè)、域名、虛擬空間、網(wǎng)站托管、服務(wù)器租用、企業(yè)網(wǎng)站設(shè)計、正陽網(wǎng)站維護(hù)等服務(wù),公司將堅持客戶導(dǎo)向、應(yīng)用為本的策略,正道將秉承"和諧、參與、激情"的文化,與客戶和合作伙伴齊心協(xié)力一起成長,共同發(fā)展。
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,找到的窗口的句柄。如未找到相符窗口,則返回零。會設(shè)置GetLastError
參數(shù)表
參數(shù)
類型及說明
hWnd1
Long,在其中查找子的父窗口。如設(shè)為零,表示使用桌面窗口(通常說的頂級窗口都被認(rèn)為是桌面的子窗口,所以也會對它們進(jìn)行查找)
hWnd2
Long,從這個窗口后開始查找。這樣便可利用對FindWindowEx的多次調(diào)用找到符合條件的所有子窗口。如設(shè)為零,表示從第一個子窗口開始搜索
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
'獲取文件名但不包括擴(kuò)展名
aaa
Public
Function
GetFileNameNoExt(FilePathFileName
As
String)
As
String
'獲取文件名但不包括擴(kuò)展名
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
'=====
'獲取擴(kuò)展名
.txt
Public
Function
GetFileExtName(FilePathFileName
As
String)
As
String
'獲取擴(kuò)展名
.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
網(wǎng)頁名稱:vb.net獲取程序名稱 vbs 獲取文件的文件名
本文路徑:http://chinadenli.net/article22/hijicc.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供關(guān)鍵詞優(yōu)化、服務(wù)器托管、商城網(wǎng)站、網(wǎng)站排名、定制網(wǎng)站、外貿(mào)建站
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)