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

Delphi
在线播放器DIY
关于VisiBroker For Delphi的使用(3)
关于VisiBroker For Delphi的使用(2)
关于VisiBroker For Delphi的使用(1)
Delphi的两个实用技巧(2)巧用Windows的API函数
Delphi的两个实用技巧(1)播放Flash
delphi学习:两种方法使用xml文档
Delphi与Word之间的融合技术
Delphi中动态链接库(DLL)的建立和使用
Delphi基础:Window 消息大全使用详解下
Delphi基础:Window 消息大全使用详解上
教你在DELPHI中如何调用系统对话框
Delphi开发单机瘦小数据库程序要点
用Delphi + DirectX开发简单RPG游戏
Delphi7从入门到精通之认识Delphi编辑器
Delphi7从入门到精通之历数Delphi七个版本
Delphi学习:图像放大漫游攻略
用编程来实现24小时制到12小时制的转换
一个实际的OLE服务器的开发
Delphi一点通:如何将源代码学好

Delphi学习:查句柄知多少


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