Community
Inventor Programming - iLogic, Macros, AddIns & Apprentice
Inventor iLogic, Macros, AddIns & Apprentice Forum. Share your knowledge, ask questions, and explore popular Inventor topics related to programming, creating add-ins, macros, working with the API or creating iLogic tools.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Inventor loses focus

5 REPLIES 5
Reply
Message 1 of 6
simonsson
428 Views, 5 Replies

Inventor loses focus

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?
5 REPLIES 5
Message 2 of 6
jeff.pek
in reply to: simonsson

Hi -

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

Jeff
Message 3 of 6
simonsson
in reply to: simonsson

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


public MainForm()
{
InitializeComponent();

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

...

}
Message 4 of 6
jeff.pek
in reply to: simonsson

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);
...
Message 5 of 6
Anonymous
in reply to: simonsson


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); ...
Message 6 of 6
simonsson
in reply to: simonsson

Thanks alot! I found this SetFocus method in the Win API that seems to work.

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report