How to use the GenericWindow co-class?

896
8
Jump to solution
06-15-2012 12:05 PM
SuiHuang
Occasional Contributor II
Hi Everybody:

    I am testing around the ArcObjects 10 ESRI.ArcGIS.*UI interfaces and see what kind of out-of-box dialog boxes and windows are available to me.

    I am guessing that the GenericWindow co-class should popup a window for me
http://help.arcgis.com/en/sdk/10.0/arcobjects_net/componenthelp/index.html#/GenericWindowClass_Class...

    However, I haven't been able to find a way to use it. I tried the following code and debuged it:
*********************************************
try
{
     IGenericWindow x = new GenericWindowClass();
     x.Application = _mApplication;
     x.Show(true);
} catch (Exception ex)
{
    MessageBox.Show(ex.Message);
}
**********************************************

an exception is throwned at "x.Show(true)": Error HRESULT E_FAIL has been returned from a call to a COM component.

I also searched around the namespace including the Object Model diagram, but didn't find any *Factory class to generate an instance of it.

How shall I use this co-class? and any clue how I can figure the similar information?

Thank you!
0 Kudos
1 Solution

Accepted Solutions
LeoDonahue
Occasional Contributor III
I took out the line to show the window and I still got the window and no error message.  What is the show(true) method for if you don't need it?  Don't know.  It obviously does not set the title like I asked it either...

I will ask, why use this?  Why not create your own window using a JFrame or a .NET window, or why not even use a dockable window?

View solution in original post

0 Kudos
8 Replies
LeoDonahue
Occasional Contributor III
I think x.Application should be set to the _mApplication windows handle, something like _mApplication.getHWnd() or whatever the syntax is for .NET.
0 Kudos
SuiHuang
Occasional Contributor II
I think x.Application should be set to the _mApplication windows handle, something like _mApplication.getHWnd() or whatever the syntax is for .NET.


Hi Idonahue:

    I got an "Attempted to read or write protected memory. This is often an indication that other memory is corrupt." error after changing that line of code to "x.Application = _mApplication.hWnd" and the execution attempt to execute this line.
    Anything else I shall try?
    Thank you.
0 Kudos
LeoDonahue
Occasional Contributor III
Well, I can't find what I want in the .NET docs.

The Java docs indicate that if you set the application reference of a Generic Window, that it needs a reference to another Automation Object.  So maybe you don't need the application window's handle after all.



When I created a simple button to launch a GenericWindow, I got an error on the show method, but I also got a Generic Window.

Add-in Code:
public class Button1 extends Button {

    /**
     * Called when the button is clicked.
     * 
     * @exception java.io.IOException if there are interop problems.
     * @exception com.esri.arcgis.interop.AutomationException if the component throws an ArcObjects exception.
     */
    @Override
    public void onClick() throws IOException, AutomationException {
        // TODO Auto-generated method stub
        GenericWindow genWindow = new GenericWindow();
        genWindow.setApplicationByRef(app);
        genWindow.setName("Window 1");
        genWindow.setTitle("Generic Window Test");
        genWindow.putPosition(100, 100, 500, 500);
        genWindow.show(true);
        
    }

    @Override
    public void init(IApplication app) throws IOException, AutomationException {
        // TODO Auto-generated method stub
        super.init(app);
        this.app = app;
        mxDoc = (IMxDocument) app.getDocument();
        map = mxDoc.getActiveView().getFocusMap();
    }

    private IApplication app;
    private IMxDocument mxDoc;
    private IMap map;
}


Error message from log file:
INFO::Using the following arguments to create the JVM
-Djava.class.path=C:\Program Files (x86)\ArcGIS\Desktop10.0\\java\lib\arcobjects.jar
-Xms64m
-Xmx128m
-Xss512k
-Xdebug
-Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=8013
INFO::Successfully created an instance of : com/esri/arcgis/addinframework/AddInFactory
java.lang.reflect.InvocationTargetException

    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)

    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)

    at java.lang.reflect.Method.invoke(Method.java:597)

Caused by: AutomationException: 0x80004005 - Unspecified error

    at com.esri.arcgis.arcmapui.GenericWindow.show(Unknown Source)

    at Button1.onClick(Button1.java:27)

    at com.esri.arcgis.addinframework.InternalButton.onClick(Unknown Source)

    ... 4 more

SEVERE::CAUSE
AutomationException: 0x80004005 - Unspecified error

    at com.esri.arcgis.arcmapui.GenericWindow.show(Unknown Source)

    at Button1.onClick(Button1.java:27)

    at com.esri.arcgis.addinframework.InternalButton.onClick(Unknown Source)

    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)

    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)

    at java.lang.reflect.Method.invoke(Method.java:597)


GenericWindow Screenshot is attached.
0 Kudos
LeoDonahue
Occasional Contributor III
I took out the line to show the window and I still got the window and no error message.  What is the show(true) method for if you don't need it?  Don't know.  It obviously does not set the title like I asked it either...

I will ask, why use this?  Why not create your own window using a JFrame or a .NET window, or why not even use a dockable window?
0 Kudos
SuiHuang
Occasional Contributor II
[ATTACH=CONFIG]15298[/ATTACH]

Hi Idonahue:

    I tried the following code in C#:
IGenericWindow x = new GenericWindowClass();
x.Application = _mApplication;
x.PutPosition(100, 100, 200, 200);

    and then a window pops up. If I add a show(true) statement to the end, then I will get an "Error HRESULT E_FAIL has been returned from a call to a COM component" error. In the aspect .NET works the same as JAVA.

    The reason I ask this question is that I am exploring how I can use the existing UI components in ArcMap through ArcObjects. I am making some data editing tool (ArcMap extension), and want to use as many out-of-box functions as possible, and at the same time enhance it to the client's specific situation. The attached picture is one of the things I want to do: add some additional buttons to the Attribute Window of ArcMap editing tool.
    How shall I start with?
    Thank you!


I took out the line to show the window and I still got the window and no error message.  What is the show(true) method for if you don't need it?  Don't know.  It obviously does not set the title like I asked it either...

I will ask, why use this?  Why not create your own window using a JFrame or a .NET window, or why not even use a dockable window?
0 Kudos
LeoDonahue
Occasional Contributor III
Adding buttons to existing controls, such as the Edit Attributes Window?  I have not seen this done using Add-ins.
0 Kudos
SuiHuang
Occasional Contributor II
Adding buttons to existing controls, such as the Edit Attributes Window?  I have not seen this done using Add-ins.


Then what about putting existing ESRI controls together with other .NET control (such as a button)?
Thank you!
0 Kudos
SuiHuang
Occasional Contributor II
Then what about putting existing ESRI controls together with other .NET control (such as a button)?
Thank you!


I found that there is a way to customize the ArcMap Attribute Window (such as to add a button).
Here is an example.
http://resources.arcgis.com/en/help/arcobjects-net/conceptualhelp/index.html#//0001000004s8000000

Cheers.
0 Kudos