软件都是半成品,各位看管不要挑剔就好;代码可以拿去随便用,如果您从我的代码中学习到了东西或找到了灵感来这里说声谢谢或顶一下就好了。
软件截图:
点击看大图
红色的字就是软件的效果了、任务栏中 FoxMail 前面的图标就是本程序;程序没有什么高深技术就是用了几个API;技术基本和上一次发的“CS忙狙器”类似说明如下
程序中用到的API
//
取得绘图句柄
[DllImport( " user32.dll " , CharSet = CharSet.Auto)]
public static extern IntPtr GetDC(IntPtr hWnd);
// 释放绘图句柄
[DllImport( " user32.dll " , CharSet = CharSet.Auto)]
public static extern int ReleaseDC(IntPtr hWnd, IntPtr hDC);
// 刷新区域
[DllImport( " user32.dll " , CharSet = CharSet.Auto)]
public static extern bool InvalidateRect(IntPtr hWnd, IntPtr lpRect, bool bErase);
应用程序初始化:
[DllImport( " user32.dll " , CharSet = CharSet.Auto)]
public static extern IntPtr GetDC(IntPtr hWnd);
// 释放绘图句柄
[DllImport( " user32.dll " , CharSet = CharSet.Auto)]
public static extern int ReleaseDC(IntPtr hWnd, IntPtr hDC);
// 刷新区域
[DllImport( " user32.dll " , CharSet = CharSet.Auto)]
public static extern bool InvalidateRect(IntPtr hWnd, IntPtr lpRect, bool bErase);
隐藏窗口,这里可以使窗口根本就不出现
protected
override
CreateParams CreateParams
{
get
{
base .Visible = false ; // 隐藏窗口
return base .CreateParams;
}
}
{
get
{
base .Visible = false ; // 隐藏窗口
return base .CreateParams;
}
}
程序绘图流程很简单:
取得屏幕绘图句柄 GetGC -> 创建 Graphics -> 向屏幕上写字 -> 释放绘图句柄 ReleaseDC
private
void
timer1_Tick(
object
sender, EventArgs e)
{
if (swTick == false )
{
swTick = true ;
try
{
IntPtr hdc;
System.Drawing.Graphics g;
int x = Settings.Default.TextXY.X;
int y = Settings.Default.TextXY.Y;
Rectangle workingArea = Screen.PrimaryScreen.WorkingArea;
Rectangle TaskDrawArea = new Rectangle(x, y, workingArea.Width - x, workingArea.Height - y);
int textOpacity = 50 ;
hdc = GetDC(IntPtr.Zero); // 1) 参数 0 就是取得整个屏幕的GC句柄
using (g = System.Drawing.Graphics.FromHdc(hdc))
{
g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
g.TextRenderingHint = System.Drawing.Text.TextRenderingHint.ClearTypeGridFit; // 设置利用 ClearType
Color clr = Color.FromArgb(textOpacity, Settings.Default.TextColor);
Font f = Settings.Default.TextFont;
using (SolidBrush sldbrush = new SolidBrush(clr))
{
g.DrawString(Settings.Default.TaskText.Replace( " \t " , " " ), f, sldbrush, TaskDrawArea); // 2) 写字
}
}
ReleaseDC(IntPtr.Zero, hdc); // 2)释放GC
}
catch (Exception ex)
{
Debug.WriteLine(ex.Message);
}
finally
{
swTick = false ;
}
}
}
{
if (swTick == false )
{
swTick = true ;
try
{
IntPtr hdc;
System.Drawing.Graphics g;
int x = Settings.Default.TextXY.X;
int y = Settings.Default.TextXY.Y;
Rectangle workingArea = Screen.PrimaryScreen.WorkingArea;
Rectangle TaskDrawArea = new Rectangle(x, y, workingArea.Width - x, workingArea.Height - y);
int textOpacity = 50 ;
hdc = GetDC(IntPtr.Zero); // 1) 参数 0 就是取得整个屏幕的GC句柄
using (g = System.Drawing.Graphics.FromHdc(hdc))
{
g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
g.TextRenderingHint = System.Drawing.Text.TextRenderingHint.ClearTypeGridFit; // 设置利用 ClearType
Color clr = Color.FromArgb(textOpacity, Settings.Default.TextColor);
Font f = Settings.Default.TextFont;
using (SolidBrush sldbrush = new SolidBrush(clr))
{
g.DrawString(Settings.Default.TaskText.Replace( " \t " , " " ), f, sldbrush, TaskDrawArea); // 2) 写字
}
}
ReleaseDC(IntPtr.Zero, hdc); // 2)释放GC
}
catch (Exception ex)
{
Debug.WriteLine(ex.Message);
}
finally
{
swTick = false ;
}
}
}
窗口关闭时:
使用 InvalidateRect API 刷新整个屏幕
protected
override
void
OnHandleDestroyed(EventArgs e)
{
// 刷新整个屏幕
bool rVar = InvalidateRect(IntPtr.Zero, IntPtr.Zero, false );
base .OnHandleDestroyed(e);
}
{
// 刷新整个屏幕
bool rVar = InvalidateRect(IntPtr.Zero, IntPtr.Zero, false );
base .OnHandleDestroyed(e);
}
工程中还有:
设置窗口:设置文本位置、字体颜色等 相关技术:绑定配置文件,绑定config
文本更改窗口:更改文本;
不多说了:下载代码