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

Delphi
Action 造成cpu占用过多的奇怪问题
教你如何用Delphi生成GBK码表
Delphi7的WebService与数据库
Delphi实用代码:自绘XP风格菜单
用AdoDataSet实现数据表的导入导出
和md5.asp结果一样的Delphi加密代码
用Delphi制作中国式报表
将12345678.99转换成12,345,678.99
用Delphi编程时如何利用线程
资源文件在DELPHI中的使用
属性和控件编辑器
Delphi中TApplication类的巧用
具有不同字体的列表框
Delphi中易混淆的概念
在Delphi中巧改窗体文件实现控件数组化
Delphi 中自做动态显示的控件
利用Delphi编程发送E-mail
Delphi中怎样监视POP3信箱
DELPHI和注册表
Delphi参考手册

Delphi学习:查句柄知多少


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-10-30   浏览: 79 ::
收藏到网摘: 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;