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());
        }
}

 

arrow
arrow
    全站熱搜

    Frank 發表在 痞客邦 留言(0) 人氣()