using Autodesk.Revit.DB; using Autodesk.Revit.UI; using System; using System.Collections.Generic; using System.Diagnostics; using System.Drawing; using System.Linq; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; using System.Text; using System.Windows.Forms; using Color = System.Drawing.Color; using Rectangle = System.Drawing.Rectangle; using View = Autodesk.Revit.DB.View; namespace HYJig { public class WndMsgManager : IDisposable { public WndMsgManager(UIDocument uiDoc) { this.m_uiDoc = uiDoc; this.method_4(); this.method_6(true); this.method_0(true); this.method_1(); this.SetFocus2MDIActiveChildClient(); } public void Dispose() { this.method_6(false); this.method_0(false); } private void method_0(bool bool_1) { if (!bool_1) { if (WndMsgManager.jigTransparentForm_0 == null || WndMsgManager.jigTransparentForm_0.IsDisposed) { return; } this.JigPen.Dispose(); using (Graphics graphics = WndMsgManager.jigTransparentForm_0.CreateGraphics()) { graphics.Clear(WndMsgManager.jigTransparentForm_0.BackColor); return; } } Process currentProcess = Process.GetCurrentProcess(); WindowHandle windowHandle = new WindowHandle(currentProcess.MainWindowHandle); if (WndMsgManager.jigTransparentForm_0 == null) { WndMsgManager.jigTransparentForm_0 = new JigTransparentForm(); WndMsgManager.jigTransparentForm_0.Show(windowHandle); } this.JigPen = new Pen(this.RevitViewBackgroundReverseColor); } private void method_1() { Class1.Struct1 @struct; Class1.GetWindowRect(this.m_hMDIClientWnd, out @struct); Point point = new Point(@struct.int_0, @struct.WuApKkPsaL); Class1.Struct1 struct2; Class1.GetWindowRect(this.m_hMDIActiveChildClientWnd, out struct2); Point point2 = new Point(struct2.int_0, struct2.WuApKkPsaL); int num = Math.Max(@struct.int_0, struct2.int_0); int num2 = Math.Max(@struct.WuApKkPsaL, struct2.WuApKkPsaL); int num3 = Math.Min(@struct.int_1, struct2.int_1); int num4 = Math.Min(@struct.int_2, struct2.int_2); WndMsgManager.jigTransparentForm_0.Location = new Point(num, num2); Size size = new Size(num3 - num, num4 - num2); WndMsgManager.jigTransparentForm_0.Size = size; } private void method_2(IntPtr intptr_2, IntPtr intptr_3) { if (this.mouseEventHandler_0 != null) { Point position = Cursor.Position; Class1.ScreenToClient(WndMsgManager.jigTransparentForm_0.Handle, ref position); MouseEventArgs mouseEventArgs = new MouseEventArgs(MouseButtons.None, 0, position.X, position.Y, 0); this.mouseEventHandler_0(this, mouseEventArgs); } } private void method_3(IntPtr intptr_2, IntPtr intptr_3) { if (this.OnPaintEvent != null) { Graphics graphics = WndMsgManager.jigTransparentForm_0.CreateGraphics(); graphics.Clear(this.JigForm.BackColor); try { Rectangle rectangle = new Rectangle(0, 0, WndMsgManager.jigTransparentForm_0.Width, WndMsgManager.jigTransparentForm_0.Height); PaintEventArgs paintEventArgs = new PaintEventArgs(graphics, rectangle); this.OnPaintEvent(this, paintEventArgs); } catch { } finally { graphics.Dispose(); } } } private bool method_4() { IntPtr mainWindowHandle = Process.GetCurrentProcess().MainWindowHandle; int num = Convert.ToInt32(this.m_uiDoc.Application.Application.VersionNumber); if (num < 2019) { this.m_hMDIClientWnd = Class1.FindWindowEx(mainWindowHandle, IntPtr.Zero, "MDIClient", string.Empty); } else { this.m_hMDIClientWnd = mainWindowHandle; } bool flag; if (this.m_hMDIClientWnd == IntPtr.Zero) { flag = false; } else { this.m_hMDIActiveChildWnd = (IntPtr)Class1.SendMessage(this.m_hMDIClientWnd, 553, IntPtr.Zero, IntPtr.Zero); if (this.m_hMDIActiveChildWnd == IntPtr.Zero) { flag = false; } else { IntPtr intPtr = IntPtr.Zero; try { intPtr = Marshal.StringToHGlobalAnsi("AfxFrameOrView"); Class1.EnumChildWindows(this.m_hMDIActiveChildWnd, new Class1.Delegate0(this.method_5), intPtr); } catch { return false; } finally { Marshal.FreeHGlobal(intPtr); } flag = true; } } return flag; } private bool method_5(IntPtr intptr_2, IntPtr intptr_3) { try { string text = Marshal.PtrToStringAnsi(intptr_3); StringBuilder stringBuilder = new StringBuilder(512); Class1.GetClassName(intptr_2, stringBuilder, stringBuilder.Capacity); if (stringBuilder.ToString().Contains(text)) { this.m_hMDIActiveChildClientWnd = intptr_2; return false; } } catch { } return true; } private bool method_6(bool bool_1) { if (bool_1) { this.intptr_0 = Class1.SetWindowLong_1(this.m_hMDIClientWnd, -4, method_7); this.intptr_1 = Class1.SetWindowLong_1(this.m_hMDIActiveChildClientWnd, -4, KknpwAaawt); } else { if (this.delegate1_0 != null) { Class1.SetWindowLong(this.m_hMDIClientWnd, -4, this.intptr_0); this.delegate1_0 = null; } if (this.delegate1_1 != null) { Class1.SetWindowLong(this.m_hMDIActiveChildClientWnd, -4, this.intptr_1); this.delegate1_1 = null; } } return true; } private IntPtr method_7(IntPtr intptr_2, int int_0, IntPtr intptr_3, IntPtr intptr_4) { IntPtr intPtr = Class1.CallWindowProc(this.intptr_0, intptr_2, int_0, intptr_3, intptr_4); if (int_0 != 32) { if (int_0 - 70 <= 1 || int_0 == 546) { this.method_1(); } } else { short num = JigFuncs.HIWORD((int)intptr_4); if (num == 512 && (this.m_UserForm != null && !this.m_UserForm.IsDisposed)) { Rectangle rectangle = new Rectangle(this.m_UserForm.Location, this.m_UserForm.Size); if (!rectangle.Contains(Cursor.Position)) { if (!this.bool_0 && this.OnMouseLeaveFormClientEvent != null) { EventArgs eventArgs = new EventArgs(); this.OnMouseLeaveFormClientEvent(this, eventArgs); Class1.SetCapture(this.m_hMDIActiveChildClientWnd); Class1.SetFocus(this.m_hMDIActiveChildClientWnd); } this.bool_0 = true; } } } return intPtr; } private IntPtr KknpwAaawt(IntPtr intptr_2, int int_0, IntPtr intptr_3, IntPtr intptr_4) { IntPtr intPtr = Class1.CallWindowProc(this.intptr_1, intptr_2, int_0, intptr_3, intptr_4); if (int_0 <= 15) { switch (int_0) { case 5: break; case 6: return intPtr; case 7: if (this.OnFocusEvent != null) { this.OnFocusEvent(this, true); return intPtr; } return intPtr; case 8: if (this.OnFocusEvent != null) { this.OnFocusEvent(this, false); return intPtr; } return intPtr; default: if (int_0 != 15) { return intPtr; } this.method_3(intptr_3, intptr_4); return intPtr; } } else if (int_0 != 71) { if (int_0 != 257) { if (int_0 != 512) { return intPtr; } if (this.m_UserForm != null && !this.m_UserForm.IsDisposed) { Rectangle rectangle = new Rectangle(this.m_UserForm.Location, this.m_UserForm.Size); if (rectangle.Contains(Cursor.Position)) { bool flag = false; if (this.bool_0 && this.OnMouseMoveIntoFormClientEvent != null) { EventArgs eventArgs = new EventArgs(); this.OnMouseMoveIntoFormClientEvent(this, eventArgs); Class1.ReleaseCapture(); Class1.SetFocus(this.m_UserForm.Handle); flag = true; } if (flag) { } this.bool_0 = false; return intPtr; } } this.method_2(intptr_3, intptr_4); this.method_3(intptr_3, intptr_4); return intPtr; } else { if (this.OnKeyDownEvent != null) { KeyEventArgs keyEventArgs = new KeyEventArgs((Keys)(int)intptr_3); this.OnKeyDownEvent(this, keyEventArgs); return intPtr; } return intPtr; } } this.method_1(); return intPtr; } public int SetFocus2MDIActiveChildClient() { return Class1.SendMessage(this.m_hMDIActiveChildWnd, 7, IntPtr.Zero, IntPtr.Zero); } private bool method_8() { Graphics graphics = null; Font font = null; SolidBrush solidBrush = null; Pen pen = null; try { graphics = WndMsgManager.jigTransparentForm_0.CreateGraphics(); graphics.Clear(WndMsgManager.jigTransparentForm_0.BackColor); Color red = Color.Red; Point point = Cursor.Position; string text = string.Format("屏幕坐标:({0}, {1})", point.X, point.Y); point = WndMsgManager.jigTransparentForm_0.PointToClient(point); font = new Font("宋体", 12f); solidBrush = new SolidBrush(red); graphics.DrawString(text, font, solidBrush, point); List list = new List(5); Point point2 = new Point(0, 0); Point point3 = new Point(WndMsgManager.jigTransparentForm_0.ClientSize.Width, 0); Point point4 = new Point(0, WndMsgManager.jigTransparentForm_0.ClientSize.Height); Point point5 = new Point(WndMsgManager.jigTransparentForm_0.ClientSize.Width, WndMsgManager.jigTransparentForm_0.ClientSize.Height); list.Add(point2); list.Add(point3); list.Add(point5); list.Add(point4); list.Add(point2); pen = new Pen(red, 10f); graphics.DrawLines(pen, list.ToArray()); } catch { return false; } finally { font.Dispose(); pen.Dispose(); solidBrush.Dispose(); graphics.Dispose(); } return true; } public Graphics CreateJigFormGraphics() { return WndMsgManager.jigTransparentForm_0.CreateGraphics(); } public UIDocument UiDoc { get { return this.m_uiDoc; } } public Document Doc { get { return this.UiDoc.Document; } } public UIView UiViewActive { get { try { IList openUIViews = this.m_uiDoc.GetOpenUIViews(); return openUIViews.First(uiview => uiview.ViewId == UiDoc.ActiveView.Id); } catch { } return null; } } public View ViewActive { get { return this.UiDoc.ActiveView; } } public SketchPlane SketchPlane { get { try { return this.ViewActive.SketchPlane; } catch { } return null; } } public Pen JigPen { get; private set; } protected System.Windows.Forms.Form JigForm { get { return WndMsgManager.jigTransparentForm_0; } } protected Color RevitViewBackgroundReverseColor { get { return GetViewBackgroundReverseColor(this.m_uiDoc.Application.Application); } } public static Color GetViewBackgroundReverseColor(Autodesk.Revit.ApplicationServices.Application app) { if (GetViewBackgroundColor(app).ToArgb() == Color.Black.ToArgb()) { return Color.White; } return Color.Black; } public static Color GetViewBackgroundColor(Autodesk.Revit.ApplicationServices.Application app) { var backgroundColor = app.BackgroundColor; return Color.FromArgb((int)backgroundColor.Red, (int)backgroundColor.Green, (int)backgroundColor.Blue); } public event MouseEventHandler OnMouseActivity; protected UIDocument m_uiDoc; private static JigTransparentForm jigTransparentForm_0; protected System.Windows.Forms.Form m_UserForm; private Class1.Delegate1 delegate1_0 = null; private IntPtr intptr_0 = IntPtr.Zero; private Class1.Delegate1 delegate1_1 = null; private IntPtr intptr_1 = IntPtr.Zero; protected IntPtr m_hMDIClientWnd = IntPtr.Zero; protected IntPtr m_hMDIActiveChildWnd = IntPtr.Zero; protected IntPtr m_hMDIActiveChildClientWnd = IntPtr.Zero; [CompilerGenerated] private MouseEventHandler mouseEventHandler_0; public PaintEventHandler OnPaintEvent; public KeyEventHandler OnKeyDownEvent; public WndMsgManager.FocusChangeEvent OnFocusEvent; public WndMsgManager.MouseLeaveFormClientEvnetHandler OnMouseLeaveFormClientEvent; private bool bool_0 = true; public WndMsgManager.MouseMoveIntoFormClientEvnetHandler OnMouseMoveIntoFormClientEvent; public delegate void FocusChangeEvent(object sender, bool bHadFocus); public delegate void MouseLeaveFormClientEvnetHandler(object sender, EventArgs e); public delegate void MouseMoveIntoFormClientEvnetHandler(object sender, EventArgs e); } }