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: 

Get handle of parent window? Needed to keep focus on a popup window.

4 REPLIES 4
Reply
Message 1 of 5
cpicke
493 Views, 4 Replies

Get handle of parent window? Needed to keep focus on a popup window.

I have a script that opens a popup form when a custom button is clicked in the ribbon. In the code, this was implemented using the code snippet:

override protected void ButtonDefinition_OnExecute(NameValueMap context)
{
    if (InventorApplication.ActiveEditObject is Inventor.PartDocument)
    {
        MyWin win = new MyWin();
        win.Show();
    }
    else
    {
        MessageBox.Show("A part document must be active for this command");
    }
}

Also note that this window must not be modal i.e., I cannot use win.ShowMessage(); because there is a button on this window that invokes e.g., the line of code

pickedFace = StandardAddInServer.m_inventorApplication.CommandManager.Pick(Inventor.SelectionFilterEnum.kPartFaceFilter,"Pick Face") as Face;

which will not work properly if the window is modal.

I wish to keep focus on MyWin. You would think that one way to do this is to put the handle of the parent window inside the parentheses of win.Show(); However, the parent window appears to be the Inventor main window itself. Does anybody know what is the handle of the parent window, so I can keep focus on the popup window MyWin?

Thank you.

4 REPLIES 4
Message 2 of 5
rjay75
in reply to: cpicke

Here's the code to get Inventor's window handle to do what you need.

 

        void btnDoSomething_OnExecute(NameValueMap Context)
        {
            MyWinForm myWin = null; 
            if (appInventor.ActiveDocument.DocumentType == DocumentTypeEnum.kPartDocumentObject)
            {
                myWin = new MyWinForm();
                NativeWindow hWnd = new NativeWindow();
                hWnd.AssignHandle((IntPtr)m_inventorApplication.MainFrameHWND);
                myWin.Show(hWnd);
}
else
{
MessageBox.Show("A part document must be active for this command");
} }

 

Message 3 of 5
Anonymous
in reply to: rjay75

Hello! 

 

is it possible to get the code in VBA too? in order to get the Window handle in VBA?

 

thanks!

Message 4 of 5
GeorgK
in reply to: Anonymous

You can use the converter:

http://converter.telerik.com/

Message 5 of 5
Anonymous
in reply to: GeorgK

never mind I found a premade command:

 

SyntaxEditor Code Snippet

ThisApplication.MainFrameHWND

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

Post to forums  

Autodesk Design & Make Report