﻿<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/"><channel><title>IT博客-ChengKing-文章分类-.Net使用DLL中的方法</title><link>http://www.cnitblog.com/ChengKing/category/1230.html</link><description>ChengKing</description><language>zh-cn</language><lastBuildDate>Mon, 03 Oct 2011 09:17:34 GMT</lastBuildDate><pubDate>Mon, 03 Oct 2011 09:17:34 GMT</pubDate><ttl>60</ttl><item><title>DerectX7实现播放音乐效果</title><link>http://www.cnitblog.com/ChengKing/articles/4004.html</link><dc:creator>ZhengJian</dc:creator><author>ZhengJian</author><pubDate>Sun, 06 Nov 2005 04:40:00 GMT</pubDate><guid>http://www.cnitblog.com/ChengKing/articles/4004.html</guid><wfw:comment>http://www.cnitblog.com/ChengKing/comments/4004.html</wfw:comment><comments>http://www.cnitblog.com/ChengKing/articles/4004.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cnitblog.com/ChengKing/comments/commentRss/4004.html</wfw:commentRss><trackback:ping>http://www.cnitblog.com/ChengKing/services/trackbacks/4004.html</trackback:ping><description><![CDATA[<P>using System;<BR>using System.Drawing;<BR>using System.Collections;<BR>using System.ComponentModel;<BR>using System.Windows.Forms;<BR>using System.Data;</P>
<P>using DxVBLib;</P>
<P>namespace 播放音乐<BR>{<BR>&nbsp;/// &lt;summary&gt;<BR>&nbsp;/// Form1 的摘要说明。<BR>&nbsp;/// &lt;/summary&gt;<BR>&nbsp;public class Form1 : System.Windows.Forms.Form<BR>&nbsp;{<BR>&nbsp;&nbsp;/// &lt;summary&gt;<BR>&nbsp;&nbsp;/// 必需的设计器变量。<BR>&nbsp;&nbsp;/// &lt;/summary&gt;<BR>&nbsp;&nbsp;private System.ComponentModel.Container components = null;</P>
<P>&nbsp;&nbsp;public Form1()<BR>&nbsp;&nbsp;{<BR>&nbsp;&nbsp;&nbsp;//<BR>&nbsp;&nbsp;&nbsp;// Windows 窗体设计器支持所必需的<BR>&nbsp;&nbsp;&nbsp;//<BR>&nbsp;&nbsp;&nbsp;InitializeComponent();</P>
<P>&nbsp;&nbsp;&nbsp;<BR>&nbsp;&nbsp;&nbsp;directX=new DirectX7Class();<BR>&nbsp;&nbsp;&nbsp;performance=directX.DirectMusicPerformanceCreate();<BR>&nbsp;&nbsp;&nbsp;composer=directX.DirectMusicComposerCreate();<BR>&nbsp;&nbsp;&nbsp;loader=directX.DirectMusicLoaderCreate();</P>
<P>&nbsp;&nbsp;&nbsp;performance.Init(null,0);<BR>&nbsp;&nbsp;&nbsp;performance.SetPort(-1,4);<BR>&nbsp;&nbsp;&nbsp;performance.SetMasterAutoDownload(true);</P>
<P>&nbsp;&nbsp;&nbsp;<BR>&nbsp;&nbsp;&nbsp;//chordMap=loader.LoadChordMap(@"F:\游戏音乐(mid)\GAME01FM.MID");<BR>&nbsp;&nbsp;&nbsp;try<BR>&nbsp;&nbsp;&nbsp;{<BR>&nbsp;&nbsp;&nbsp;&nbsp;chordMap=loader.LoadChordMap("CHORDMAP.CDM");<BR>&nbsp;&nbsp;&nbsp;}<BR>&nbsp;&nbsp;&nbsp;catch (Exception)<BR>&nbsp;&nbsp;&nbsp;{<BR>&nbsp;&nbsp;&nbsp;&nbsp;MessageBox.Show("Could not load ChordMap."+"Please ensure that CHORDMAP.CDM is"+"in the directory of this exectutable.");<BR>&nbsp;&nbsp;&nbsp;}</P>
<P>&nbsp;&nbsp;&nbsp;//<BR>&nbsp;&nbsp;&nbsp;// TODO: 在 InitializeComponent 调用后添加任何构造函数代码<BR>&nbsp;&nbsp;&nbsp;//<BR>&nbsp;&nbsp;}</P>
<P>&nbsp;&nbsp;/// &lt;summary&gt;<BR>&nbsp;&nbsp;/// 清理所有正在使用的资源。<BR>&nbsp;&nbsp;/// &lt;/summary&gt;<BR>&nbsp;&nbsp;protected override void Dispose( bool disposing )<BR>&nbsp;&nbsp;{<BR>&nbsp;&nbsp;&nbsp;if( disposing )<BR>&nbsp;&nbsp;&nbsp;{<BR>&nbsp;&nbsp;&nbsp;&nbsp;if (components != null) <BR>&nbsp;&nbsp;&nbsp;&nbsp;{<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;components.Dispose();<BR>&nbsp;&nbsp;&nbsp;&nbsp;}<BR>&nbsp;&nbsp;&nbsp;}<BR>&nbsp;&nbsp;&nbsp;base.Dispose( disposing );<BR>&nbsp;&nbsp;}</P>
<P>&nbsp;&nbsp;#region Windows 窗体设计器生成的代码<BR>&nbsp;&nbsp;/// &lt;summary&gt;<BR>&nbsp;&nbsp;/// 设计器支持所需的方法 - 不要使用代码编辑器修改<BR>&nbsp;&nbsp;/// 此方法的内容。<BR>&nbsp;&nbsp;/// &lt;/summary&gt;<BR>&nbsp;&nbsp;private void InitializeComponent()<BR>&nbsp;&nbsp;{<BR>&nbsp;&nbsp;&nbsp;this.button1 = new System.Windows.Forms.Button();<BR>&nbsp;&nbsp;&nbsp;this.SuspendLayout();<BR>&nbsp;&nbsp;&nbsp;// <BR>&nbsp;&nbsp;&nbsp;// button1<BR>&nbsp;&nbsp;&nbsp;// <BR>&nbsp;&nbsp;&nbsp;this.button1.Location = new System.Drawing.Point(96, 192);<BR>&nbsp;&nbsp;&nbsp;this.button1.Name = "button1";<BR>&nbsp;&nbsp;&nbsp;this.button1.TabIndex = 0;<BR>&nbsp;&nbsp;&nbsp;this.button1.Text = "button1";<BR>&nbsp;&nbsp;&nbsp;this.button1.Click += new System.EventHandler(this.button1_Click);<BR>&nbsp;&nbsp;&nbsp;// <BR>&nbsp;&nbsp;&nbsp;// Form1<BR>&nbsp;&nbsp;&nbsp;// <BR>&nbsp;&nbsp;&nbsp;this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);<BR>&nbsp;&nbsp;&nbsp;this.ClientSize = new System.Drawing.Size(292, 266);<BR>&nbsp;&nbsp;&nbsp;this.Controls.Add(this.button1);<BR>&nbsp;&nbsp;&nbsp;this.Name = "Form1";<BR>&nbsp;&nbsp;&nbsp;this.Text = "Form1";<BR>&nbsp;&nbsp;&nbsp;this.ResumeLayout(false);</P>
<P>&nbsp;&nbsp;}<BR>&nbsp;&nbsp;#endregion</P>
<P>&nbsp;&nbsp;/// &lt;summary&gt;<BR>&nbsp;&nbsp;/// 应用程序的主入口点。<BR>&nbsp;&nbsp;/// &lt;/summary&gt;<BR>&nbsp;&nbsp;private DirectX7 directX;<BR>&nbsp;&nbsp;private DirectMusicChordMap chordMap;<BR>&nbsp;&nbsp;private DirectMusicComposer composer;<BR>&nbsp;&nbsp;private DirectMusicPerformance performance;<BR>&nbsp;&nbsp;private DirectMusicSegment segment;<BR>&nbsp;&nbsp;private DirectMusicLoader loader;<BR>&nbsp;&nbsp;private System.Windows.Forms.Button button1;<BR>&nbsp;&nbsp;private DirectMusicStyle style;<BR>&nbsp;&nbsp;[STAThread]<BR>&nbsp;&nbsp;static void Main() <BR>&nbsp;&nbsp;{<BR>&nbsp;&nbsp;&nbsp;Application.Run(new Form1());<BR>&nbsp;&nbsp;}<BR>&nbsp;&nbsp;private void button1_Click(object sender, System.EventArgs e)<BR>&nbsp;&nbsp;{&nbsp;&nbsp;&nbsp;<BR>&nbsp;&nbsp;&nbsp;try<BR>&nbsp;&nbsp;&nbsp;{<BR>&nbsp;&nbsp;&nbsp;&nbsp;style=loader.LoadStyle(@"F:\游戏音乐(mid)\GAME01FM.MID");<BR>&nbsp;&nbsp;&nbsp;&nbsp;segment=composer.ComposeSegmentFromShape(style,64,0,2,false,false,chordMap);<BR>&nbsp;&nbsp;&nbsp;&nbsp;composer.AutoTransition(performance,segment,(int)CONST_DMUS_COMMANDT_TYPES.DMUS_COMMANDT_FILL,(int)CONST_DMUS_COMPOSEF_FLAGS.DMUS_COMPOSEF_IMMEDIATE,chordMap);<BR>&nbsp;&nbsp;&nbsp;}<BR>&nbsp;&nbsp;&nbsp;catch(Exception)<BR>&nbsp;&nbsp;&nbsp;{<BR>&nbsp;&nbsp;&nbsp;&nbsp;MessageBox.Show("不能播放音乐");<BR>&nbsp;&nbsp;&nbsp;}<BR>&nbsp;&nbsp;}<BR>&nbsp;}<BR>}</P>
<P></P>
<P><BR>&nbsp;</P><img src ="http://www.cnitblog.com/ChengKing/aggbug/4004.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cnitblog.com/ChengKing/" target="_blank">ZhengJian</a> 2005-11-06 12:40 <a href="http://www.cnitblog.com/ChengKing/articles/4004.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Control Study -&gt; 模拟鼠标 </title><link>http://www.cnitblog.com/ChengKing/articles/3999.html</link><dc:creator>ZhengJian</dc:creator><author>ZhengJian</author><pubDate>Sun, 06 Nov 2005 04:31:00 GMT</pubDate><guid>http://www.cnitblog.com/ChengKing/articles/3999.html</guid><wfw:comment>http://www.cnitblog.com/ChengKing/comments/3999.html</wfw:comment><comments>http://www.cnitblog.com/ChengKing/articles/3999.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cnitblog.com/ChengKing/comments/commentRss/3999.html</wfw:commentRss><trackback:ping>http://www.cnitblog.com/ChengKing/services/trackbacks/3999.html</trackback:ping><description><![CDATA[<P>using System;<BR>using System.Drawing;<BR>using System.Collections;<BR>using System.ComponentModel;<BR>using System.Windows.Forms;<BR>using System.Data;</P>
<P>namespace 模拟鼠标<BR>{<BR>&nbsp;/// &lt;summary&gt;<BR>&nbsp;/// Form1 的摘要说明。<BR>&nbsp;/// &lt;/summary&gt;<BR>&nbsp;public class Form1 : System.Windows.Forms.Form<BR>&nbsp;{<BR>&nbsp;&nbsp;/// &lt;summary&gt;<BR>&nbsp;&nbsp;/// 必需的设计器变量。<BR>&nbsp;&nbsp;/// &lt;/summary&gt;<BR>&nbsp;&nbsp;private System.ComponentModel.Container components = null;</P>
<P>&nbsp;&nbsp;public Form1()<BR>&nbsp;&nbsp;{<BR>&nbsp;&nbsp;&nbsp;//<BR>&nbsp;&nbsp;&nbsp;// Windows 窗体设计器支持所必需的<BR>&nbsp;&nbsp;&nbsp;//<BR>&nbsp;&nbsp;&nbsp;InitializeComponent();</P>
<P>&nbsp;&nbsp;&nbsp;//<BR>&nbsp;&nbsp;&nbsp;// TODO: 在 InitializeComponent 调用后添加任何构造函数代码<BR>&nbsp;&nbsp;&nbsp;//<BR>&nbsp;&nbsp;}</P>
<P>&nbsp;&nbsp;/// &lt;summary&gt;<BR>&nbsp;&nbsp;/// 清理所有正在使用的资源。<BR>&nbsp;&nbsp;/// &lt;/summary&gt;<BR>&nbsp;&nbsp;protected override void Dispose( bool disposing )<BR>&nbsp;&nbsp;{<BR>&nbsp;&nbsp;&nbsp;if( disposing )<BR>&nbsp;&nbsp;&nbsp;{<BR>&nbsp;&nbsp;&nbsp;&nbsp;if (components != null) <BR>&nbsp;&nbsp;&nbsp;&nbsp;{<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;components.Dispose();<BR>&nbsp;&nbsp;&nbsp;&nbsp;}<BR>&nbsp;&nbsp;&nbsp;}<BR>&nbsp;&nbsp;&nbsp;base.Dispose( disposing );<BR>&nbsp;&nbsp;}</P>
<P>&nbsp;&nbsp;#region Windows 窗体设计器生成的代码<BR>&nbsp;&nbsp;/// &lt;summary&gt;<BR>&nbsp;&nbsp;/// 设计器支持所需的方法 - 不要使用代码编辑器修改<BR>&nbsp;&nbsp;/// 此方法的内容。<BR>&nbsp;&nbsp;/// &lt;/summary&gt;<BR>&nbsp;&nbsp;private void InitializeComponent()<BR>&nbsp;&nbsp;{<BR>&nbsp;&nbsp;&nbsp;this.pictureBox1 = new System.Windows.Forms.PictureBox();<BR>&nbsp;&nbsp;&nbsp;this.label1 = new System.Windows.Forms.Label();<BR>&nbsp;&nbsp;&nbsp;this.SuspendLayout();<BR>&nbsp;&nbsp;&nbsp;// <BR>&nbsp;&nbsp;&nbsp;// pictureBox1<BR>&nbsp;&nbsp;&nbsp;// <BR>&nbsp;&nbsp;&nbsp;this.pictureBox1.BackColor = System.Drawing.SystemColors.ActiveCaption;<BR>&nbsp;&nbsp;&nbsp;this.pictureBox1.Location = new System.Drawing.Point(88, 120);<BR>&nbsp;&nbsp;&nbsp;this.pictureBox1.Name = "pictureBox1";<BR>&nbsp;&nbsp;&nbsp;this.pictureBox1.TabIndex = 0;<BR>&nbsp;&nbsp;&nbsp;this.pictureBox1.TabStop = false;<BR>&nbsp;&nbsp;&nbsp;this.pictureBox1.KeyDown += new System.Windows.Forms.KeyEventHandler(this.pictureBox1_KeyDown);<BR>&nbsp;&nbsp;&nbsp;this.pictureBox1.MouseDown += new System.Windows.Forms.MouseEventHandler(this.pictureBox1_MouseDown);<BR>&nbsp;&nbsp;&nbsp;// <BR>&nbsp;&nbsp;&nbsp;// label1<BR>&nbsp;&nbsp;&nbsp;// <BR>&nbsp;&nbsp;&nbsp;this.label1.BackColor = System.Drawing.Color.DarkOliveGreen;<BR>&nbsp;&nbsp;&nbsp;this.label1.FlatStyle = System.Windows.Forms.FlatStyle.System;<BR>&nbsp;&nbsp;&nbsp;this.label1.Location = new System.Drawing.Point(48, 208);<BR>&nbsp;&nbsp;&nbsp;this.label1.Name = "label1";<BR>&nbsp;&nbsp;&nbsp;this.label1.TabIndex = 1;<BR>&nbsp;&nbsp;&nbsp;this.label1.Text = "label1";<BR>&nbsp;&nbsp;&nbsp;// <BR>&nbsp;&nbsp;&nbsp;// Form1<BR>&nbsp;&nbsp;&nbsp;// <BR>&nbsp;&nbsp;&nbsp;this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);<BR>&nbsp;&nbsp;&nbsp;this.ClientSize = new System.Drawing.Size(292, 266);<BR>&nbsp;&nbsp;&nbsp;this.Controls.Add(this.label1);<BR>&nbsp;&nbsp;&nbsp;this.Controls.Add(this.pictureBox1);<BR>&nbsp;&nbsp;&nbsp;this.Name = "Form1";<BR>&nbsp;&nbsp;&nbsp;this.Text = "Form1";<BR>&nbsp;&nbsp;&nbsp;this.KeyDown += new System.Windows.Forms.KeyEventHandler(this.Form1_KeyDown);<BR>&nbsp;&nbsp;&nbsp;this.Load += new System.EventHandler(this.Form1_Load);<BR>&nbsp;&nbsp;&nbsp;this.KeyUp += new System.Windows.Forms.KeyEventHandler(this.Form1_KeyUp);<BR>&nbsp;&nbsp;&nbsp;this.MouseMove += new System.Windows.Forms.MouseEventHandler(this.Form1_MouseMove);<BR>&nbsp;&nbsp;&nbsp;this.ResumeLayout(false);</P>
<P>&nbsp;&nbsp;}<BR>&nbsp;&nbsp;#endregion</P>
<P>&nbsp;&nbsp;/// &lt;summary&gt;<BR>&nbsp;&nbsp;/// 应用程序的主入口点。<BR>&nbsp;&nbsp;/// &lt;/summary&gt;<BR>&nbsp;&nbsp;[STAThread]<BR>&nbsp;&nbsp;static void Main() <BR>&nbsp;&nbsp;{<BR>&nbsp;&nbsp;&nbsp;Application.Run(new Form1());<BR>&nbsp;&nbsp;}<BR>&nbsp;&nbsp;[System.Runtime.InteropServices.DllImport("user32")]<BR>&nbsp;&nbsp;&nbsp;&nbsp; private static extern int mouse_event(int dwFlags,int dx,int dy,int cButtons,int dwExtraInfo);<BR>&nbsp;&nbsp;const int MOUSEEVENTF_MOVE=0x0001;<BR>&nbsp;&nbsp;const int MOUSEEVENTF_LEFTDOWN=0X0002;<BR>&nbsp;&nbsp;const int MOUSEEVENTF_LEFTUP=0X0004;<BR>&nbsp;&nbsp;const int MOUSEEVENTF_RIGHTDOWN=0X0008;<BR>&nbsp;&nbsp;const int MOUSEEVENTF_RIGHTUP=0X0010;<BR>&nbsp;&nbsp;const int MOUSEEVENTF_MIDDLEDOWN=0X0020;<BR>&nbsp;&nbsp;const int MOUSEEVENTF_MIDDLEUP=0X0040;<BR>&nbsp;&nbsp;private System.Windows.Forms.PictureBox pictureBox1;<BR>&nbsp;&nbsp;private System.Windows.Forms.Label label1;<BR>&nbsp;&nbsp;const int MOUSEEVENTF_ABSOLUTE=0X8000;</P>
<P>&nbsp;&nbsp;private void Form1_MouseMove(object sender, System.Windows.Forms.MouseEventArgs e)<BR>&nbsp;&nbsp;{<BR>&nbsp;&nbsp;&nbsp;//mouse_event(MOUSEEVENTF_MOVE,-10,-10,0,0);<BR>&nbsp;&nbsp;}</P>
<P>&nbsp;&nbsp;private void Form1_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e)<BR>&nbsp;&nbsp;{<BR>&nbsp;&nbsp;&nbsp;if(e.KeyCode==Keys.Down)<BR>&nbsp;&nbsp;&nbsp;&nbsp;mouse_event(MOUSEEVENTF_MOVE,0,20,0,0);<BR>&nbsp;&nbsp;&nbsp;if(e.KeyCode==Keys.Up)<BR>&nbsp;&nbsp;&nbsp;&nbsp;mouse_event(MOUSEEVENTF_MOVE,0,-20,0,0);<BR>&nbsp;&nbsp;&nbsp;if(e.KeyCode==Keys.Left)<BR>&nbsp;&nbsp;&nbsp;&nbsp;mouse_event(MOUSEEVENTF_MOVE,-20,0,0,0);<BR>&nbsp;&nbsp;&nbsp;if(e.KeyCode==Keys.Right)<BR>&nbsp;&nbsp;&nbsp;&nbsp;mouse_event(MOUSEEVENTF_MOVE,20,0,0,0);<BR>&nbsp;&nbsp;}</P>
<P>&nbsp;&nbsp;public void pictureBox1_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e)<BR>&nbsp;&nbsp;{<BR>&nbsp;&nbsp;&nbsp;/*if(e.KeyCode==Keys.Down)<BR>&nbsp;&nbsp;&nbsp;&nbsp;mouse_event(MOUSEEVENTF_MOVE,0,20,0,0);<BR>&nbsp;&nbsp;&nbsp;if(e.KeyCode==Keys.Up)<BR>&nbsp;&nbsp;&nbsp;&nbsp;mouse_event(MOUSEEVENTF_MOVE,0,-20,0,0);<BR>&nbsp;&nbsp;&nbsp;if(e.KeyCode==Keys.Left)<BR>&nbsp;&nbsp;&nbsp;&nbsp;mouse_event(MOUSEEVENTF_MOVE,-20,0,0,0);<BR>&nbsp;&nbsp;&nbsp;if(e.KeyCode==Keys.Right)<BR>&nbsp;&nbsp;&nbsp;&nbsp;mouse_event(MOUSEEVENTF_MOVE,20,0,0,0);<BR>&nbsp;&nbsp;&nbsp;&nbsp;*/<BR>&nbsp;&nbsp;}<BR>&nbsp;&nbsp;private void Form1_KeyUp(object sender, System.Windows.Forms.KeyEventArgs e)<BR>&nbsp;&nbsp;{<BR>&nbsp;&nbsp;<BR>&nbsp;&nbsp;}</P>
<P>&nbsp;&nbsp;</P>
<P>&nbsp;&nbsp;private void pictureBox1_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e)<BR>&nbsp;&nbsp;{<BR>&nbsp;&nbsp;&nbsp;if(e.Button==MouseButtons.Right)<BR>&nbsp;&nbsp;&nbsp;&nbsp;mouse_event(MOUSEEVENTF_MOVE,0,20,0,0);<BR>&nbsp;&nbsp;&nbsp;else<BR>&nbsp;&nbsp;&nbsp;&nbsp;mouse_event(MOUSEEVENTF_MOVE,0,-20,0,0);<BR>&nbsp;&nbsp;}</P>
<P>&nbsp;&nbsp;private void Form1_Load(object sender, System.EventArgs e)<BR>&nbsp;&nbsp;{<BR>&nbsp;&nbsp;&nbsp;<BR>&nbsp;&nbsp;}</P>
<P><BR>&nbsp;&nbsp;<BR>&nbsp;<BR>&nbsp;}<BR>}<BR></P><img src ="http://www.cnitblog.com/ChengKing/aggbug/3999.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cnitblog.com/ChengKing/" target="_blank">ZhengJian</a> 2005-11-06 12:31 <a href="http://www.cnitblog.com/ChengKing/articles/3999.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Control Study -&gt; 用获取路径方法得到圆形窗体(如将: PictureBox变成圆形)</title><link>http://www.cnitblog.com/ChengKing/articles/3998.html</link><dc:creator>ZhengJian</dc:creator><author>ZhengJian</author><pubDate>Sun, 06 Nov 2005 04:30:00 GMT</pubDate><guid>http://www.cnitblog.com/ChengKing/articles/3998.html</guid><wfw:comment>http://www.cnitblog.com/ChengKing/comments/3998.html</wfw:comment><comments>http://www.cnitblog.com/ChengKing/articles/3998.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cnitblog.com/ChengKing/comments/commentRss/3998.html</wfw:commentRss><trackback:ping>http://www.cnitblog.com/ChengKing/services/trackbacks/3998.html</trackback:ping><description><![CDATA[<P>(一).功能</P>
<P>     有时候由于显示效果,需要将某个控件变一下形状.<BR>     本文举例将PictureBox[]数组变成圆形.</P>
<P>(二).代码</P>
<P>    (这里说明一下,我个人将它变形是因为我用PictureBox表示象棋棋子,</P>
<P>     由于PictureBox默认是方 的,  所以得把它变成圆的)</P>
<P>     大家可以将这个功能作为其它用途使用.</P>
<P>using System;<BR>using System.Drawing;<BR>using System.Collections;<BR>using System.ComponentModel;<BR>using System.Windows.Forms;<BR>using System.Data;</P>
<P><BR>namespace 智能象棋游戏<BR>{<BR> /// <summary><BR> /// 功能:将所有picturebox控件变为圆形<BR> /// 特点:使旗子变圆形</P>
<P> /// </summary></P>
<P> public class Class7<BR> {<BR>  [System.Runtime.InteropServices.DllImport("gdi32")]<BR>  private static extern IntPtr BeginPath(IntPtr hdc);<BR>  [System.Runtime.InteropServices.DllImport("gdi32")]<BR>  private static extern int SetBkMode(IntPtr hdc,int nBkMode);  <BR>  const int TRANSPARENT=1;<BR>  [System.Runtime.InteropServices.DllImport("gdi32")]     <BR>  private static extern IntPtr EndPath(IntPtr hdc);<BR>  [System.Runtime.InteropServices.DllImport("gdi32")]<BR>  private static extern IntPtr PathToRegion(IntPtr hdc);<BR>  [System.Runtime.InteropServices.DllImport("gdi32")]<BR>  private static extern int Ellipse(IntPtr hdc,int x1,int y1,int x2,int y2);<BR>  [System.Runtime.InteropServices.DllImport("user32")]<BR>  private static extern IntPtr SetWindowRgn(IntPtr hwnd,IntPtr hRgn,bool bRedraw);<BR>  [System.Runtime.InteropServices.DllImport("user32")]<BR>  private static extern IntPtr GetDC(IntPtr hwnd);<BR>  public Class7()<BR>  {   <BR>  }<BR>  public void MakeToPictureBoxsToCircle(PictureBox[] pb)<BR>  {<BR>   IntPtr dc;<BR>   IntPtr region;<BR>   for(int i=0;i<pb.Length;i++)<BR>   {<BR>    dc=GetDC(pb[i].Handle);<BR>    BeginPath(dc);<BR>    SetBkMode(dc,TRANSPARENT);<BR>    Ellipse(dc,0,0,pb[i].Width-3,pb[i].Height-2);<BR>    EndPath(dc);<BR>    region=PathToRegion(dc);<BR>    SetWindowRgn(pb[i].Handle,region,false);<BR>   }   <BR>  }<BR> }<BR>}</P>
<P></P>
<P><BR></P><img src ="http://www.cnitblog.com/ChengKing/aggbug/3998.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cnitblog.com/ChengKing/" target="_blank">ZhengJian</a> 2005-11-06 12:30 <a href="http://www.cnitblog.com/ChengKing/articles/3998.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>播放音乐</title><link>http://www.cnitblog.com/ChengKing/articles/3988.html</link><dc:creator>ZhengJian</dc:creator><author>ZhengJian</author><pubDate>Sun, 06 Nov 2005 04:20:00 GMT</pubDate><guid>http://www.cnitblog.com/ChengKing/articles/3988.html</guid><wfw:comment>http://www.cnitblog.com/ChengKing/comments/3988.html</wfw:comment><comments>http://www.cnitblog.com/ChengKing/articles/3988.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cnitblog.com/ChengKing/comments/commentRss/3988.html</wfw:commentRss><trackback:ping>http://www.cnitblog.com/ChengKing/services/trackbacks/3988.html</trackback:ping><description><![CDATA[<P>(一). 说明</P>
<P>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 一个播放音乐的类,直接COPY就可以用了.<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 可用于自己编写的游戏等一些需要播放音乐的地方. 只要给它正在的文件名<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 就OK了.&nbsp;&nbsp; 具体看下面代码.</P>
<P>(二).步骤&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </P>
<P>using System;<BR>//using System.Drawing;<BR>using System.Collections;<BR>using System.ComponentModel;<BR>//using System.Windows.Forms;<BR>//using System.Data;<BR>using System.Runtime.InteropServices;</P>
<P align=left>namespace 智能象棋游戏<BR>{<BR>&nbsp;/// &lt;summary&gt;<BR>&nbsp;/// 用于播放音乐<BR>&nbsp;/// &lt;/summary&gt;&nbsp;<BR>&nbsp;internal class Helpers <BR>&nbsp;{<BR>&nbsp;&nbsp; &nbsp;&nbsp;[Flags]<BR>&nbsp;&nbsp; &nbsp;&nbsp;public enum PlaySoundFlags : int <BR>&nbsp;&nbsp; &nbsp;&nbsp;{<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;SND_SYNC = 0x0000,&nbsp; /* play synchronously (default) */ //同步<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;SND_ASYNC = 0x0001,&nbsp; /* play asynchronously */ //异步<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;SND_NODEFAULT = 0x0002,&nbsp; /* silence (!default) if sound not found */<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; &nbsp;&nbsp;SND_MEMORY = 0x0004,&nbsp; /* pszSound points to a memory file */<BR>&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;SND_LOOP = 0x0008,&nbsp; /* loop the sound until next sndPlaySound */<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp; &nbsp;SND_NOSTOP = 0x0010,&nbsp; /* don't stop any currently playing sound */<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp; &nbsp;SND_NOWAIT = 0x00002000, /* don't wait if the driver is busy */<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; SND_ALIAS = 0x00010000, /* name is a registry alias */<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;SND_ALIAS_ID = 0x00110000, /* alias is a predefined ID */<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;SND_FILENAME = 0x00020000, /* name is file name */<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; &nbsp;&nbsp;SND_RESOURCE = 0x00040004&nbsp; /* name is resource name or atom */<BR>&nbsp;&nbsp;&nbsp;}</P>
<P>&nbsp;&nbsp;&nbsp;[DllImport("winmm")]<BR>&nbsp;&nbsp; public static extern bool PlaySound( string szSound, IntPtr hMod, PlaySoundFlags flags );<BR>}</P>
<P>&nbsp;public class Sound <BR>&nbsp;{<BR>&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;public static void Play( string strFileName )<BR>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;{<BR>&nbsp;&nbsp;&nbsp;//Helpers.PlaySound( strFileName, IntPtr.Zero, Helpers.PlaySoundFlags.SND_FILENAME |&nbsp;&nbsp;&nbsp; Helpers.PlaySoundFlags.SND_ASYNC );<BR>&nbsp;&nbsp;&nbsp;&nbsp; switch(strFileName)<BR>&nbsp;&nbsp;&nbsp;&nbsp; {<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; case "start": <A href='mailto:strFileName=@"..\..\sound\start.WAV'>strFileName=@"..\..\sound\start.WAV</A>";&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; break;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;case "back": <A href='mailto:strFileName=@"..\..\sound\back.WAV'>strFileName=@"..\..\sound\back.WAV</A>";&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; break;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;case "fall": <A href='mailto:strFileName=@"..\..\sound\fall.WAV'>strFileName=@"..\..\sound\fall.WAV</A>";&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; break;&nbsp;&nbsp;&nbsp;&nbsp;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;case "huiqi": <A href='mailto:strFileName=@"..\..\sound\huiqi.WAV'>strFileName=@"..\..\sound\huiqi.WAV</A>";&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; break;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; case "huiqiend": <A href='mailto:strFileName=@"..\..\sound\huiqiend.WAV'>strFileName=@"..\..\sound\huiqiend.WAV</A>"; break;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;case "jiangjun": <A href='mailto:strFileName=@"..\..\sound\jiangjun.WAV'>strFileName=@"..\..\sound\jiangjun.WAV</A>"; break;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;case "kill": <A href='mailto:strFileName=@"..\..\sound\kill.WAV'>strFileName=@"..\..\sound\kill.WAV</A>";&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; break;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; case "win": <A href='mailto:strFileName=@"..\..\sound\win.WAV'>strFileName=@"..\..\sound\win.WAV</A>";&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; break;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;case "move": <A href='mailto:strFileName=@"..\..\sound\move.WAV'>strFileName=@"..\..\sound\move.WAV</A>";&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; break;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp; case "hold": <A href='mailto:strFileName=@"..\..\sound\hold.WAV'>strFileName=@"..\..\sound\hold.WAV</A>";&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; break;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;case "no": <A href='mailto:strFileName=@"..\..\sound\no.WAV'>strFileName=@"..\..\sound\no.WAV</A>";&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; break;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;case "popup": <A href='mailto:strFileName=@"..\..\sound\popup.WAV'>strFileName=@"..\..\sound\popup.WAV</A>";&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; break;<BR>&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; case "mayfall": <A href='mailto:strFileName=@"..\..\sound\mayfall.WAV'>strFileName=@"..\..\sound\mayfall.WAV</A>";&nbsp;&nbsp; break;<BR>&nbsp;&nbsp;&nbsp; }<BR>&nbsp;&nbsp;&nbsp;Helpers.PlaySound(strFileName, IntPtr.Zero, Helpers.PlaySoundFlags.SND_FILENAME | Helpers.PlaySoundFlags.SND_ASYNC);&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //调用Dll方法,播放音乐<BR>&nbsp;&nbsp; &nbsp;}<BR>&nbsp; }&nbsp;&nbsp;<BR>}</P>
<P>(三).使用</P>
<P>&nbsp;&nbsp;&nbsp; 1.添加组件 (Interop.WMPLib) . &nbsp;这个类库 VS.Net自带的,默认没有添加进来.</P>
<P>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 方法:&nbsp; 展开项目文件夹,右击引用,添加引用,到Com组件栏,找到添加到项目中.</P>
<P>&nbsp;&nbsp;&nbsp; 2.新建一个*.cs文件,把这些代码拷贝进去,全部覆盖即可,并修改上例子中的播放文件名.</P>
<P>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;就是这样的语句:&nbsp; <A href='mailto:strFileName=@"..\..\sound\mayfall.WAV'>strFileName=@"..\..\sound\mayfall.WAV</A>";&nbsp;&nbsp;&nbsp;&nbsp; //一定要存在这个音乐文件,否则不能播放</P>
<P>&nbsp;&nbsp;&nbsp; 3.如果调用这个方法的地方与此类不在同一个命名空间. 要在用的地方打开类的命名空间.</P>
<P>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 方法:&nbsp; 如这个示例类的命名空间应该这样写:&nbsp;&nbsp;&nbsp; using 智能象棋游戏;</P>
<P>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 最后就可以用了,用法极简单,直接调用此类的方法:&nbsp;&nbsp; </P>
<P>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Sound.Play("move");&nbsp;&nbsp; //其中参数自定义. 跟方法底层无关. 看一上类里面的swith语句就明白了.</P>
<P></P>
<P>&nbsp;</P>
<P>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <BR></P>
<P>&nbsp;&nbsp;&nbsp;<BR>&nbsp;&nbsp;&nbsp;</P><img src ="http://www.cnitblog.com/ChengKing/aggbug/3988.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cnitblog.com/ChengKing/" target="_blank">ZhengJian</a> 2005-11-06 12:20 <a href="http://www.cnitblog.com/ChengKing/articles/3988.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>