我在一个项目里添加了两个类,两个类有一些关联,其中一个类包含有另一个类定义的东西,请问在主程序中调用时该怎么写呢?
两个类分别为:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Runtime.InteropServices;
namespace luyin1
{
/// <summary>
/// Class3 的摘要说明。
/// </summary>
public class APIClass
{
[DllImport("kernel32.dll",CharSet = CharSet.Auto)]
public static extern int GetShortPathName(
string IpszLongPath,
string shortFile,
int cchBuffer
);
[DllImport("winmm.dll",EntryPoint = "mciSendString",CharSet = CharSet.Auto)]
public static extern int mciSendString(
string IpstrCommand,
string IpstrReturnString,
int uReturnLength,
int hwndCallback
);
}
}
和
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Runtime.InteropServices;
namespace luyin1
{
/// <summary>
/// Class3 的摘要说明。
/// </summary>
public class MCIClass
{
//
// TODO: 在此处添加构造函数逻辑
//
[MarshalAs(UnmangedType.ByValTStr,SizeConst = 260)]
private string Name = " ";
[MarshalAs(UnmangedType.ByValTStr,SizeConst = 128)]
private string durLenght = " ";
[MarshalAs(UnmangedType.LPTStr,SizeConst = 128)]
private string TemStr = " ";
int ilong;
public enum State
{
mPlaying = 1,
mPuase = 2,
mStop = 3
}
public struct structMCI
{
public bool bMut;
public int iDur;
public int iPos;
public int iVol;
public int iBal;
public string iName;
public State state;
}
public structMCI mc = new structMCI();
public string FileName
{
get
{
return mc.iName;
}
set
{
try
{
TemStr = " ";
TmeStr = TemStr.PadLeft(127,Convert.ToChar(" "));
Name = Name.PadLeft(260,Convert.ToChar(" "));
mc.iName = value;
ilong = APIClass.GetShortPathName(mc.iName,Name, Name.Lenght);
Name = GetCurrPath(Name);
Name = "open " + Convert.ToChar(34) + Name + Convert.ToChar(34) + "alias media" ;
ilong = APIClass.mciSendString("close all ", TemStr,TemStr.Length,0);
ilong = APIClass.mciSendString( Name, TemStr,TemStr.Lenght,0);
ilong = APIClass.mciSendString("set media time format milliseconds",TemStr,TemStr.Length,0);
mc.state = State.mStop;
}
catch
{
MessageBox.Show("错误!");
}
}
}
public void Play()
{
TemStr = " ";
TemStr = TemStr.PadLeft(127,Convert.ToChar(" "));
APIClass.mciSendString("play media",TemStr,TemStr.Lenght,0);
mc.state = State.mPlaying;
}
public void Stop()
{
TemStr = " ";
TemStr = TemStr.PadLeft(128,Convert.ToChar(" "));
ilong = APIClass.mciSendString("close media",TemStr,128,0);
ilong = APIClass.mciSendString("close all",TemStr,128,0);
mc.state = State.mStop;
}
}
}
[此贴子已经被作者于2006-8-9 18:27:07编辑过]