C# 桌面雪花飘飘 雪花飘飘洒洒
usingSystem;usingSystem.Collections.Generic;usingSystem.Drawing;usingSystem.Drawing.Drawing2D;usingSystem.Drawing.Imaging;usingSystem.Runtime.InteropServices;usingSystem.Windows.Forms; namespace雪花飘飘{publicpartialclassForm1:Form{privateBitmapm_Snow;privateImagescreenImage;privateTimertimer=newTimer();privatestaticreadonlyRandomrand=newRandom();privatereadonlyList<SnowFlake>SnowFlakes=newList<SnowFlake>();privateintTick=0; publicForm1(){this.components=newSystem.ComponentModel.Container();this.timer=newSystem.Windows.Forms.Timer(this.components);this.SuspendLayout();////timer//this.timer.Enabled=true;this.timer.Interval=100;this.timer.Tick+=newSystem.EventHandler(this.OnTick);////Form1//this.ControlBox=false;this.ShowInTaskbar=false;this.StartPosition=System.Windows.Forms.FormStartPosition.CenterScreen;this.TopMost=true;this.WindowState=System.Windows.Forms.FormWindowState.Maximized;this.ResumeLayout(false); SetStyle(ControlStyles.UserPaint|ControlStyles.AllPaintingInWmPaint|ControlStyles.DoubleBuffer,true); screenImage=newBitmap(Screen.PrimaryScreen.Bounds.Width,Screen.PrimaryScreen.Bounds.Height); } privatevoidOnTick(objectsender,EventArgsargs){Tick++;//newsnowflake//控制雪量if(Tick%5==0&&rand.NextDouble()<0.30){SnowFlakes=newSnowFlake();s.X=rand.Next(-20,this.Width+20);s.Y=0f;s.XVelocity=(float)(rand.NextDouble()-0.5f)*2f;s.YVelocity=(float)(rand.NextDouble()*3)+1f;s.Rotation=rand.Next(0,359);s.RotVelocity=rand.Next(-3,3)*2;if(s.RotVelocity==0){s.RotVelocity=3;}s.Scale=(float)(rand.NextDouble()/2)+0.75f;SnowFlakes.Add(s);}//TodrawsnowflakeGraphicsg=Graphics.FromImage(screenImage);g.Clear(Color.Transparent);g.SmoothingMode=SmoothingMode.HighSpeed; for(inti=0;i<SnowFlakes.Count;i++){SnowFlakes=SnowFlakes[i];s.X+=s.XVelocity;s.Y+=s.YVelocity;s.Rotation+=s.RotVelocity;s.XVelocity+=((float)rand.NextDouble()-0.5f)*0.7f;s.XVelocity=Math.Max(s.XVelocity,-2f);s.XVelocity=Math.Min(s.XVelocity,+2f);//如果雪下到屏幕下面后就让他消失if(s.Y>this.Height){SnowFlakes.RemoveAt(i);}//没有落到屏幕下面的时候就继续让它往下落else{g.ResetTransform();g.TranslateTransform(-16,-16,MatrixOrder.Append);//pang.ScaleTransform(s.Scale,s.Scale,MatrixOrder.Append);//scaleg.RotateTransform(s.Rotation,MatrixOrder.Append);//rotateg.TranslateTransform(s.X,s.Y,MatrixOrder.Append);//pang.DrawImage(Snow,0,0);//draw}}g.Dispose();SetBackground(screenImage);} privateclassSnowFlake{publicfloatRotation;publicfloatRotVelocity;publicfloatScale;publicfloatX;publicfloatXVelocity;publicfloatY;publicfloatYVelocity;} privatevoidSetBackground(Imageimg){try{Bitmapbitmap=(Bitmap)img;if(bitmap.PixelFormat!=PixelFormat.Format32bppArgb){thrownewApplicationException();}IntPtrhObject=IntPtr.Zero;IntPtrzero=IntPtr.Zero;IntPtrhDC=Win32.GetDC(IntPtr.Zero);IntPtrptr2=Win32.CreateCompatibleDC(hDC);try{hObject=bitmap.GetHbitmap(Color.FromArgb(0));zero=Win32.SelectObject(ptr2,hObject);Win32.Sizesize2=newWin32.Size(bitmap.Width,bitmap.Height);Win32.Sizepsize=size2;Win32.Pointpoint3=newWin32.Point(0,0);Win32.PointpprSrc=point3;point3=newWin32.Point(base.Left,base.Top);Win32.PointpptDst=point3;Win32.BLENDFUNCTIONpblend=newWin32.BLENDFUNCTION();pblend.BlendOp=0;pblend.BlendFlags=0;pblend.SourceConstantAlpha=0xff;pblend.AlphaFormat=1;Win32.UpdateLayeredWindow(this.Handle,hDC,refpptDst,refpsize,ptr2,refpprSrc,0,refpblend,2);}catch(Exceptionexception1){Exceptionexception=exception1;throwexception;}finally{Win32.ReleaseDC(IntPtr.Zero,hDC);if(hObject!=IntPtr.Zero){Win32.SelectObject(ptr2,zero);Win32.DeleteObject(hObject);}Win32.DeleteDC(ptr2);}}catch(Exceptione){MessageBox.Show(e.Message);}} protectedoverrideSystem.Windows.Forms.CreateParamsCreateParams{get{System.Windows.Forms.CreateParamscreateParams=base.CreateParams;createParams.ExStyle|=0x80000;returncreateParams;}} privateBitmapSnow{get{if(m_Snow==null){m_Snow=newBitmap(32,32);using(Graphicsg=Graphics.FromImage(m_Snow)){g.SmoothingMode=SmoothingMode.AntiAlias;g.Clear(Color.Transparent);g.TranslateTransform(16,16,MatrixOrder.Append);Colorblack=Color.FromArgb(1,1,1);Colorwhite=Color.FromArgb(255,255,255);DrawSnow(g,newSolidBrush(black),newPen(black,3f));DrawSnow(g,newSolidBrush(white),newPen(white,2f));g.Save();}}returnm_Snow;}} privatestaticvoidDrawSnow(Graphicsg,Brushb,Penp){constinta=6;constinta2=a+2;constintr=2;g.DrawLine(p,-a,-a,+a,+a);g.DrawLine(p,-a,+a,+a,-a);g.DrawLine(p,-a2,0,+a2,0);g.DrawLine(p,0,-a2,0,+a2);g.FillEllipse(b,-r,-r,r*2,r*2);} }internalclassWin32{publicconstbyteAC_SRC_ALPHA=1;publicconstbyteAC_SRC_OVER=0;publicconstintULW_ALPHA=2; [DllImport("gdi32.dll")]publicstaticexternIntPtrCreateCompatibleDC(IntPtrhDC);[DllImport("gdi32.dll")]publicstaticexternBoolDeleteDC(IntPtrhdc);[DllImport("gdi32.dll")]publicstaticexternBoolDeleteObject(IntPtrhObject);[DllImport("user32.dll")]publicstaticexternIntPtrGetDC(IntPtrhandle);[DllImport("user32.dll",ExactSpelling=true)]publicstaticexternintReleaseDC(IntPtrhandle,IntPtrhDC);[DllImport("gdi32.dll")]publicstaticexternIntPtrSelectObject(IntPtrhDC,IntPtrhObject);[DllImport("user32.dll")]publicstaticexternBoolUpdateLayeredWindow(IntPtrhandle,IntPtrhdcDst,refPointpptDst,refSizepsize,IntPtrhdcSrc,refPointpprSrc,intcrKey,refBLENDFUNCTIONpblend,intdwFlags); [StructLayout(LayoutKind.Sequential)]publicstructBLENDFUNCTION{publicbyteBlendOp;publicbyteBlendFlags;publicbyteSourceConstantAlpha;publicbyteAlphaFormat;} publicenumBool{False,True} [StructLayout(LayoutKind.Sequential)]publicstructPoint{publicintx;publicinty;publicPoint(intx,inty){this=newWin32.Point();this.x=x;this.y=y;}} [StructLayout(LayoutKind.Sequential)]publicstructSize{publicintcx;publicintcy;publicSize(intcx,intcy){this=newWin32.Size();this.cx=cx;this.cy=cy;}}} }
更多阅读
转载 数字与历史——写给20121212李亚童 历史齐文化ppt转载
原文地址:数字与历史——写给20121212李亚童作者:李庄 按:北京下雪了,早晨起床,看见窗外飘飘洒洒的美丽雪花,银装素裹,分外妖娆,雪,是柔弱的,风吹欲碎,雪,又是坚强的,赋路万条。在欣赏悦目景色的同时,遐想着明年烂漫的春光。今天,是个千年一遇的日
现代文阅读及答案 《身后的眼睛》答案
《小鸟,你飞向何方》在黄昏的微光里,有那清晨的鸟儿来到了我的沉默的鸟巢里。我喜欢泰戈尔的诗。还在读中学的时候,泰戈尔就把我迷住了,一本薄薄的《飞鸟集》,竟被我纤的嫩的手指翻得稀烂。好些充满着光彩和幻想的诗句,曾多少次拨动我少
外面的雪花飘进来(小说 王继怀 文艺处 王继怀
外面的雪花飘进来王继怀1牛家营和马家店两村毗邻,中间只隔一座小山,走大路两村之间超不过五里路,翻山走小路也就一二里的路程,两个自然村同属一个村委会。牛家营村子不大总共也就百十来户,没有杂性一水都姓马。马家店村稍大百十多户,
杜甫的诗歌:《茅屋为秋风所破歌》:“八月秋高风怒号,卷我屋上
杜甫的诗歌:《茅屋为秋风所破歌》:“八月秋高风怒号,卷我屋上三重茅。茅飞渡江洒江郊,高者挂罥长林梢,下者飘转沈塘坳。八月深秋,狂风怒号,(风)卷走了我屋顶上好几层茅草。茅草乱飞,渡过浣花溪,散落在对岸江边。飞得高的茅草悬挂在高高的树梢上
天山雪 天山雪原味酸牛奶饮品
巍巍天山似乎与生俱来就与雪有着密切的关系,因为历史上它曾有过白山、雪山等名字。晋代山水诗人谢眺冬日见雪,即赋诗曰“飞雪天山来,飘聚绳棂外”(《答王世子诗》),诗仙李白说“白雪初下天山外,浮云直上五原间”(《从军行》),唐人董思恭《咏