forked from architecture-building-systems/revitpythonshell
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
64 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
using System; | ||
using System.ComponentModel; | ||
using System.Diagnostics; | ||
using System.Runtime.InteropServices; | ||
using System.Windows; | ||
using System.Windows.Interop; | ||
|
||
namespace RevitPythonShell.Helpers | ||
{ | ||
public static class ProcessManager | ||
{ | ||
|
||
[DllImport("user32.dll")] | ||
[return: MarshalAs(UnmanagedType.Bool)] | ||
private static extern bool SetForegroundWindow(IntPtr hWnd); | ||
|
||
public static void SetRevitAsWindowOwner(this Window window) | ||
{ | ||
if (null == window) { return; } | ||
window.WindowStartupLocation = WindowStartupLocation.CenterScreen; | ||
WindowInteropHelper helper = new WindowInteropHelper(window); | ||
helper.Owner = GetActivateWindow(); | ||
window.Closing += SetActivateWindow; | ||
} | ||
|
||
private static void SetActivateWindow(object sender, CancelEventArgs e) | ||
{ | ||
SetActivateWindow(); | ||
} | ||
|
||
/// <summary> | ||
/// Set process revert use revit | ||
/// </summary> | ||
/// <returns></returns> | ||
public static bool SetActivateWindow() | ||
{ | ||
IntPtr ptr = GetActivateWindow(); | ||
if (ptr != IntPtr.Zero) | ||
{ | ||
return SetForegroundWindow(ptr); | ||
} | ||
return false; | ||
} | ||
|
||
/// <summary> | ||
/// return active windows is active | ||
/// </summary> | ||
/// <returns></returns> | ||
public static IntPtr GetActivateWindow() | ||
{ | ||
return Process.GetCurrentProcess().MainWindowHandle; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters