VB 修改窗口标题
用VB如何修改其他的窗口标题,注意:要获取不完全的窗口标题!比如一个窗口标题是111222但后面的222是随机出现的,所以如何让他只判断前面的111并修改?不能取得全部的...
用VB 如何修改其他的窗口标题,注意:要获取不完全的窗口标题!
比如一个窗口标题是111 222 但后面的222是随机出现的,所以如何让他只判断前面的111 并修改?
不能取得全部的标题...标题中有部分是随机出现的..如何只判断一部分标题 展开
比如一个窗口标题是111 222 但后面的222是随机出现的,所以如何让他只判断前面的111 并修改?
不能取得全部的标题...标题中有部分是随机出现的..如何只判断一部分标题 展开
4个回答
展开全部
查找所有窗体,然后匹配一下
Option Explicit
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String, ByVal cch As Long) As Long
Private Declare Function GetWindow Lib "user32" (ByVal hwnd As Long, ByVal wCmd As Long) As Long
Private Declare Function GetDesktopWindow Lib "user32" () As Long
Private Declare Function GetClassName Lib "user32" Alias "GetClassNameA" (ByVal hwnd As Long, ByVal lpClassName As String, ByVal nMaxCount As Long) As Long
Private Declare Function SetWindowText Lib "user32" Alias "SetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String) As Long
Private Const GW_HWNDFIRST = 0
Private Const GW_HWNDNEXT = 2
Private Const GW_CHILD = 5
Private Sub Command1_Click() '查找所有窗体
Dim hwnd As Long
Dim s As String, t As String
ReDim wdt(0 To 0) As String
hwnd = GetDesktopWindow()
s = String(256, Chr(0))
GetClassName hwnd, s, 255
s = Replace(s, Chr(0), "")
t = String(256, Chr(0))
GetWindowText hwnd, t, 255
t = Replace(t, Chr(0), "")
hwnd = GetWindow(hwnd, GW_CHILD Or GW_HWNDFIRST)
s = String(256, Chr(0))
GetClassName hwnd, s, 255
s = Replace(s, Chr(0), "")
t = String(256, Chr(0))
GetWindowText hwnd, t, 255
t = Replace(t, Chr(0), "")
While hwnd <> 0
hwnd = GetWindow(hwnd, GW_HWNDNEXT)
s = String(256, Chr(0))
GetClassName hwnd, s, 255
s = Replace(s, Chr(0), "")
t = String(256, Chr(0))
GetWindowText hwnd, t, 255
t = Replace(t, Chr(0), "")
If InStr(t, "111") > 0 Then '找到,修改标题
SetWindowText hwnd, "aaaaaaaa"
End If
Wend
End Sub
Private Sub Form_Load()
Command1.Caption = "遍历所有窗体"
End Sub
Option Explicit
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String, ByVal cch As Long) As Long
Private Declare Function GetWindow Lib "user32" (ByVal hwnd As Long, ByVal wCmd As Long) As Long
Private Declare Function GetDesktopWindow Lib "user32" () As Long
Private Declare Function GetClassName Lib "user32" Alias "GetClassNameA" (ByVal hwnd As Long, ByVal lpClassName As String, ByVal nMaxCount As Long) As Long
Private Declare Function SetWindowText Lib "user32" Alias "SetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String) As Long
Private Const GW_HWNDFIRST = 0
Private Const GW_HWNDNEXT = 2
Private Const GW_CHILD = 5
Private Sub Command1_Click() '查找所有窗体
Dim hwnd As Long
Dim s As String, t As String
ReDim wdt(0 To 0) As String
hwnd = GetDesktopWindow()
s = String(256, Chr(0))
GetClassName hwnd, s, 255
s = Replace(s, Chr(0), "")
t = String(256, Chr(0))
GetWindowText hwnd, t, 255
t = Replace(t, Chr(0), "")
hwnd = GetWindow(hwnd, GW_CHILD Or GW_HWNDFIRST)
s = String(256, Chr(0))
GetClassName hwnd, s, 255
s = Replace(s, Chr(0), "")
t = String(256, Chr(0))
GetWindowText hwnd, t, 255
t = Replace(t, Chr(0), "")
While hwnd <> 0
hwnd = GetWindow(hwnd, GW_HWNDNEXT)
s = String(256, Chr(0))
GetClassName hwnd, s, 255
s = Replace(s, Chr(0), "")
t = String(256, Chr(0))
GetWindowText hwnd, t, 255
t = Replace(t, Chr(0), "")
If InStr(t, "111") > 0 Then '找到,修改标题
SetWindowText hwnd, "aaaaaaaa"
End If
Wend
End Sub
Private Sub Form_Load()
Command1.Caption = "遍历所有窗体"
End Sub
展开全部
用字符串函数截取。如假设你的窗口form的名称是111223。那么你可以这么做:
dim str1 as string
str1=form.caption
str1=right(str1,len(str1)-1)
这样str1就是你想要的111....后面的部分窗口标题。
希望对你有所帮助!
dim str1 as string
str1=form.caption
str1=right(str1,len(str1)-1)
这样str1就是你想要的111....后面的部分窗口标题。
希望对你有所帮助!
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
取得全部标题后进行截取.
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询