WinForm与Revit窗口之间的切换:
1)首先添加引用:AdWindows.dll
2) 非托管引用
[DllImport(“user32.dll”)]
public static extern IntPtr GetActiveWindow();
[DllImport(“user32.dll”)]
public static extern IntPtr SetActiveWindow(IntPtr hwnd);
IntPtr active = IntPtr.Zero;
3)初始化
private void TestForm_Load(object sender, EventArgs e)
{
active = ComponentManager.ApplicationWindow;
}
4)事件中调用
private void button1_Click(object sender, EventArgs e)
{
SetActiveWindow(active);
}
在VS项目中通过DllImport引入一个DLL和添加引用方式添加一个DLL区别在于:
DllImpor针对非托管的,非托管指的是不利用.net 生成的DLL;
引用是针对托管的。