Delphi代码
  1. unit Unit1;
  2. interface
  3. uses
  4. SysUtils, WinTypes, WinProcs, Messages, Classes, Graphics, Controls,
  5. Forms, Dialogs, Buttons, DdeMan, StdCtrls;
  6. type
  7. TTitleBtnForm = class(TForm)
  8. Button1: TButton;
  9. procedure FormResize(Sender: TObject);
  10. private
  11. TitleButton : TRect;
  12. procedure DrawTitleButton;
  13. {Paint-related messages}
  14. procedure WMSetText(var Msg : TWMSetText); message WM_SETTEXT;
  15. procedure WMNCPaint(var Msg : TWMNCPaint); message WM_NCPAINT;
  16. procedure WMNCActivate(var Msg : TWMNCActivate); message WM_NCACTIVATE;
  17. {Mouse down-related messages}
  18. procedure WMNCHitTest(var Msg : TWMNCHitTest); message WM_NCHITTEST;
  19. procedure WMNCLButtonDown(var Msg : TWMNCLButtonDown); message WM_NCLBUTTONDOWN;
  20. function GetVerInfo : DWORD;
  21. end;
  22. var
  23. TitleBtnForm: TTitleBtnForm;
  24. const
  25. htTitleBtn = htSizeLast + 1;
  26. implementation
  27. {$R *.DFM}
  28. procedure TTitleBtnForm.DrawTitleButton;
  29. var
  30. bmap : TBitmap; {Bitmap to be drawn - 16 X 16 : 16 Colors}
  31. XFrame, {X and Y size of Sizeable area of Frame}
  32. YFrame,
  33. XTtlBit, {X and Y size of Bitmaps in caption}
  34. YTtlBit : Integer;
  35. begin
  36. {Get size of form frame and bitmaps in title bar}
  37. XFrame := GetSystemMetrics(SM_CXFRAME);
  38. YFrame := GetSystemMetrics(SM_CYFRAME);
  39. XTtlBit := GetSystemMetrics(SM_CXSIZE);
  40. YTtlBit := GetSystemMetrics(SM_CYSIZE);
  41. {$IFNDEF WIN32}
  42. TitleButton := Bounds(Width - (3 * XTtlBit) - ((XTtlBit div 2) - 2),
  43. YFrame - 1,
  44. XTtlBit + 2,
  45. YTtlBit + 2);
  46. {$ELSE} {Delphi 2.0 positioning}
  47. if (GetVerInfo = VER_PLATFORM_WIN32_NT) then
  48. TitleButton := Bounds(Width - (3 * XTtlBit) - ((XTtlBit div 2) - 2),
  49. YFrame - 1,
  50. XTtlBit + 2,
  51. YTtlBit + 2)
  52. else
  53. TitleButton := Bounds(Width - XFrame - 4*XTtlBit + 2,
  54. XFrame + 2,
  55. XTtlBit + 2,
  56. YTtlBit + 2);
  57. {$ENDIF}
  58. Canvas.Handle := GetWindowDC(Self.Handle); {Get Device context for drawing}
  59. try
  60. {Draw a button face on the TRect}
  61. DrawButtonFace(Canvas, TitleButton, 1, bsAutoDetect, False, False, False);
  62. bmap := TBitmap.Create;
  63. bmap.LoadFromFile('c:\windows\desktop\aaa.bmp');
  64. with TitleButton do
  65. {$IFNDEF WIN32}
  66. Canvas.Draw(Left + 2, Top + 2, bmap);
  67. {$ELSE}
  68. if (GetVerInfo = VER_PLATFORM_WIN32_NT) then
  69. Canvas.Draw(Left + 2, Top + 2, bmap)
  70. else
  71. Canvas.StretchDraw(TitleButton, bmap);
  72. {$ENDIF}
  73. finally
  74. ReleaseDC(Self.Handle, Canvas.Handle);
  75. bmap.Free;
  76. Canvas.Handle := 0;
  77. end;
  78. end;
  79. {Paint triggering events}
  80. procedure TTitleBtnForm.WMNCActivate(var Msg : TWMNCActivate);
  81. begin
  82. Inherited;
  83. DrawTitleButton;
  84. end;
  85. procedure TTitleBtnForm.FormResize(Sender: TObject);
  86. begin
  87. Perform(WM_NCACTIVATE, Word(Active), 0);
  88. end;
  89. {Painting events}
  90. procedure TTitleBtnForm.WMNCPaint(var Msg : TWMNCPaint);
  91. begin
  92. Inherited;
  93. DrawTitleButton;
  94. end;
  95. procedure TTitleBtnForm.WMSetText(var Msg : TWMSetText);
  96. begin
  97. Inherited;
  98. DrawTitleButton;
  99. end;
  100. {Mouse-related procedures}
  101. procedure TTitleBtnForm.WMNCHitTest(var Msg : TWMNCHitTest);
  102. begin
  103. Inherited;
  104. {Check to see if the mouse was clicked in the area of the button}
  105. with Msg do
  106. if PtInRect(TitleButton, Point(XPos - Left, YPos - Top)) then
  107. Result := htTitleBtn;
  108. end;
  109. procedure TTitleBtnForm.WMNCLButtonDown(var Msg : TWMNCLButtonDown);
  110. begin
  111. inherited;
  112. if (Msg.HitTest = htTitleBtn) then
  113. ShowMessage('You pressed the new button');
  114. end;
  115. function TTitleBtnForm.GetVerInfo : DWORD;
  116. var
  117. verInfo : TOSVERSIONINFO;
  118. begin
  119. result:=0;
  120. verInfo.dwOSVersionInfoSize := SizeOf(TOSVersionInfo);
  121. if GetVersionEx(verInfo) then
  122. Result := verInfo.dwPlatformID;
  123. {Returns:
  124. VER_PLATFORM_WIN32s Win32s on Windows 3.1
  125. VER_PLATFORM_WIN32_WINDOWS Win32 on Windows 95
  126. VER_PLATFORM_WIN32_NT Windows NT }
  127. end;
  128. end.

DELPHI在标题栏上增加按钮的更多相关文章

  1. delphi编程实现为Windows窗口标题栏添加新按钮

    下面我们就讨论一下在delphi中如何给窗口的标题栏上添加新的按钮. 一.实现起来要定义以下过程: 1. 定义DrawCaptButton过程,这个过程的功能是在指定的位置画出按钮. 在过程中要使用w ...

  2. Android标题栏上添加多个Menu按钮

    最近项目中碰到要在Android Menu旁边再添加一个按钮,而不是点击menu按钮然后在弹出一些选项. MainActivity代码: public class MainActivity exten ...

  3. C#点击按钮用DataGridView动态增加行、删除行,增加按钮列

    原来有一行: 点击添加,在下面增加同样的一行 新增加的行有一列删除按钮,点击某行的删除按钮时,删除当前行 方法: 哈哈,我果然好聪明啊 1.文本框.文本框.添加按钮 2.一个DataGridView( ...

  4. 为Windows窗口标题栏添加新按钮

    为Windows窗口标题栏添加新按钮   对于我们熟悉的标准windows窗口来讲,标题栏上一般包含有3个按钮,即最大化按钮,最小化按钮和关闭按钮.你想不想在Windows的窗口标题栏上添加一个新的自 ...

  5. Delphi中 为DBNavigator的按钮加中文

    Delphi中 为DBNavigator的按钮加中文 /*Delphi中数据库控件DBNavigator使用起来不错,但是按钮上“+”.“-”等含义对于中国的用户不习惯,甚至不知道是什么含义.改成相应 ...

  6. Mac OS X:在标题栏上显示目录完整路径

    众所周知mac的finder是不带路径显示的,你进入某个文件夹只会显示当前文件夹的名字而已.虽然你可以在finder的菜单栏中点“显示”-“显示路径栏”把路径栏调出来,但是这样只会不必要的增加find ...

  7. 一个漂亮的上传按钮input[type=file]

    ;;} <div class="input-group xj-file xj-panel-top"> <span class="input-group- ...

  8. input上传按钮美化

    <!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content ...

  9. css input[type=file] 样式美化,input上传按钮美化

    css input[type=file] 样式美化,input上传按钮美化 参考:http://www.haorooms.com/post/css_input_uploadmh

随机推荐

  1. GraphicsMagick +im4java高并发处理大型网站图片工具-图片剪切、遮蔽、水印添加之环境搭建

    环境: centos 6.5 GraphicsMagick 下载安装 准备环镜: 需要依赖zlib图片操作函数库 下载地址:http://www.zlib.net/ 编译安装 .tar.gz cd z ...

  2. chpasswd 更简单的更改密码的方式

    [root@m01 .ssh]# useradd test[root@m01 .ssh]# echo "test:123"|chpasswd Linux命令:chpasswd 批量 ...

  3. 流媒体服务器开发笔记(2)--RTCP协议介绍

    http://blog.sina.com.cn/s/blog_53061af00100o2no.html ——————————————————————————————————————————————— ...

  4. java程序调用kettle

    (1).将相应的kettle的jar包导入的java项目,主要的jar包有一下几个. (2).java程序. package cn.com.taiji.oosweb.test.web; import ...

  5. C++ 类的多态一(virtual关键字--构造函数深刻理解)

    //virtual关键字--构造函数深刻理解 #include<iostream> using namespace std; /* C语言编译器,c++编译器全部是静态链编,就是一段一段代 ...

  6. 把查询到结果合并放在一行 JOIN非union

    select one.max,one.min,one.low sts,c.high ens,one.time from ( select a.max max,a.min min,b.low low,a ...

  7. python文件的编译

    背景知识 pyc文件: .pyc 是一种二进制文件,是由 .py 文件经过编译后,生成一种byte code文件. .py 文件变成 .pyc 文件后,加载的速度有所提高,而且 .pyc 是一种跨平台 ...

  8. java语言中public、private、protected三个关键字的用法,重写和重载的区别。

    java语言中public.private.protected三个关键字的用法,重写和重载的区别. 解答: 作用域 当前类 同包 子类 其它 public √ √ √ √ protected √ √ ...

  9. 设置EntityFramework中decimal类型数据精度

    EF中默认的decimal数据精度为两位数,当我们数据库设置的精度大于2时,EF将只会保留到2为精度. e.g. 2.1999将会被保存为2.20 网上找到常见的方法为重写DbContext的OnMo ...

  10. 使用BarcodeLib.Barcode.ASP.NET生成条形码

    生成条形码图片,然后在前台页面展示: <img id="img" src="Mobile/<%=url %>"/> public str ...