永发信息网

VB里调用 getpixel返回值为什么是0

答案:1  悬赏:20  手机版
解决时间 2021-07-20 08:41

模块声明:

Private Declare Function GetPixel Lib "gdi32" (ByVal hdc As Long, ByVal x As Long, ByVal y As Long) As Long

Public Function aipcolor(hdc As Long, x As Long, y As Long) As Long
Call GetPixel(hdc, x, y)
End Function

工程:Private Sub Timer1_Timer()
Dim zuobiao As POINTAPI
Call GetCursorPos(zuobiao)
Dim dc As Long
Dim hhdc As Long

hhdc = GetDC(0)
dc = Module1.aipcolor(hhdc, zuobiao.x, zuobiao.y)
Label1.Caption = "颜色的量:" & dc
Label1.BackColor = dc
End Su

里面一切都正常最后调试dc的值为0 ,3个参数值都正常

最佳答案

'在vb6 中添加 command 一个,timer 一个,picturebox 两个,form 中添加如下命令


'出错原因,getpixel 是针对picturebox 的api ,对象不明确,getdc(0) 不属于picturebox 成员之一


'by 竹潺◎水墨


Private Declare Function GetPixel Lib "gdi32" (ByVal hdc As Long, ByVal x As Long, ByVal y As Long) As Long
Private Type POINTAPI
x As Long
y As Long
End Type
Private Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long
Private Declare Function GetDC Lib "user32" (ByVal hwnd As Long) As Long
Private Declare Function BitBlt Lib "gdi32" (ByVal hDestDC As Long, ByVal x As Long, ByVal y As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal hSrcDC As Long, ByVal xSrc As Long, ByVal ySrc As Long, ByVal dwRop As Long) As Long
Private Declare Function StretchBlt Lib "gdi32" (ByVal hdc As Long, ByVal x As Long, ByVal y As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal hSrcDC As Long, ByVal xSrc As Long, ByVal ySrc As Long, ByVal nSrcWidth As Long, ByVal nSrcHeight As Long, ByVal dwRop As Long) As Long


Private Sub Command1_Click()
End
End Sub


Private Sub Form_Load()
Dim hdc As Long
hdc = GetDC(0)
Me.Visible = False
DoEvents
Form1.WindowState = vbMaximized
Form1.BorderStyle = 2
With Picture2
.Left = 3000
.Top = 200
End With
With Command1
.Left = 1000
.Top = 200
.Caption = "单击此处退出"
End With
With Picture1
.ScaleMode = 1
.Top = 0
.Left = 0
.Width = Screen.Width
.Height = Screen.Height
StretchBlt .hdc, 0, 0, .Width, .Height, hdc, 0, 0, .Width, .Height, vbSrcCopy '将屏幕保存到picture1
End With
Me.Visible = True
End Sub


Private Sub Timer1_Timer()
On Error Resume Next
Dim zuobiao As POINTAPI
GetCursorPos zuobiao
Dim dc As Long
' dc = GetPixel(Picture1.hdc, zuobiao.x, zuobiao.y)
dc = Picture1.Point(zuobiao.x * Screen.TwipsPerPixelX, zuobiao.y * Screen.TwipsPerPixelY) '这两个东东是一样功能的,不需要刻意调用api
Me.Caption = "颜色的量:" & dc
Picture2.BackColor = dc
End Sub


我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
赛尔号的书在那买多少钱
什么东西凉的不能打,热了能打?
为啥子天不怕.地不怕.就怕四川人讲普通话!
今年豆子能卖多少钱?
都是家长逼的...第一次相亲应都说些什么?
新奇迹世界进不去??弹出failes to create app
为什么我的DNF下载不了,去官网点下载也没反
在地下城里边有的人收东西或者卖东西时所说的
Who can tell me which the better grammatic
QQ宠物去电脑里哪找?
上海居民用电可以按分时计费地方法收取,从六
推荐些法语歌听吧!艾莉婕的除外
关于早退的检讨书怎么写?
李孝利的详细资料
心理的小问题
推荐资讯
在下面数字之间添上运算符号和括号,使等式成
想创业却困难重重啊为啥创业这么难那
什么是正三棱锥?(概念)
用面铣刀怎么把工件平面铣的光滑?
QQ华夏图标这么点亮?
51视频学院-视频教程网的网址是什么?
电脑上没导航怎么下载网站导航
谁可以给QQ堂探险的道具/装备出现图。
寻找石器时代
极品五笔拼音怎么才可以同时使用
为什么在1959年和1969,1979年不举行阅兵了?
什么是实地调研法
正方形一边上任一点到这个正方形两条对角线的
阴历怎么看 ?