using System.Runtime.InteropServices; //使用DllImport
public partial class Form1 : Form
{ [DllImport("kernel32.dll")] static extern void GetSystemTime(out SYSTEMTIME lpSystemTime);
private struct SYSTEMTIME
{ public ushort wYear;
public ushort wMonth;
public ushort wDayOfWeek;
public ushort wDay;
public ushort wHour;
public ushort wMinute;
public ushort wSecond;
public ushort wMilliseconds;
}
private void GetTime()
{ // Call the native GetSystemTime method
// with the defined structure.
SYSTEMTIME stime = new SYSTEMTIME();
GetSystemTime(out stime);
// Show the current time.
MessageBox.Show("Current Time: " + stime.wHour.ToString() + ":"
+ stime.wMinute.ToString());
}
}
請先 登入 以發表留言。