新建一个应用程序,在窗体上放置一个TTimer和一个TPopupMenu,TTimer的Interval属性为1500,TPopupMenu建立三个子菜单项,分别为“总在最前”、“背景穿透”和“退出”。
再准备一张背景图片。工程源代码如下:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, IGDIPlus, ExtCtrls, Menus;
type
TForm1 = class(TForm)
tmr1: TTimer;
pm1: TPopupMenu;
mni_topMost: TMenuItem;
mni_transparent: TMenuItem;
mni_exit: TMenuItem;
procedure FormCreate(Sender: TObject);
procedure FormMouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
procedure FormMouseMove(Sender: TObject; Shift: TShiftState; X,
Y: Integer);
procedure tmr1Timer(Sender: TObject);
procedure mni_topMostClick(Sender: TObject);
procedure MouseLeave(var Msg: TMessage);message WM_MOUSELEAVE;
procedure mni_transparentClick(Sender: TObject);
procedure mni_exitClick(Sender: TObject);
private
m_Kind: Integer; //当前第几行字符串
m_bBack: Boolean; //是否显示背景
m_pszbuf: array[0..5] of WideString; //要绘制的字符串数组
function UpdateDisplay(pszbuf: WideString;bBack: Boolean = False;
Transparent: Integer = 100):Boolean;
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
{-------------------------------------------------------------------------------
过程名: TForm1.UpdateDisplay
功能: 绘制桌面歌词
参数: pszbuf: WideString; 绘制的字符串
bBack: Boolean; 是否绘制背景
Transparent: Integer 透明程度
返回值: Boolean
-------------------------------------------------------------------------------}
function TForm1.UpdateDisplay(pszbuf: WideString;bBack: Boolean;Transparent: Integer):Boolean;
var
hdcTemp,hdcScreen,m_hdcMemory: HDC;
hBitMap: Windows.HBITMAP;
blend: BLENDFUNCTION; //这种结构的混合控制通过指定源和目标位图的混合功能
rct: TRect;
ptWinPos,ptSrc: TPoint;
graphics: IGPGraphics; //封装一个 GDI+ 绘图图面
fontFamily: IGPFontFamily; /