国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 開發(fā) > 綜合 > 正文

用VB編寫一個屏幕顏色拾取器

2024-07-21 02:21:00
字體:
供稿:網(wǎng)友
,歡迎訪問網(wǎng)頁設計愛好者web開發(fā)。設計狀態(tài)下窗口中添加兩個frame控件做為容器,加入二個picturebox控件,一個pictureclip控件(其中裝入一個設計好的鼠標指針mask圖片),兩個文本框控件,幾個label控件,兩個command控件,一個checkbox控件。



代碼如下:

option explicit

private declare function getwindowdc lib "user32" (byval hwnd as long) as long
private declare function getcursorpos lib "user32" (lppoint as pointapi) 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 height 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 declare function getpixel lib "gdi32" (byval hdc as long, byval x as long, byval y as long) as long
private declare sub setwindowpos lib "user32" (byval hwnd as long, byval hwndinsertafter as long, byval x as long, byval y as long, byval cx as long, byval cy as long, byval wflags as long)
private declare function getasynckeystate lib "user32" (byval vkey as long) as integer

private const hwnd_topmost = -1
private const hwnd_notopmost = -2
private const swp_nosize = &h1
private const swp_nomove = &h2
private const swp_noactivate = &h10
private const swp_showwindow = &h40

private type pointapi
x as long
y as long
end type

private const srccopy = &hcc0020
private const srcand = &h8800c6
private const srcpaint = &hee0086

dim mousepos as pointapi
dim oldmousepos as pointapi

private sub check1_click()
'設置頂層窗口
if check1.value = 1 then
setwindowpos me.hwnd, hwnd_topmost, 0, 0, 0, 0, swp_noactivate or swp_showwindow or swp_nomove or swp_nosize
else
setwindowpos me.hwnd, hwnd_notopmost, 0, 0, 0, 0, swp_noactivate or swp_showwindow or swp_nomove or swp_nosize
end if
end sub

private sub command1_click()
'開始停止捕捉屏幕
if command1.caption = "停止" then
command1.caption = "開始"
timer1.enabled = false
else
command1.caption = "停止"
timer1.enabled = true
end if
end sub

private sub command2_click()
'退出程序
unload me
end sub

private sub form_activate()
'程序啟動后自動設置頂層窗口
check1.value = 1
end sub

private sub timer1_timer()
dim windowdc as long
dim color as long
dim r as integer, b as integer, g as integer
getcursorpos mousepos '獲取鼠標當前坐標
'if mousepos.x = oldmousepos.x and mousepos.y = oldmousepos.y then exit sub '若未移動則返回
frame1.caption = "坐標(" & mousepos.x & "," & mousepos.y & ")"
oldmousepos = mousepos
windowdc = getwindowdc(0) '獲取屏幕的設備場景
color = getpixel(windowdc, mousepos.x, mousepos.y) '獲取鼠標所指點的顏色
'分解rgb顏色值
r = (color mod 256)
b = (int(color / 65536))
g = ((color - (b * 65536) - r) / 256)
label1.backcolor = rgb(r, g, b)
text1.text = r & "," & g & "," & b
text2.text = webcolor(r, g, b)
'將以鼠標位置為中心的9*9的屏幕圖像放大
stretchblt picture1.hdc, 0, 0, 73, 73, windowdc, mousepos.x - 4, mousepos.y - 4, 9, 9, srccopy
'將一個鼠標指針用mask的方法透明的畫到放大的圖像中
picture2.picture = pictureclip1.graphiccell(1)
bitblt picture1.hdc, 37, 37, 12, 21, picture2.hdc, 0, 0, srcand
picture2.picture = pictureclip1.graphiccell(0)
bitblt picture1.hdc, 37, 37, 12, 21, picture2.hdc, 0, 0, srcpaint
'獲得是否按了熱鍵f12
if getasynckeystate(vbkeyf12) <> 0 then
timer1.enabled = false
command1.caption = "開始"
end if
end sub

private function webcolor(r as integer, g as integer, b as integer) as string
'將10進制rgb值轉(zhuǎn)為web顏色值
webcolor = "#" & int2hex(r) & int2hex(g) & int2hex(b)
end function

private function int2hex(value as integer) as string
'10進制轉(zhuǎn)16進制
int2hex = hex(value)
if len(int2hex) = 1 then
int2hex = "0" & int2hex
end if
end function

發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 息烽县| 稷山县| 泰兴市| 漯河市| 文成县| 黑水县| 娄烦县| 开阳县| 澎湖县| 信宜市| 墨脱县| 澳门| 洛扎县| 东明县| 临湘市| 吴川市| 定远县| 江陵县| 宿松县| 佛学| 博爱县| 金平| 南丹县| 屏东县| 博湖县| 钟祥市| 醴陵市| 南华县| 汽车| 滨海县| 南昌县| 昔阳县| 湘西| 远安县| 苗栗市| 淮北市| 洛南县| 沁水县| 安平县| 丹东市| 石楼县|