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

Delphi
闪动标题栏
制作真正的TopMost窗口
制作类似WinAmp一样的“磁性”窗口
不可移动的窗口示例代码
自制替换指定串函数
Delphi中RichEdit的奥妙
Delphi数据集过滤技巧
为VB应用程序定制浮动提示
DELPHI图形编辑技巧二则
Delphi使用技巧两则
Delphi 3.0中的函数调用模式
Delphi3中制作快速按钮条
Delphi 4增订的Object Pascal
Delphi3.0中的函数调用模式
DCU文件(编译的库单元)的重用
命令行参数的使用
在编译时获得提示
运行时生成控件
任意打印
分行提示

Delphi学习:查句柄知多少


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