严重参考FLASHELF DX的文章:http://www.cnblogs.com/flashelf/archive/2006/10/07/522777.html
呵呵,基本算是抄袭,就是瞄准器根据自己习惯改了下。
学习了一点GDI的东西,顺便记下来。扬州移动出差,偷写。 :-)
主要是通过GetDC API获得桌面的句柄,再根据该句柄创建Graphics对象。
PS:笔记本测试,发现失败,进入CS1.5后,瞄准镜消失,无法最前。有了解的,大家帮忙!!!!!!
代码及程序点击下载
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Runtime.InteropServices;

namespace cs_cheat


{

/**//// <summary>
/// Form1 的摘要说明。
/// </summary>
public class CS_CHEAT : System.Windows.Forms.Form

{
private System.Windows.Forms.Timer timer1;
private System.Windows.Forms.NotifyIcon notifyIcon1;
private System.Windows.Forms.ContextMenu contextMenu1;
private System.Windows.Forms.MenuItem menuItem_config;
private System.Windows.Forms.MenuItem menuItem_exit;
private System.Windows.Forms.MenuItem menuItem_640;
private System.Windows.Forms.MenuItem menuItem_1650;
private System.Windows.Forms.MenuItem menuItem_800;
private System.Windows.Forms.MenuItem menuItem_1024;
private System.Windows.Forms.MenuItem menuItem1;
private System.ComponentModel.IContainer components;
[DllImport("User32.dll")]
public extern static System.IntPtr GetDC(System.IntPtr hWnd);
[DllImport("user32.dll", CharSet=CharSet.Auto)]
public static extern bool InvalidateRect(IntPtr hWnd,IntPtr lpRect ,bool bErase);

int x=839;
int y=525;
int w=4;
System.IntPtr DesktopHandle = GetDC(System.IntPtr.Zero);

public CS_CHEAT()

{
//
// Windows 窗体设计器支持所必需的
//
InitializeComponent();

//
// TODO: 在 InitializeComponent 调用后添加任何构造函数代码
//
}


/**//// <summary>
/// 清理所有正在使用的资源。
/// </summary>
protected override void Dispose( bool disposing )

{
if( disposing )

{
if (components != null)

{
components.Dispose();
}
}
base.Dispose( disposing );
}


Windows 窗体设计器生成的代码#region Windows 窗体设计器生成的代码

/**//// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()

{
this.components = new System.ComponentModel.Container();
System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(CS_CHEAT));
this.timer1 = new System.Windows.Forms.Timer(this.components);
this.notifyIcon1 = new System.Windows.Forms.NotifyIcon(this.components);
this.contextMenu1 = new System.Windows.Forms.ContextMenu();
this.menuItem_config = new System.Windows.Forms.MenuItem();
this.menuItem_exit = new System.Windows.Forms.MenuItem();
this.menuItem_640 = new System.Windows.Forms.MenuItem();
this.menuItem_1650 = new System.Windows.Forms.MenuItem();
this.menuItem_800 = new System.Windows.Forms.MenuItem();
this.menuItem_1024 = new System.Windows.Forms.MenuItem();
this.menuItem1 = new System.Windows.Forms.MenuItem();
//
// timer1
//
this.timer1.Enabled = true;
this.timer1.Interval = 5;
this.timer1.Tick += new System.EventHandler(this.timer1_Tick);
//
// notifyIcon1
//
this.notifyIcon1.ContextMenu = this.contextMenu1;
this.notifyIcon1.Icon = ((System.Drawing.Icon)(resources.GetObject("notifyIcon1.Icon")));
this.notifyIcon1.Text = "notifyIcon1";
this.notifyIcon1.Visible = true;
//
// contextMenu1
//

this.contextMenu1.MenuItems.AddRange(new System.Windows.Forms.MenuItem[]
{
this.menuItem1,
this.menuItem_config,
this.menuItem_exit});
//
// menuItem_config
//
this.menuItem_config.Index = 1;

this.menuItem_config.MenuItems.AddRange(new System.Windows.Forms.MenuItem[]
{
this.menuItem_640,
this.menuItem_800,
this.menuItem_1024,
this.menuItem_1650});
this.menuItem_config.Text = "屏幕配置";
//
// menuItem_exit
//
this.menuItem_exit.Index = 2;
this.menuItem_exit.Text = "退出";
this.menuItem_exit.Click += new System.EventHandler(this.menuItem_exit_Click);
//
// menuItem_640
//
this.menuItem_640.Index = 0;
this.menuItem_640.Text = "640X480";
this.menuItem_640.Click += new System.EventHandler(this.menuItem_640_Click);
//
// menuItem_1650
//
this.menuItem_1650.Index = 3;
this.menuItem_1650.Text = "1650X1050";
this.menuItem_1650.Click += new System.EventHandler(this.menuItem_1650_Click);
//
// menuItem_800
//
this.menuItem_800.Index = 1;
this.menuItem_800.Text = "800X600";
this.menuItem_800.Click += new System.EventHandler(this.menuItem_800_Click);
//
// menuItem_1024
//
this.menuItem_1024.Index = 2;
this.menuItem_1024.Text = "1024X768";
this.menuItem_1024.Click += new System.EventHandler(this.menuItem_1024_Click);
//
// menuItem1
//
this.menuItem1.Index = 0;
this.menuItem1.Text = "By MadGoat 2006-12-01";
//
// CS_CHEAT
//
this.AutoScaleBaseSize = new System.Drawing.Size(8, 18);
this.ClientSize = new System.Drawing.Size(256, 144);
this.Name = "CS_CHEAT";
this.ShowInTaskbar = false;
this.Text = "CS_CHEAT 0.1";
this.WindowState = System.Windows.Forms.FormWindowState.Minimized;
this.Closed += new System.EventHandler(this.Form1_Closed);

}
#endregion


/**//// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main()

{
Application.Run(new CS_CHEAT());
}

private void timer1_Tick(object sender, System.EventArgs e)

{
Graphics g = System.Drawing.Graphics.FromHdc(DesktopHandle);
g.FillRectangle(Brushes.Lime,x,y,w,w);
g.FillRectangle(Brushes.Lime,x-15,y,10,w);
g.FillRectangle(Brushes.Lime,x+5+w,y,10,w);
g.FillRectangle(Brushes.Lime,x,y-15,w,10);
g.FillRectangle(Brushes.Lime,x,y+5+w,w,10);
}

private void menuItem_exit_Click(object sender, System.EventArgs e)

{
this.Close();
}

private void Form1_Closed(object sender, System.EventArgs e)

{
InvalidateRect(IntPtr.Zero,IntPtr.Zero,false);
}

private void menuItem_800_Click(object sender, System.EventArgs e)

{
x=399;
y=300;
InvalidateRect(IntPtr.Zero,IntPtr.Zero,false);
}

private void menuItem_1024_Click(object sender, System.EventArgs e)

{
x=511;
y=384;
InvalidateRect(IntPtr.Zero,IntPtr.Zero,false);
}

private void menuItem_640_Click(object sender, System.EventArgs e)

{
x=319;
y=240;
InvalidateRect(IntPtr.Zero,IntPtr.Zero,false);
}

private void menuItem_1650_Click(object sender, System.EventArgs e)

{
x=839;
y=525;
InvalidateRect(IntPtr.Zero,IntPtr.Zero,false);
}
}
}
