如何做个程序用鼠标“吸取”桌面上某点象素颜色?(100分)

Y

Yarrow

Unregistered / Unconfirmed
GUEST, unregistred user!
我想做一个程序功能是获取桌面上任意点的象素颜色,思想如下:<br><br>将鼠标光标设置成“吸管”样式,当鼠标离开本窗体,在桌面上其它程序上游动时仍显示本程序的“吸管”式鼠标光标。需要知道鼠标下象素的颜色时,点击鼠标,获得鼠标下象素的颜色。当然这时点击鼠标不应该击活其下面的应用程序,但允许在开始状态栏上切换程序。<br><br>请问该怎么做?
 
var DC: &nbsp;HDC;<br>&nbsp; &nbsp; P: &nbsp; TPoint;<br>&nbsp; &nbsp; co: &nbsp;TColor;<br>&nbsp; &nbsp;GetCurSorPos(P);<br>&nbsp; &nbsp;DC:=GetDC(0);<br>&nbsp; &nbsp;co:=GetPixel(DC,p.x,p.y);<br>&nbsp; &nbsp;ReleaseDC(0,DC); &nbsp;//鼠标点击后依然不激活下面的程序,多半就只有设置钩子了!<br><br>&nbsp; &nbsp;另外判断GetforeGroundWindow=form1.Handle可能用的上,其它关注!
 
先抓图在你自己的窗体中显示“桌面”,然后再做你要做的事
 
tan_jian的方法应该能行!<br>用钩子反耳麻烦了
 
鼠标点击后依然不激活下面的程序:<br>请参见 SetCapture 这个WINDOWS API<br>
 
告诉你一个匆忙绝顶的方法!<br>新建立一个Form,把它设置成最大化,无边框,<br>在OnCreate事件中<br>&nbsp; Brush.Style:=bsClear;<br>这样就建立了一个覆盖全屏幕的透明的窗口!<br>&nbsp; 提取像素时<br>var<br>&nbsp; FCanvas:TCanvas;<br>&nbsp; MyColor:TColor;<br>begin<br>&nbsp; try<br>&nbsp; &nbsp; FCanvas:=TCanvas.Create;<br>&nbsp; &nbsp; FCanvas.Handle:=GetDC(0);<br>&nbsp; &nbsp; MyColor:=FCanvas.pixel[x,y];//x,y为屏幕坐标<br>&nbsp;finally<br>&nbsp; &nbsp; ReleaseDC(0,FCanvas.Handle);<br>&nbsp; &nbsp; FCanvas.Free;<br>&nbsp;end;<br>end;
 
一个VC的源代码,自己参考一下吧<br>http://www.vckbase.com/code/downcode.asp?id=1602
 
跟踪屏幕像素颜色。<br><br>在Form中放一 TLabel(Label1),再放置一定时器(TTimer).<br>然后粘贴以下定时器代码即可运行。<br>当鼠标在屏幕的任何位置移动时,Label中显示鼠标所指<br>像素的颜色(十六进制 RGB 格式)。<br><br>///////////////以下是定时器的处理代码:<br>procedure TForm1.Timer1Timer(Sender: TObject);<br>var<br>&nbsp; P: &nbsp; TPoint;<br>&nbsp; co: &nbsp;TColor;<br>&nbsp; ScreenDC : HDC;<br>&nbsp; fBitmap : TBitmap;<br>begin<br>&nbsp; GetCurSorPos(P);<br>&nbsp; fBitmap := TBitmap.Create;<br>&nbsp; fBitmap.Width := 1;<br>&nbsp; fBitmap.Height := 1;<br>&nbsp; ScreenDC:=CreateDC('DISPLAY',nil,nil,nil);<br>&nbsp; BitBlt(FBitmap.Canvas.Handle, 0,0,<br>&nbsp; &nbsp; FBitmap.Width, FBitmap.Height,<br>&nbsp; &nbsp; ScreenDC, p.x,p.y, SRCCOPY);<br>&nbsp; DeleteDC(ScreenDC);<br>&nbsp; label1.caption:=inttohex(fbitmap.canvas.pixels[0,0],8);<br>&nbsp; fBitmap.Free<br>end;<br><br>
 
楼上的类似抓屏的代码有些错误,请提出问题者,去查找相关代码,楼上的BitBlt以下的代码都可以参照!:D
 
What problems ?????
 
非常感谢,我认为还是做一个Copy屏幕的窗体会比较容易,因为那样还可以控制鼠标光标。
 
顶部