用VFP打造屏幕取色器

屏幕取色器,大家想必都见识过,小弟也从网上找了一个,做网页很方便,尤其像俺这种偏于代码的那种人,看到合适的,可以用这个小东东取出来,然后可直接用在网页中,真是很方便,不过,像咱也是做开发的,于是想到了,自己也做这样一个东东,正好,小弟在尝试VFP9,所以便拿这个小工具开刀了


第一步,界面设置
不用多说,于代码相关的是一个timer控件,intervalue值可以自行设定一下,合适为好,太大则取色不准,太小则会大量占用系统资源。

第二步,编写代码,在timer事件中写入以下代码:
DECLARE integer GetCursorPos IN WIN32API  as "GetCursorPos"  string  @lpPoint
DECLARE integer ClientToScreen IN WIN32API as "ClientToScreen" integer hWnd,string @lpPoint
DECLARE integer GetPixel IN WIN32API as "GetPixel" integer hDc,integer xPos,integer yPos
DECLARE integer GetDC IN WIN32API as "GetDC" integer hWnd
arrPos=REPLICATE(CHR(0),8)
LOCAL intXPos,intYPos
SET PROCEDURE TO funclib.prg
LOCAL myreturn
myreturn=GetCursorPos(@arrPos)
myreturn=ClientToScreen(0,@arrPos)
strX=LEFT(arrPos,4)
strY=SUBSTR(arrPos,5,4)
strXPos=left(strX,2)
strXPosLow=LEFT(strXPos,1)
strXPosHigh=SUBSTR(strXpos,2,1)
strYPos=left(strY,2)
strYPosLow=LEFT(strYPos,1)
strYPosHigh=SUBSTR(strYpos,2,1)
thisform.text1.value=256*ASC(strXPosHigh)+ASC(strXPosLow)
thisform.text2.Value=256*ASC(strYPosHigh)+ASC(strYPosLow)
intXPos=thisform.text1.Value
intYPos=thisform.text2.Value
hDcScreen=GetDC(0)
LOCAL xRgbColor as Integer
xRgbColor=GetPixel(hDcScreen,intXPos,intYPos)
intBlue=int(xRgbColor/65536)
intGreen=INT((xRgbColor%65536)/256)
intRed=xRgbColor%256
IF NOT thisform.locktext
 thisform.text3.Value="#"+ALLTRIM(int2Hex16(intRed))+ALLTRIM(int2Hex16(intGreen))+ALLTRIM(int2Hex16(intBlue))
 thisform.text4.Value=intRed
 thisform.text5.Value=intGreen
 thisform.text6.Value=intBlue
 thisform.container1.BackColor=RGB(intRed,intGreen,intBlue)
ENDIF
CLEAR DLLS
其次,还要在将颜色取出来,放到剪切板上以便在其它软件环境中适用
于是,在主表单的keypress中使用
if nKeyCode=CTRL+C
    _cliptext=thisform.text1.value
endif
以上代码在WIN2000 ADV SERVER +VFP9。0下通过

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值