424 lines
16 KiB
C#
424 lines
16 KiB
C#
using Autodesk.Revit.UI;
|
|
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Diagnostics;
|
|
using System.Drawing;
|
|
using System.Drawing.Drawing2D;
|
|
using System.Linq;
|
|
using System.Runtime.CompilerServices;
|
|
using System.Runtime.InteropServices;
|
|
using System.Text;
|
|
using System.Windows.Forms;
|
|
|
|
using UIFramework;
|
|
|
|
using Win32;
|
|
|
|
namespace ShowGridNumber
|
|
{
|
|
public partial class GridNumberForm : Form
|
|
{
|
|
private IntPtr method_0()
|
|
{
|
|
if (!this.dictionary_0.ContainsKey(this.intptr_2))
|
|
{
|
|
this.dictionary_0.Add(this.intptr_2, IntPtr.Zero);
|
|
}
|
|
return this.dictionary_0[this.intptr_2];
|
|
}
|
|
|
|
private IntPtr method_1()
|
|
{
|
|
if (!this.dictionary_0.ContainsKey(this.intptr_1))
|
|
{
|
|
this.dictionary_0.Add(this.intptr_1, IntPtr.Zero);
|
|
}
|
|
return this.dictionary_0[this.intptr_1];
|
|
}
|
|
|
|
public GridNumberForm(ShowGridApplication application)
|
|
{
|
|
this.showGridApplication_0 = application;
|
|
this.InitializeComponent();
|
|
}
|
|
|
|
[DllImport("user32.dll", CharSet = CharSet.Auto)]
|
|
public static extern IntPtr CallWindowProc(IntPtr wndProc, IntPtr hWnd, int msg, IntPtr wParam, IntPtr lParam);
|
|
|
|
[DllImport("user32.dll", CharSet = CharSet.Auto)]
|
|
public static extern IntPtr SetWindowLong(IntPtr hWnd, int nIndex, IntPtr dwNewLong);
|
|
|
|
[DllImport("user32.dll", CharSet = CharSet.Auto)]
|
|
public static extern IntPtr SetWindowLong(IntPtr hWnd, int nIndex, GridNumberForm.NewWndProc wndproc);
|
|
|
|
[DllImport("user32.dll")]
|
|
public static extern IntPtr FindWindowEx(IntPtr hwndParent, IntPtr hwndChildAfter, string lpszClass, string lpszWindow);
|
|
|
|
private void GridNumberForm_Load(object sender, EventArgs e)
|
|
{
|
|
this.method_2();
|
|
}
|
|
|
|
private void method_2()
|
|
{
|
|
IntPtr zero = IntPtr.Zero;
|
|
try
|
|
{
|
|
IntPtr mainWindowHandle = Process.GetCurrentProcess().MainWindowHandle;
|
|
this.intptr_0 = DllImportManeger.FindWindowEx(mainWindowHandle, IntPtr.Zero, "MDIClient", string.Empty);
|
|
}
|
|
catch
|
|
{
|
|
}
|
|
finally
|
|
{
|
|
Marshal.FreeHGlobal(zero);
|
|
}
|
|
}
|
|
|
|
private void GridNumberForm_FormClosed(object sender, FormClosedEventArgs e)
|
|
{
|
|
if (IntPtr.Zero != this.method_0())
|
|
{
|
|
GridNumberForm.SetWindowLong(this.intptr_2, -4, this.method_0());
|
|
}
|
|
if (IntPtr.Zero != this.method_1())
|
|
{
|
|
GridNumberForm.SetWindowLong(this.intptr_1, -4, this.method_1());
|
|
}
|
|
this.font_0.Dispose();
|
|
}
|
|
|
|
public IntPtr WndMsgProcChildClient(IntPtr hWnd, int msg, IntPtr wParam, IntPtr lParam)
|
|
{
|
|
IntPtr intPtr2;
|
|
try
|
|
{
|
|
IntPtr intPtr = GridNumberForm.CallWindowProc(this.method_0(), hWnd, msg, wParam, lParam);
|
|
if (msg <= 32)
|
|
{
|
|
if (msg != 2)
|
|
{
|
|
if (msg != 32)
|
|
{
|
|
}
|
|
}
|
|
else
|
|
{
|
|
GridNumberForm.SetWindowLong(this.intptr_2, -4, this.method_0());
|
|
this.newWndProc_0 = null;
|
|
base.Hide();
|
|
}
|
|
}
|
|
else if (msg != 512)
|
|
{
|
|
switch (msg)
|
|
{
|
|
case 519:
|
|
this.bool_0 = true;
|
|
break;
|
|
case 520:
|
|
this.bool_0 = false;
|
|
break;
|
|
case 521:
|
|
case 522:
|
|
this.DrawGridNumText(false);
|
|
break;
|
|
}
|
|
}
|
|
else if (this.bool_0)
|
|
{
|
|
this.DrawGridNumText(false);
|
|
}
|
|
intPtr2 = intPtr;
|
|
}
|
|
catch (Exception)
|
|
{
|
|
intPtr2 = IntPtr.Zero;
|
|
}
|
|
return intPtr2;
|
|
}
|
|
|
|
public IntPtr WndMsgProcChild(IntPtr hWnd, int msg, IntPtr wParam, IntPtr lParam)
|
|
{
|
|
IntPtr intPtr2;
|
|
try
|
|
{
|
|
IntPtr intPtr = GridNumberForm.CallWindowProc(this.method_1(), hWnd, msg, wParam, lParam);
|
|
if (msg <= 5)
|
|
{
|
|
if (msg != 2)
|
|
{
|
|
if (msg == 5)
|
|
{
|
|
this.DrawGridNumText(false);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
GridNumberForm.SetWindowLong(this.intptr_1, -4, this.method_1());
|
|
this.newWndProc_1 = null;
|
|
base.Hide();
|
|
}
|
|
}
|
|
else if (msg == 532 || msg == 534)
|
|
{
|
|
this.DrawGridNumText(false);
|
|
}
|
|
intPtr2 = intPtr;
|
|
}
|
|
catch (Exception)
|
|
{
|
|
intPtr2 = IntPtr.Zero;
|
|
}
|
|
return intPtr2;
|
|
}
|
|
|
|
public void RefreshDocAndView(UIDocument uiDoc)
|
|
{
|
|
if (uiDoc == null)
|
|
{
|
|
return;
|
|
}
|
|
this.uidocument_0 = uiDoc;
|
|
if (this.gridNumberShowManager_0 == null)
|
|
{
|
|
this.gridNumberShowManager_0 = new GridNumberShowManager(uiDoc);
|
|
}
|
|
else
|
|
{
|
|
this.gridNumberShowManager_0.RefreshUIDocument(this.uidocument_0);
|
|
}
|
|
IntPtr intPtr = IntPtr.Zero;
|
|
try
|
|
{
|
|
this.intptr_1 = (IntPtr)Functions.SendMessage(this.intptr_0, 553U, 0, 0);
|
|
if (this.newWndProc_1 == null)
|
|
{
|
|
this.newWndProc_1 = new GridNumberForm.NewWndProc(this.WndMsgProcChild);
|
|
}
|
|
IntPtr intPtr2 = GridNumberForm.SetWindowLong(this.intptr_1, -4, this.newWndProc_1);
|
|
if (!this.dictionary_0.ContainsKey(this.intptr_1))
|
|
{
|
|
this.dictionary_0.Add(this.intptr_1, intPtr2);
|
|
}
|
|
intPtr = Marshal.StringToHGlobalAnsi("AfxFrameOrView");
|
|
DllImportManeger.EnumChildWindows(this.intptr_1, new DllImportManeger.CallBack(this.method_3), intPtr);
|
|
if (this.newWndProc_0 == null)
|
|
{
|
|
this.newWndProc_0 = new GridNumberForm.NewWndProc(this.WndMsgProcChildClient);
|
|
}
|
|
IntPtr intPtr3 = GridNumberForm.SetWindowLong(this.intptr_2, -4, this.newWndProc_0);
|
|
if (!this.dictionary_0.ContainsKey(this.intptr_2))
|
|
{
|
|
this.dictionary_0.Add(this.intptr_2, intPtr3);
|
|
}
|
|
}
|
|
catch (Exception)
|
|
{
|
|
this.showGridApplication_0.DrawGridNumber = false;
|
|
}
|
|
finally
|
|
{
|
|
Marshal.FreeHGlobal(intPtr);
|
|
}
|
|
}
|
|
|
|
public void RefreshDocAndView2019(UIDocument uiDoc)
|
|
{
|
|
if (uiDoc == null)
|
|
{
|
|
return;
|
|
}
|
|
this.uidocument_0 = uiDoc;
|
|
if (this.gridNumberShowManager_0 == null)
|
|
{
|
|
this.gridNumberShowManager_0 = new GridNumberShowManager(uiDoc);
|
|
}
|
|
else
|
|
{
|
|
this.gridNumberShowManager_0.RefreshUIDocument(this.uidocument_0);
|
|
}
|
|
IntPtr intPtr = IntPtr.Zero;
|
|
try
|
|
{
|
|
intPtr = Marshal.StringToHGlobalAnsi("AfxFrameOrView");
|
|
MFCMDIChildFrameControl mfcmdichildFrameControl = MainWindow.getMainWnd().getAllViews().Where(form=>form.isActive)
|
|
.FirstOrDefault<MFCMDIChildFrameControl>();
|
|
this.intptr_0 = mfcmdichildFrameControl.hostHWnd;
|
|
DllImportManeger.EnumChildWindows(this.intptr_0, new DllImportManeger.CallBack(this.method_3), intPtr);
|
|
if (this.newWndProc_0 == null)
|
|
{
|
|
this.newWndProc_0 = new GridNumberForm.NewWndProc(this.WndMsgProcChildClient);
|
|
}
|
|
IntPtr intPtr2 = GridNumberForm.SetWindowLong(this.intptr_2, -4, this.newWndProc_0);
|
|
if (!this.dictionary_0.ContainsKey(this.intptr_2))
|
|
{
|
|
this.dictionary_0.Add(this.intptr_2, intPtr2);
|
|
}
|
|
}
|
|
catch
|
|
{
|
|
this.showGridApplication_0.DrawGridNumber = false;
|
|
}
|
|
finally
|
|
{
|
|
Marshal.FreeHGlobal(intPtr);
|
|
}
|
|
}
|
|
|
|
public bool UnLoad()
|
|
{
|
|
if (this.newWndProc_0 != null)
|
|
{
|
|
if (this.showGridApplication_0.m_version < 2019)
|
|
{
|
|
GridNumberForm.SetWindowLong(this.intptr_1, -4, this.method_1());
|
|
}
|
|
GridNumberForm.SetWindowLong(this.intptr_2, -4, this.method_0());
|
|
return false;
|
|
}
|
|
return true;
|
|
}
|
|
|
|
private bool method_3(IntPtr intptr_3, IntPtr intptr_4)
|
|
{
|
|
try
|
|
{
|
|
string text = Marshal.PtrToStringAnsi(intptr_4);
|
|
StringBuilder stringBuilder = new StringBuilder(512);
|
|
DllImportManeger.GetClassName(intptr_3, stringBuilder, stringBuilder.Capacity);
|
|
if (stringBuilder.ToString().Contains(text))
|
|
{
|
|
this.intptr_2 = intptr_3;
|
|
return false;
|
|
}
|
|
}
|
|
catch
|
|
{
|
|
}
|
|
return true;
|
|
}
|
|
|
|
public void SetShowLinkDocGridNum(bool bShowLink)
|
|
{
|
|
ShowGridApplication.m_ThisApp.m_bShowLink = bShowLink;
|
|
}
|
|
|
|
public void DrawGridNumText(bool bIdling = false)
|
|
{
|
|
Graphics graphics = base.CreateGraphics();
|
|
if (this.uidocument_0 != null && this.uidocument_0.ActiveView != null)
|
|
{
|
|
if (this.showGridApplication_0.DrawGridNumber)
|
|
{
|
|
if (this.uidocument_0.ActiveView.ViewType != Autodesk.Revit.DB.ViewType.ThreeD)
|
|
{
|
|
Size size = default(Size);
|
|
Point empty = Point.Empty;
|
|
DllImportManeger.Rect rect;
|
|
DllImportManeger.GetWindowRect(this.intptr_0, out rect);
|
|
if (this.gridNumberShowManager_0.GetGridNumberShowInfo(bIdling, rect, ref empty, ref size) == CalcGridInfoResult.eIdling)
|
|
{
|
|
return;
|
|
}
|
|
base.Location = empty;
|
|
base.Size = size;
|
|
this.gridNumberShowManager_0.TranformIntersectPt(base.Handle);
|
|
graphics.SmoothingMode = SmoothingMode.AntiAlias;
|
|
graphics.InterpolationMode = InterpolationMode.HighQualityBicubic;
|
|
graphics.CompositingQuality = CompositingQuality.HighQuality;
|
|
graphics.Clear(Color.White);
|
|
Brush red = Brushes.Red;
|
|
Pen pen = new Pen(Color.Red, 2f);
|
|
StringFormat stringFormat = new StringFormat();
|
|
stringFormat.Alignment = StringAlignment.Center;
|
|
stringFormat.LineAlignment = StringAlignment.Center;
|
|
StringFormat stringFormat2 = new StringFormat();
|
|
stringFormat2.Alignment = StringAlignment.Near;
|
|
stringFormat2.LineAlignment = StringAlignment.Center;
|
|
StringFormat stringFormat3 = new StringFormat();
|
|
stringFormat3.Alignment = StringAlignment.Far;
|
|
stringFormat3.LineAlignment = StringAlignment.Center;
|
|
for (int i = 0; i < this.gridNumberShowManager_0.m_lstGridNumShowInfo.Count; i++)
|
|
{
|
|
Point cirlLocation = this.gridNumberShowManager_0.m_lstGridNumShowInfo[i].CirlLocation;
|
|
Point textLocation = this.gridNumberShowManager_0.m_lstGridNumShowInfo[i].TextLocation;
|
|
string elemText = this.gridNumberShowManager_0.m_lstGridNumShowInfo[i].ElemText;
|
|
if (this.gridNumberShowManager_0.m_lstGridNumShowInfo[i].ElemClass == ElemType.eGrid)
|
|
{
|
|
graphics.DrawArc(pen, cirlLocation.X, cirlLocation.Y, 50, 50, 0, 360);
|
|
}
|
|
switch (this.gridNumberShowManager_0.m_lstGridNumShowInfo[i].OutlineSide)
|
|
{
|
|
case OutLineSide.eUp:
|
|
case OutLineSide.eBottom:
|
|
graphics.DrawString(elemText, this.font_0, red, textLocation, stringFormat);
|
|
break;
|
|
case OutLineSide.eLeft:
|
|
graphics.DrawString(elemText, this.font_0, red, textLocation, stringFormat2);
|
|
break;
|
|
case OutLineSide.eRight:
|
|
graphics.DrawString(elemText, this.font_0, red, textLocation, stringFormat3);
|
|
break;
|
|
}
|
|
}
|
|
stringFormat.Dispose();
|
|
stringFormat2.Dispose();
|
|
stringFormat3.Dispose();
|
|
graphics.Dispose();
|
|
return;
|
|
}
|
|
}
|
|
graphics.Clear(Color.White);
|
|
graphics.Dispose();
|
|
return;
|
|
}
|
|
graphics.Clear(Color.White);
|
|
graphics.Dispose();
|
|
}
|
|
|
|
private void InitializeComponent()
|
|
{
|
|
base.SuspendLayout();
|
|
base.AutoScaleDimensions = new SizeF(6f, 12f);
|
|
base.AutoScaleMode = AutoScaleMode.Font;
|
|
this.BackColor = Color.White;
|
|
base.ClientSize = new Size(132, 76);
|
|
base.FormBorderStyle = FormBorderStyle.None;
|
|
base.Name = "GridNumberForm";
|
|
base.ShowInTaskbar = false;
|
|
base.TransparencyKey = Color.White;
|
|
base.FormClosed += this.GridNumberForm_FormClosed;
|
|
base.Load += this.GridNumberForm_Load;
|
|
base.ResumeLayout(false);
|
|
}
|
|
|
|
private Dictionary<IntPtr, IntPtr> dictionary_0 = new Dictionary<IntPtr, IntPtr>();
|
|
|
|
private UIDocument uidocument_0;
|
|
|
|
private Font font_0 = new Font("微软雅黑", 25f, GraphicsUnit.Pixel);
|
|
|
|
private GridNumberShowManager gridNumberShowManager_0;
|
|
|
|
private GridNumberForm.NewWndProc newWndProc_0;
|
|
|
|
private GridNumberForm.NewWndProc newWndProc_1;
|
|
|
|
private IntPtr intptr_0 = IntPtr.Zero;
|
|
|
|
private IntPtr intptr_1 = IntPtr.Zero;
|
|
|
|
private IntPtr intptr_2 = IntPtr.Zero;
|
|
|
|
private bool bool_0;
|
|
|
|
private ShowGridApplication showGridApplication_0;
|
|
|
|
public delegate IntPtr NewWndProc(IntPtr hWnd, int msg, IntPtr wParam, IntPtr lParam);
|
|
|
|
}
|
|
}
|