字符串明明相等,为什么不对呢????????????????
时间:2011-11-26
来源:互联网
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 GetForegroundWindow Lib "user32" () As Long
Dim strTitle As String * 255 '用来存储窗口的标题
Private Sub Command1_Click() '第一种
GetWindowText hwnd, strTitle, Len(strTitle)
Print strTitle
If strTitle = "Form1" Then
MsgBox "相等"
End If
End Sub
明明 strTitle = Form1 为什么不相等?
如果我改为下面的例子就相等,怎么回事???????
Private Sub Command1_Click() '第二种
GetWindowText hwnd, strTitle, Len(strTitle)
Print strTitle
If strTitle = "Form1" Then
MsgBox "相等"
End If
Text1.Text = strTitle
Text2.Text = "Form1"
If Text1.Text = Text2.Text Then
MsgBox "相等2"
End If
End Sub
Private Declare Function GetForegroundWindow Lib "user32" () As Long
Dim strTitle As String * 255 '用来存储窗口的标题
Private Sub Command1_Click() '第一种
GetWindowText hwnd, strTitle, Len(strTitle)
Print strTitle
If strTitle = "Form1" Then
MsgBox "相等"
End If
End Sub
明明 strTitle = Form1 为什么不相等?
如果我改为下面的例子就相等,怎么回事???????
Private Sub Command1_Click() '第二种
GetWindowText hwnd, strTitle, Len(strTitle)
Print strTitle
If strTitle = "Form1" Then
MsgBox "相等"
End If
Text1.Text = strTitle
Text2.Text = "Form1"
If Text1.Text = Text2.Text Then
MsgBox "相等2"
End If
End Sub
作者: duaozhuan0 发布时间: 2011-11-26
Form1 当然不等于 "Form1"
类型都不一样
类型都不一样
作者: ningweidong 发布时间: 2011-11-26
应为你的strTitle 是定长字符串
其实实际里面的内容为 "Form1" & chr(0)... & chr(0) & chr(0) 而已
但你的 Text2.Text 却是 "Form1" ,没有后面的 chr(0)
所以通常处理这种东西需要这样处理
GetWindowText hwnd, strTitle, Len(strTitle)
rd = GetWindowTextLength(hwnd)
strTitle=Left(strTitle,rd)
其实实际里面的内容为 "Form1" & chr(0)... & chr(0) & chr(0) 而已
但你的 Text2.Text 却是 "Form1" ,没有后面的 chr(0)
所以通常处理这种东西需要这样处理
GetWindowText hwnd, strTitle, Len(strTitle)
rd = GetWindowTextLength(hwnd)
strTitle=Left(strTitle,rd)
作者: SupermanKing 发布时间: 2011-11-26
看你自己的定义: Dim strTitle As String * 255
"Form1"才5个字符, 当然不会相等.
"Form1"才5个字符, 当然不会相等.
作者: WallesCai 发布时间: 2011-11-26
问题在于你都strTitle是255长度的定长字符串,而"Form1"不是,两者长度都不相等,那又何来相等?
作者: Veron_04 发布时间: 2011-11-26
相关阅读 更多
热门阅读
-
office 2019专业增强版最新2021版激活秘钥/序列号/激活码推荐 附激活工具
阅读:74
-
如何安装mysql8.0
阅读:31
-
Word快速设置标题样式步骤详解
阅读:28
-
20+道必知必会的Vue面试题(附答案解析)
阅读:37
-
HTML如何制作表单
阅读:22
-
百词斩可以改天数吗?当然可以,4个步骤轻松修改天数!
阅读:31
-
ET文件格式和XLS格式文件之间如何转化?
阅读:24
-
react和vue的区别及优缺点是什么
阅读:121
-
支付宝人脸识别如何关闭?
阅读:21
-
腾讯微云怎么修改照片或视频备份路径?
阅读:28