c#桌面飘雪小程序,之前在网上查到过代码,但有很多错误,并且在win7下无法运行。
将其改成c#代码,并测试,效果如上图,可兼容XP和win7系统均可运行。 其主要代码如下:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Threading;
using System.Runtime.InteropServices;
namespace WindowsXueJi04
{
public partial class Form1 : Form
{
[DllImport("gdi32.dll")]
static extern int SetPixel(IntPtr hSdc, int x, int y, int crColor);
[System.Runtime.InteropServices.DllImportAttribute("gdi32.dll")]
public static extern IntPtr CreateDC(string lpszDriver, string lpszDevice, string lpszOutput, int lpInitData);
[DllImport("gdi32.dll")]
public static extern int DeleteDC(IntPtr hdc);
static int SnowNumber = 600;
public SnowNode[] SnowNodes = new SnowNode[SnowNumber];
int CrWind = 0;
int ScreenWidth; //屏幕宽度
int ScreenHeight;