当前位置: 首页 > 图文教程 > 开发语言 > Delphi > Delphi学习:查句柄知多少

Delphi
Delphi编程中Http协议应用(一)
Delphi存取图像完整解决方案
简析Delphi中的XML编程
用Delphi实现IP地址的隐藏
Delphi面向对象编程的20条规则
Delphi中的Wrapper设计模式
用Delphi实现软件的在线升级
Delphi7.0实现添加记录的“携带”实现
Delphi编程访问注册表
让Delphi的DBGrid支持鼠标轮
怎样在DELPHI中实现文件切割/组合
Delphi设计可中/英文切换的界面技巧
用Delphi制作以浏览器为界面的应用程序
Delphi 中压缩流和解压流的应用
Delphi控制并行端口位操作
Delphi编写后台监控软件
用Delphi编写VxD设备驱动程序
用Delphi进行OpenGL编程学习心得
DELPHI编程实现3DS的动画播放
用Delphi制作动态菜单

Delphi学习:查句柄知多少


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-10-30   浏览: 74 ::
收藏到网摘: n/a

 
基本上句柄是标志窗口,我可以根据句柄又可引申其中更多如类名,windowtitle等属性所以基于这点,一般开发工具会提供查句柄,查类名等工具,vs提供的spy++就是一个很好例子。现在教你们一查句柄知多少。其实也简单,下面贴出源代码。




  procedure Tform1.TimerTimer(Sender: TObject);
  var
  Pos: TPoint;
  Handle: HWND;
  ScreenDC: HDC;
  Buf: array[0..1024] of Char;
  ScreenColor: COLORREF;
  begin
  GetCursorPos(Pos); // 得到当前光标位置
  Handle := WindowFromPoint(Pos); // 返回当前位置的句柄
  HandleText.Caption := IntToStr(Handle);
  GetClassName(Handle, Buf, 1024); // 得到类名
  ClassNameText.Caption := Buf;
  SendMessage(Handle, WM_GETTEXT, 33, Integer(@Buf)); // 得到标题
  TitleText.Caption := Buf;
  { 得到光标处点的颜色 }
  ScreenDC := GetDC(0);
  ScreenColor := GetPixel(ScreenDC, Pos.X, Pos.Y);
  Shape.Brush.Color := TColor(ScreenColor);
  RGBColorText.Caption := '红: ' + IntToStr(GetRValue(ScreenColor)) +
  '  绿: ' + IntToStr(GetGValue(ScreenColor)) + '  蓝: ' +
  IntToStr(GetBValue(ScreenColor));
  ReleaseDC(0, ScreenDC);
  DelphiColorText.Caption := Format('Delphi中颜色值:$00%2.2x%2.2x%2.2x', [GetBValue(ScreenColor),
  GetGValue(ScreenColor), GetRValue(ScreenColor)]);
  HTMLColorText.Caption := Format('HTML颜色值:#%2.2x%2.2x%2.2x', [GetRValue(ScreenColor),
  GetGValue(ScreenColor), GetBValue(ScreenColor)]);
  end;