永发信息网

VB获得空格的窗口

答案:4  悬赏:50  手机版
解决时间 2021-04-22 15:39
  • 提问者网友:你独家记忆
  • 2021-04-21 22:18
一般name = FindWindow(vbNullString, "连连看 v4.6"),获取的是无空格的窗口,我想获得那个窗口,但是标题后面很多空格,用上面的代码获取不了,会的写出代码!
最佳答案
  • 五星知识达人网友:等灯
  • 2021-04-21 23:17

给你个思路,用循环
for i = 1 to 100'还能超过一百个空格吗?


name = FindWindow(vbNullString, "连连看 v4.6" & space(i))


if name<>"" then exit for


next

全部回答
  • 1楼网友:人類模型
  • 2021-04-22 01:15

枚举窗体得到的是窗体句柄

'放到窗体里面 Private Sub Form_Load() 'KPD-Team 2000 'URL: http://www.allapi.net/ 'E-Mail: KPDTeam@Allapi.net 'Set the form's graphics mode to persistent Me.AutoRedraw = True 'call the Enumwindows-function EnumWindows AddressOf EnumWindowsProc, ByVal 0& End Sub '放在模块里面 Declare Function EnumWindows Lib "user32" (ByVal lpEnumFunc As Long, ByVal lParam As Long) As Boolean Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String, ByVal cch As Long) As Long Declare Function GetWindowTextLength Lib "user32" Alias "GetWindowTextLengthA" (ByVal hwnd As Long) As Long Public Function EnumWindowsProc(ByVal hwnd As Long, ByVal lParam As Long) As Boolean Dim sSave As String, Ret As Long Ret = GetWindowTextLength(hwnd) sSave = Space(Ret) GetWindowText hwnd, sSave, Ret + 1 Form1.Print Str$(hwnd) + " " + sSave

'这里sSave就是窗体标题,只要用Instr()就可知道是不是你要的

If InStr(1, sSave, "连连看 v4.6") > 0 Then MsgBox "找到此窗口" 'continue enumeration EnumWindowsProc = True End Function

  • 2楼网友:山有枢
  • 2021-04-22 00:45
for i = 1 to 100

name = FindWindow(vbNullString, "连连看 v4.6" & space(i))

if name<>"" then exit for

next

print i 知道空格有多少个

  • 3楼网友:逃夭
  • 2021-04-21 23:48
你可以用LTrim 及 RTrim 函数把vbNullString头和尾的空格去掉,这样不是更方便吗
我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息
大家都在看
推荐资讯