DELPHI在标题栏上增加按钮
- unit Unit1;
- interface
- uses
- SysUtils, WinTypes, WinProcs, Messages, Classes, Graphics, Controls,
- Forms, Dialogs, Buttons, DdeMan, StdCtrls;
- type
- TTitleBtnForm = class(TForm)
- Button1: TButton;
- procedure FormResize(Sender: TObject);
- private
- TitleButton : TRect;
- procedure DrawTitleButton;
- {Paint-related messages}
- procedure WMSetText(var Msg : TWMSetText); message WM_SETTEXT;
- procedure WMNCPaint(var Msg : TWMNCPaint); message WM_NCPAINT;
- procedure WMNCActivate(var Msg : TWMNCActivate); message WM_NCACTIVATE;
- {Mouse down-related messages}
- procedure WMNCHitTest(var Msg : TWMNCHitTest); message WM_NCHITTEST;
- procedure WMNCLButtonDown(var Msg : TWMNCLButtonDown); message WM_NCLBUTTONDOWN;
- function GetVerInfo : DWORD;
- end;
- var
- TitleBtnForm: TTitleBtnForm;
- const
- htTitleBtn = htSizeLast + 1;
- implementation
- {$R *.DFM}
- procedure TTitleBtnForm.DrawTitleButton;
- var
- bmap : TBitmap; {Bitmap to be drawn - 16 X 16 : 16 Colors}
- XFrame, {X and Y size of Sizeable area of Frame}
- YFrame,
- XTtlBit, {X and Y size of Bitmaps in caption}
- YTtlBit : Integer;
- begin
- {Get size of form frame and bitmaps in title bar}
- XFrame := GetSystemMetrics(SM_CXFRAME);
- YFrame := GetSystemMetrics(SM_CYFRAME);
- XTtlBit := GetSystemMetrics(SM_CXSIZE);
- YTtlBit := GetSystemMetrics(SM_CYSIZE);
- {$IFNDEF WIN32}
- TitleButton := Bounds(Width - (3 * XTtlBit) - ((XTtlBit div 2) - 2),
- YFrame - 1,
- XTtlBit + 2,
- YTtlBit + 2);
- {$ELSE} {Delphi 2.0 positioning}
- if (GetVerInfo = VER_PLATFORM_WIN32_NT) then
- TitleButton := Bounds(Width - (3 * XTtlBit) - ((XTtlBit div 2) - 2),
- YFrame - 1,
- XTtlBit + 2,
- YTtlBit + 2)
- else
- TitleButton := Bounds(Width - XFrame - 4*XTtlBit + 2,
- XFrame + 2,
- XTtlBit + 2,
- YTtlBit + 2);
- {$ENDIF}
- Canvas.Handle := GetWindowDC(Self.Handle); {Get Device context for drawing}
- try
- {Draw a button face on the TRect}
- DrawButtonFace(Canvas, TitleButton, 1, bsAutoDetect, False, False, False);
- bmap := TBitmap.Create;
- bmap.LoadFromFile('c:\windows\desktop\aaa.bmp');
- with TitleButton do
- {$IFNDEF WIN32}
- Canvas.Draw(Left + 2, Top + 2, bmap);
- {$ELSE}
- if (GetVerInfo = VER_PLATFORM_WIN32_NT) then
- Canvas.Draw(Left + 2, Top + 2, bmap)
- else
- Canvas.StretchDraw(TitleButton, bmap);
- {$ENDIF}
- finally
- ReleaseDC(Self.Handle, Canvas.Handle);
- bmap.Free;
- Canvas.Handle := 0;
- end;
- end;
- {Paint triggering events}
- procedure TTitleBtnForm.WMNCActivate(var Msg : TWMNCActivate);
- begin
- Inherited;
- DrawTitleButton;
- end;
- procedure TTitleBtnForm.FormResize(Sender: TObject);
- begin
- Perform(WM_NCACTIVATE, Word(Active), 0);
- end;
- {Painting events}
- procedure TTitleBtnForm.WMNCPaint(var Msg : TWMNCPaint);
- begin
- Inherited;
- DrawTitleButton;
- end;
- procedure TTitleBtnForm.WMSetText(var Msg : TWMSetText);
- begin
- Inherited;
- DrawTitleButton;
- end;
- {Mouse-related procedures}
- procedure TTitleBtnForm.WMNCHitTest(var Msg : TWMNCHitTest);
- begin
- Inherited;
- {Check to see if the mouse was clicked in the area of the button}
- with Msg do
- if PtInRect(TitleButton, Point(XPos - Left, YPos - Top)) then
- Result := htTitleBtn;
- end;
- procedure TTitleBtnForm.WMNCLButtonDown(var Msg : TWMNCLButtonDown);
- begin
- inherited;
- if (Msg.HitTest = htTitleBtn) then
- ShowMessage('You pressed the new button');
- end;
- function TTitleBtnForm.GetVerInfo : DWORD;
- var
- verInfo : TOSVERSIONINFO;
- begin
- result:=0;
- verInfo.dwOSVersionInfoSize := SizeOf(TOSVersionInfo);
- if GetVersionEx(verInfo) then
- Result := verInfo.dwPlatformID;
- {Returns:
- VER_PLATFORM_WIN32s Win32s on Windows 3.1
- VER_PLATFORM_WIN32_WINDOWS Win32 on Windows 95
- VER_PLATFORM_WIN32_NT Windows NT }
- end;
- end.
DELPHI在标题栏上增加按钮的更多相关文章
- delphi编程实现为Windows窗口标题栏添加新按钮
下面我们就讨论一下在delphi中如何给窗口的标题栏上添加新的按钮. 一.实现起来要定义以下过程: 1. 定义DrawCaptButton过程,这个过程的功能是在指定的位置画出按钮. 在过程中要使用w ...
- Android标题栏上添加多个Menu按钮
最近项目中碰到要在Android Menu旁边再添加一个按钮,而不是点击menu按钮然后在弹出一些选项. MainActivity代码: public class MainActivity exten ...
- C#点击按钮用DataGridView动态增加行、删除行,增加按钮列
原来有一行: 点击添加,在下面增加同样的一行 新增加的行有一列删除按钮,点击某行的删除按钮时,删除当前行 方法: 哈哈,我果然好聪明啊 1.文本框.文本框.添加按钮 2.一个DataGridView( ...
- 为Windows窗口标题栏添加新按钮
为Windows窗口标题栏添加新按钮 对于我们熟悉的标准windows窗口来讲,标题栏上一般包含有3个按钮,即最大化按钮,最小化按钮和关闭按钮.你想不想在Windows的窗口标题栏上添加一个新的自 ...
- Delphi中 为DBNavigator的按钮加中文
Delphi中 为DBNavigator的按钮加中文 /*Delphi中数据库控件DBNavigator使用起来不错,但是按钮上“+”.“-”等含义对于中国的用户不习惯,甚至不知道是什么含义.改成相应 ...
- Mac OS X:在标题栏上显示目录完整路径
众所周知mac的finder是不带路径显示的,你进入某个文件夹只会显示当前文件夹的名字而已.虽然你可以在finder的菜单栏中点“显示”-“显示路径栏”把路径栏调出来,但是这样只会不必要的增加find ...
- 一个漂亮的上传按钮input[type=file]
;;} <div class="input-group xj-file xj-panel-top"> <span class="input-group- ...
- input上传按钮美化
<!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content ...
- css input[type=file] 样式美化,input上传按钮美化
css input[type=file] 样式美化,input上传按钮美化 参考:http://www.haorooms.com/post/css_input_uploadmh
随机推荐
- Tuning 04 Sizing the Buffer Cache
Buffer Cache 特性 The buffer cache holds copies of the data blocks from the data files. Because the bu ...
- Swift-9-类和结构体
// Playground - noun: a place where people can play import UIKit // 几个重要的概念Properties/Methods/Subscr ...
- 【C++自我精讲】基础系列三 重载
[C++自我精讲]基础系列三 重载 0 前言 分二部分:函数重载,操作符重载. 1 函数重载 函数重载:指在同一名字空间中,函数名称相同,参数类型.顺序或数量不同的一类函数,同一函数名的函数能完成不同 ...
- 《linux 内核全然剖析》 include/asm/io.h
include/asm/io.h #define outb(value,port) \ __asm__ ("outb %%al,%%dx"::"a" (valu ...
- Effective JavaScript Item 55 接受配置对象作为函数參数
接受配置对象作为函数參数 尽管保持函数接受的參数的顺序非常重要,可是当函数可以接受的參数达到一定数量时.也会让用户非常头疼: var alert = new Alert(100, 75, 300, 2 ...
- SR领域文献资源汇总(链接地址)
DRCN http://www.drcn.org/ The International Workshop on Design of Reliable Communication Networks ...
- [分享]JavaScript Quick Reference Card
pdf文件:https://files.cnblogs.com/files/MakeView660/JavaScript_Quick_Reference_Card.pdf
- Visual Studio 2015 自定义文件编译
自己编译好了 QT 5.6.0 Alpha 版本后,如何使用 VS2015 创建 QT 工程呢? 1.安装插件,安装失败!因为 VS2015 不再支持 ADDIN , 所以 QT-VS-ADDIN 只 ...
- 延迟任务和循环任务ScheduledExecutorService
public class ScheduledThreadPool { public static ScheduledExecutorService scheduledThreadPool = Exec ...
- Mac中pico编辑器的使用方法
Pico是一个由华盛顿大学(University of Washington)计算与通讯研究所(Computing and Communications Group)编写并维护的文本编辑程序,在多个版 ...