| 网站镜像:电信 网通 | 加入收藏 | 设为首页

用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