Problem with modeless Form Window, which implements IWin32Window
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Dear Community,
I tried to follow the logic, described on Jeremy's post here:
https://jeremytammik.github.io/tbc/a/0088_revit_window_handle.htm
First - what is a goal.
The goal is to create a Win Form window, which would start with Revit Application and close with Revit Application. Window is in modeless dialog and displays the output of different actions/commands which are happening while working in Revit Document. Everything works fine for me, except for the part, that with each Revit Command (implementing IExternalCommand) new instance of Form Window is created. I would like to keep only one window which hides and shows, whenever any action is taken.
Below my code - I hope anyone could be able to direct me which path to go....
Win Form Class:
public partial class CmdWindowHandleForm : Form
{
public string LabelText
{
get{ return _labelText.Text; }
set{ _labelText.Text = value; }
}
private static CmdWindowHandleForm _thisInstance;
public CmdWindowHandleForm()
{
InitializeComponent();
}
}
partial class CmdWindowHandleForm
{
private void InitializeComponent()
{
this.components = new System.ComponentModel.Container();
this._labelText = new Label();
this._labelText.Text = string.Empty;
this.Controls.Add(this._labelText);
}
}
Class with WindowHandle, which is used as argument when Form.Show() method is called:
public class WindowHandle : IWin32Window
{
public IntPtr Handle
{
get{ return _handleWindow; }
}
IntPtr _handleWindow;
public WindowHandle(IntPtr handleWindow)
{
_handleWindow = handleWindow;
}
}
And lastly my static class of InfoConsole window, which would run along Revit app:
public static class InfoConsole
{
public static CmdWindowHandleForm Window
{
get{ return _window; }
}
static WindowHandle _hWndRevit = null;
static CmdWindowHandleForm _window = null;
public static void Show(string message)
{
if (_hWndRevit == null)
{
Process process = Process.GetCurrentProcess();
IntPtr h = process.MainWindowHandle;
_hWndRevit = new WindowHandle(h);
}
if(InfoConsole._window == null)
{
_window = new CmdWindowHandleForm();
_window.Show(_hWndRevit as IWin32Window);
}
else
{
_window.Visible = true;
}
_window.AddText(message);
}
}
And while running a command (implementing IExternalCommand) method is simply called:
InfoConsole.Show(outputMessage);
any help much appreciated,
Lukasz