VB中,这段代码为什么WIN7 中无法使用,只能在XP中使用,谁能帮我修改下...
发布网友
发布时间:2024-10-03 06:02
我来回答
共6个回答
热心网友
时间:2024-10-19 09:40
你这样试下就明白了:
Private Declare Function GetPixel Lib "gdi32" (ByVal hdc As Long, ByVal x As Long, ByVal y As Long) As Long
Private Declare Function GetDC Lib "user32" (ByVal hWnd As Long) As Long
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function SetWindowText Lib "user32" Alias "SetWindowTextA" (ByVal hWnd As Long, ByVal lpString As String) As Long
Dim mHwnd As Long
Private Sub Form_Load()
mHwnd = FindWindow(vbNullString, "帮助.txt - 记事本")
hDCWindow = GetDC(mHwnd)
'Dim mHwnd As Long
'hWnd = FindWindow(vbNullString, "张志晨.txt - 记事本")
If mHwnd Then
MsgBox ("找到窗口!")
Else
MsgBox ("未找到窗口!")
End If
End Sub
Private Sub Timer1_Timer()
Text1.Text = Hex(GetPixel(hDCWindow, 100, 100))
End Sub
当然也可以这样:
Private Declare Function GetPixel Lib "gdi32" (ByVal hdc As Long, ByVal x As Long, ByVal y As Long) As Long
Private Declare Function GetDC Lib "user32" (ByVal hWnd As Long) As Long
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function SetWindowText Lib "user32" Alias "SetWindowTextA" (ByVal hWnd As Long, ByVal lpString As String) As Long
Dim mHwnd As Long
Private Sub Form_Load()
mHwnd = FindWindow("Notepad", vbNullString)
hDCWindow = GetDC(mHwnd)
If mHwnd Then
MsgBox ("找到窗口!")
Else
MsgBox ("未找到窗口!")
End If
End Sub
Private Sub Timer1_Timer()
Text1.Text = Hex(GetPixel(hDCWindow, 100, 100))
End Sub
热心网友
时间:2024-10-19 09:32
可以啊朋友,你给的代码我的没有问题,我的是 win7 旗舰版,是不是其它代码不行啊
热心网友
时间:2024-10-19 09:33
没安装win7 你QQ又不知道答案 无法加
热心网友
时间:2024-10-19 09:38
把代码发给我吧。www.512482872@qq.com
我看看能不能帮到你。
热心网友
时间:2024-10-19 09:38
获取这个窗体的X.Y坐标的像素的RGB颜色值?
你调试一下。我估计是mHwnd无效值。
可能和系统有关,是因为不同的系统。显示的文件标题不一样。
换成"计算器"试试看。FindWindow(nil,"计算器");
热心网友
时间:2024-10-19 09:33
应该是两个系统api接口不同了,你这样试试:把xp上所需dll放到win7的固定位置(如C盘根目录),声明的时候这样写:
... GetPixel Lib "C:\gdi32" ...
热心网友
时间:2024-10-19 09:40
你这样试下就明白了:
Private Declare Function GetPixel Lib "gdi32" (ByVal hdc As Long, ByVal x As Long, ByVal y As Long) As Long
Private Declare Function GetDC Lib "user32" (ByVal hWnd As Long) As Long
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function SetWindowText Lib "user32" Alias "SetWindowTextA" (ByVal hWnd As Long, ByVal lpString As String) As Long
Dim mHwnd As Long
Private Sub Form_Load()
mHwnd = FindWindow(vbNullString, "帮助.txt - 记事本")
hDCWindow = GetDC(mHwnd)
'Dim mHwnd As Long
'hWnd = FindWindow(vbNullString, "张志晨.txt - 记事本")
If mHwnd Then
MsgBox ("找到窗口!")
Else
MsgBox ("未找到窗口!")
End If
End Sub
Private Sub Timer1_Timer()
Text1.Text = Hex(GetPixel(hDCWindow, 100, 100))
End Sub
当然也可以这样:
Private Declare Function GetPixel Lib "gdi32" (ByVal hdc As Long, ByVal x As Long, ByVal y As Long) As Long
Private Declare Function GetDC Lib "user32" (ByVal hWnd As Long) As Long
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function SetWindowText Lib "user32" Alias "SetWindowTextA" (ByVal hWnd As Long, ByVal lpString As String) As Long
Dim mHwnd As Long
Private Sub Form_Load()
mHwnd = FindWindow("Notepad", vbNullString)
hDCWindow = GetDC(mHwnd)
If mHwnd Then
MsgBox ("找到窗口!")
Else
MsgBox ("未找到窗口!")
End If
End Sub
Private Sub Timer1_Timer()
Text1.Text = Hex(GetPixel(hDCWindow, 100, 100))
End Sub
热心网友
时间:2024-10-19 09:34
可以啊朋友,你给的代码我的没有问题,我的是 win7 旗舰版,是不是其它代码不行啊
热心网友
时间:2024-10-19 09:39
没安装win7 你QQ又不知道答案 无法加
热心网友
时间:2024-10-19 09:32
把代码发给我吧。www.512482872@qq.com
我看看能不能帮到你。
热心网友
时间:2024-10-19 09:34
应该是两个系统api接口不同了,你这样试试:把xp上所需dll放到win7的固定位置(如C盘根目录),声明的时候这样写:
... GetPixel Lib "C:\gdi32" ...
热心网友
时间:2024-10-19 09:32
获取这个窗体的X.Y坐标的像素的RGB颜色值?
你调试一下。我估计是mHwnd无效值。
可能和系统有关,是因为不同的系统。显示的文件标题不一样。
换成"计算器"试试看。FindWindow(nil,"计算器");