Inventor loses focus

Inventor loses focus

Anonymous
Not applicable
590 Views
5 Replies
Message 1 of 6

Inventor loses focus

Anonymous
Not applicable
I've created a toolbar addin for Inventor (using C#). The toolbar contains a couple of buttons. If you click any button it will pop up a Form dialog with Inventor window set as parent. When closing some of the Form dialogs Inventor loses focus and another window pops up in front of Inventor. It could be Microsoft Explorer or any or the open windows in the background. I don't know what causes this problem. All Form dialogs are closed in the same way. I've tried both this.Close(); and this.Dispose();. Does anyone have any idea how to solve this?
0 Likes
591 Views
5 Replies
Replies (5)
Message 2 of 6

jeff.pek
Community Manager
Community Manager
Hi -

Can you show the code that you're using to establish the Inventor window as your dialog's parent?

Jeff
0 Likes
Message 3 of 6

Anonymous
Not applicable
// Win API
[DllImport("user32.dll")]
internal static extern int SetParent(IntPtr hWndChild, IntPtr hWndNewParent);


public MainForm()
{
InitializeComponent();

SetParent(this.Handle, (System.IntPtr)invApp.MainFrameHWND);

...

}
0 Likes
Message 4 of 6

jeff.pek
Community Manager
Community Manager
Are you using ShowDialog, or just Show()? If modeless, can you see if this works instead? If it's modal, you can use the same approach, but using ShowDialog.

Jeff

...
NativeWindow hWnd = new NativeWindow();
hWnd.AssignHandle((IntPtr)invApp.MainFrameHWND);

MainForm yourForm = new MainForm();
yourForm.Show(hWnd);
...
0 Likes
Message 5 of 6

Anonymous
Not applicable

This is a .NET issue (can't find the info again,
but it is out there). If you are seeing this, you will need to reset the focus
to the IV window in your code.

 


style="PADDING-RIGHT: 0px; PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: #000000 2px solid; MARGIN-RIGHT: 0px">
Are
you using ShowDialog, or just Show()? If modeless, can you see if this works
instead? If it's modal, you can use the same approach, but using ShowDialog.
Jeff ... NativeWindow hWnd = new NativeWindow();
hWnd.AssignHandle((IntPtr)invApp.MainFrameHWND); MainForm yourForm = new
MainForm(); yourForm.Show(hWnd); ...
0 Likes
Message 6 of 6

Anonymous
Not applicable
Thanks alot! I found this SetFocus method in the Win API that seems to work.
0 Likes