using System; using System.Drawing; using System.Runtime.InteropServices; using System.Text; using System.Windows.Forms; namespace JWH { public static class ExtensionAPI { /// /// 네트워크 리소스 /// [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)] public struct NETRESOURCE { public uint dwScope; public uint dwType; public uint dwDisplayType; public uint dwUsage; public string lpLocalName; public string lpRemoteName; public string lpComment; public string lpProvider; } /// /// Set Tab stops to a width of 4 /// private const int EM_SETTABSTOPS = 0x00CB; /// /// 네트워크 드라이브 연결 /// /// /// /// /// /// /// /// /// /// [DllImport("mpr.dll", CharSet = CharSet.Auto)] public static extern int WNetUseConnection( IntPtr hwndOwner, [MarshalAs(UnmanagedType.Struct)] ref NETRESOURCE lpNetResource, string lpPassword, string lpUserID, uint dwFlags, StringBuilder lpAccessName, ref int lpBufferSize, out uint lpResult); /// /// 네트워크 드라이브 해제 /// /// /// /// /// [DllImport("mpr.dll", EntryPoint = "WNetCancelConnection2", CharSet = CharSet.Auto)] public static extern int WNetCancelConnection2A(string lpName, int dwFlags, int fForce); /// /// 네트워크 드라이브 연결 /// /// /// /// /// public static int ConnectRemoteServer(string server, string uid, string pwd) { int capacity = 64; uint resultFlags = 0; uint flags = 0; System.Text.StringBuilder sb = new System.Text.StringBuilder(capacity); NETRESOURCE ns = new NETRESOURCE(); ns.dwType = 1; // 공유 디스크 ns.lpLocalName = null; // 로컬 드라이브 지정하지 않음 ns.lpRemoteName = $@"\\{server}"; ns.lpProvider = null; int result = 0; result = WNetUseConnection(IntPtr.Zero, ref ns, pwd, uid, flags, sb, ref capacity, out resultFlags); return result; } /// /// 네트워크 드라이브 해제 /// /// /// public static int CencelRemoteServer(string server) { string lpRemoteName = $@"\\{server}"; int result = 0; result = WNetCancelConnection2A(lpRemoteName, 1, 0); return result; } /// /// SendMessage /// /// /// /// /// /// [DllImport("User32.dll", CharSet = CharSet.Auto)] public static extern IntPtr SendMessage(IntPtr h, int msg, int wParam, int[] lParam); /// /// 텍스트박스의 탭 간격을 설정합니다. /// /// /// 탭간격 public static void SetTabWidth(this TextBox sender, params int[] tabWidths) { Graphics graphics = sender.CreateGraphics(); int characterWidth = 4; //characterWidth = (int)graphics.MeasureString("A", sender.Font).Width; int[] lParams = new int[tabWidths.Length]; for(int i=0; i< tabWidths.Length; i++) { lParams[i] = tabWidths[i] * characterWidth; if (i > 0) lParams[i] += lParams[i - 1]; } IntPtr ptr = SendMessage(sender.Handle, EM_SETTABSTOPS, lParams.Length, lParams); } } }