using System; using System.Collections.Generic; using System.Drawing; using System.Linq; using System.Runtime.InteropServices; using System.Text; namespace ryControls.Pram { /// /// /// public class NativeMethods { internal const int WS_EX_CLIENTEDGE = 512 /*0x0200*/; internal const int WS_EX_WINDOWEDGE = 0x0100; internal const int WM_PAINT = 15; // 0x000f internal const int WM_NCPAINT = 133; // 0x0085 internal const int RGN_COPY = 5; internal const int RGN_AND = 1; /// /// /// [StructLayout(LayoutKind.Sequential)] public struct RECT { /// /// /// public int left; /// /// /// public int top; /// /// /// public int right; /// /// /// public int bottom; /// /// /// /// public RECT(Rectangle rect) { this.bottom = rect.Bottom; this.left = rect.Left; this.right = rect.Right; this.top = rect.Top; } /// /// /// /// /// /// /// public RECT(int left, int top, int right, int bottom) { this.bottom = bottom; this.left = left; this.right = right; this.top = top; } /// /// /// /// /// /// /// /// public static RECT FromXYWH(int x, int y, int width, int height) { return new RECT(x, y, x + width, y + height); } /// /// /// public int Width { get { return this.right - this.left; } } /// /// /// public int Height { get { return this.bottom - this.top; } } /// /// /// /// public override /*Object*/ string ToString() { return String.Concat( "Left = ", this.left, " Top ", this.top, " Right = ", this.right, " Bottom = ", this.bottom); } /// /// /// /// public static implicit operator Rectangle(RECT rect) { return Rectangle.FromLTRB(rect.left, rect.top, rect.right, rect.bottom); } } [DllImport("user32.dll")] internal static extern bool GetWindowRect(IntPtr hwnd, ref RECT lpRect); [DllImport("gdi32.dll", CharSet = CharSet.Auto, ExactSpelling = true, CallingConvention = CallingConvention.Winapi)] internal static extern IntPtr CreateRectRgn(int x1, int y1, int x2, int y2); [DllImport("user32.dll", CharSet = CharSet.Auto, ExactSpelling = true, CallingConvention = CallingConvention.Winapi)] internal static extern IntPtr GetWindowDC(IntPtr hWnd); [DllImport("gdi32.dll", CharSet = CharSet.Auto, ExactSpelling = true, CallingConvention = CallingConvention.Winapi)] internal static extern IntPtr CreateCompatibleDC(IntPtr hDC); [DllImport("gdi32.dll", CharSet = CharSet.Auto, ExactSpelling = true, CallingConvention = CallingConvention.Winapi)] internal static extern IntPtr CreateCompatibleBitmap(IntPtr hDC, int width, int height); [DllImport("gdi32", CharSet = CharSet.Auto, ExactSpelling = true)] internal static extern IntPtr SelectObject(IntPtr hdc, IntPtr hObject); [DllImport("gdi32.dll", CharSet = CharSet.Auto, ExactSpelling = true, CallingConvention = CallingConvention.Winapi)] internal static extern int CombineRgn(IntPtr hRgn, IntPtr hRgn1, IntPtr hRgn2, int nCombineMode); /// /// /// /// /// /// /// [DllImport("gdi32.dll", CharSet = CharSet.Auto, ExactSpelling = true, CallingConvention = CallingConvention.Winapi)] public static extern int OffsetRgn(IntPtr hrgn, int nXOffset, int nYOffset); [DllImport("gdi32")] internal static extern bool DeleteObject(IntPtr hObject); [DllImport("gdi32.dll", CharSet = CharSet.Auto, ExactSpelling = true, CallingConvention = CallingConvention.Winapi)] internal static extern int SelectClipRgn(IntPtr hDC, IntPtr hRgn); /// /// /// /// /// /// /// /// /// [DllImport("gdi32.dll", CharSet = CharSet.Auto, ExactSpelling = true, CallingConvention = CallingConvention.Winapi)] public static extern int ExcludeClipRect(IntPtr hdc, int nLeft, int nTop, int nRight, int nBottom); [DllImport("gdi32.dll")] internal static extern bool BitBlt(IntPtr hdcDest, int nXDest, int nYDest, int nWidth, int nHeight, IntPtr hdcSrc, int nXSrc, int nYSrc, Int32 dwRop); [DllImport("gdi32", EntryPoint = "DeleteDC", CharSet = CharSet.Auto, ExactSpelling = true)] internal static extern bool DeleteDC(IntPtr hDC); } /// /// /// public class Pram { /// /// 计算两个日期的时间间隔,返回的是日期值+ /// /// 时间值,将显示在返回的值里 /// 参照时间 /// public static string DateDiff(DateTime date1, DateTime referTime) { string dateDiff = ""; TimeSpan ts1 = new TimeSpan(date1.Ticks); TimeSpan ts2 = new TimeSpan(referTime.Ticks); TimeSpan ts = ts1.Subtract(ts2).Duration(); //显示时间 if (ts.Days != 0) { int day = ts.Days; if (day == 1) { dateDiff = "昨天 "+ date1.ToString("HH:mm:ss"); } else if (day == 2) { dateDiff = "前天 " + date1.ToString("HH:mm:ss"); }; } else { if (ts.Hours != 0) { dateDiff += ts.Hours.ToString() + "小时"; } if (ts.Minutes != 0 || dateDiff == "") { dateDiff += ts.Minutes.ToString() + "分钟"; } if (dateDiff != "") { dateDiff += "前"; } } if (dateDiff == "") { dateDiff = date1.ToString("yyyy-MM-dd HH:mm:ss"); } return dateDiff; } } }