using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Windows.Forms; using System.Drawing; namespace Yaulw.Win32 { /// /// Helper class to Convert Win32 Structures to DotNet and vice versa /// public static class Convert { /// /// Use this to Convert to Win32 Window Message Enum from a C# Message /// /// a C# Message /// a Win32 Message Enum public static Definitions.WM MessageToWin32WM(Message m) { Definitions.WM wm = Definitions.WM.WM_NULL; try { wm = (Definitions.WM)m.Msg; } catch (Exception) { wm = Definitions.WM.WM_NULL; } return wm; } /// /// Use this to Convert to a C# Rectangle from a Win32 RECT /// /// a Win32 Rect /// a C# Rectancle public static Rectangle RECTToRectangle(Structures.RECT rect) { return new Rectangle(rect.left, rect.top, rect.right - rect.left, rect.bottom - rect.top); } /// /// Use this to Convert a Win32 RECT to a C# Rectangle /// /// a C# Rectangle /// a Win32 Rect public static Structures.RECT RectangleToRECT(Rectangle rect) { return Structures.RECT.FromXYWH(rect.Left, rect.Top, rect.Width, rect.Height); } #region Win32Owner /// /// a IWin32Window Object commonly used by WinForms /// public class Win32Owner : IWin32Window { public IntPtr Handle { get; set; } } /// /// Convert a Handle to a Win32Owner Object /// /// pass in a Window Handle /// a newly created Win32Owner Object public static IWin32Window ConverthWndToIWin32Window(IntPtr hWnd) { return new Win32Owner() { Handle = hWnd }; } #endregion } }