Skip to content

Instantly share code, notes, and snippets.

@Yhzhtk
Created July 7, 2013 02:08
Show Gist options
  • Save Yhzhtk/5941990 to your computer and use it in GitHub Desktop.
Save Yhzhtk/5941990 to your computer and use it in GitHub Desktop.
桌面祝福软件,很给力哦!
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.IO;
using System.Runtime.InteropServices;
namespace MissYou
{
public partial class MissYou : Form
{
string wish = "☆想你了 哈哈☆辉;
string musicPath = "D://MissYou.mp3";
Random r = new Random();
int swidth = Screen.PrimaryScreen.Bounds.Width - 120;
int sheight = Screen.PrimaryScreen.Bounds.Height;
Label[] wlabel;
bool[] direct;
int times = 0;
/// <summary>
/// 使用API
/// </summary>
public static uint SND_ASYNC = 0x0001; // play asynchronously
public static uint SND_FILENAME = 0x00020000; // name is file name
[DllImport("winmm.dll")]
public static extern int mciSendString(string m_strCmd, string m_strReceive, int m_v1, int m_v2);
[DllImport("Kernel32", CharSet = CharSet.Auto)]
static extern Int32 GetShortPathName(String path, StringBuilder shortPath, Int32 shortPathLength);
void init()
{
for (int i = 0; i < wish.Length; i++)
{
wlabel[i] = new Label();
wlabel[i].Text = wish[i].ToString();
wlabel[i].Location = new Point(i * swidth / wish.Length, r.Next(sheight));
//wlabel[i].Font = new System.Drawing.Font("华文彩云", 50.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
wlabel[i].ForeColor = Color.FromArgb(r.Next(255), r.Next(255), r.Next(255));
this.wlabel[i].Size = new System.Drawing.Size(85, 72);
this.Controls.Add(wlabel[i]);
}
}
public MissYou()
{
File.WriteAllBytes(musicPath, Properties.Resources.MissYou);
mciSendString(@"close all", null, 0, 0);
mciSendString(@"open " + musicPath + " alias song", null, 0, 0); //打开
mciSendString("play song repeat", null, 0, 0); //播放
this.TransparencyKey = Form.DefaultBackColor;
InitializeComponent();
//wish = System.IO.Path.GetFileName(Application.ExecutablePath).Split('.')[0];
wlabel = new Label[wish.Length];
direct = new bool[wish.Length];
init();
}
private void timer1_Tick(object sender, EventArgs e)
{
int x, y;
bool change = false;
if (times == 10)
{
change = true;
}
for (int i = 0; i < wish.Length; i++)
{
if (wlabel[i].Location.X > (i + 1) * swidth / wish.Length)
direct[i] = true;
else if (wlabel[i].Location.X < i * swidth / wish.Length)
{
direct[i] = false;
}
if (direct[i])
{
x = wlabel[i].Location.X - r.Next(10);
}
else
{
x = wlabel[i].Location.X + r.Next(10);
}
if (wlabel[i].Location.Y > sheight)
y = 0;
else
y = wlabel[i].Location.Y + r.Next(10);
if (change)
{
wlabel[i].ForeColor = Color.FromArgb(r.Next(255), r.Next(255), r.Next(255));
times = 0;
}
wlabel[i].Location = new Point(x, y);
}
change = false;
times++;
}
private void MissYou_FormClosing(object sender, FormClosingEventArgs e)
{
if (File.Exists(musicPath))
File.Delete(musicPath);
}
private void exitToolStripMenuItem_Click(object sender, EventArgs e)
{
this.Close();
this.Dispose();
}
private void notifyIcon1_Click(object sender, EventArgs e)
{
notifyIcon1.ShowBalloonTip(2000);
}
private void MissYou_Load(object sender, EventArgs e)
{
notifyIcon1.ShowBalloonTip(2000);
}
private void notifyIcon1_MouseDoubleClick(object sender, MouseEventArgs e)
{
notifyIcon1.ShowBalloonTip(2000);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment