Getting a sequence of Point2D objects from a PathIterator?

I would like to be able to take an arc or some other non-straight shape and convert it's geometry into a series of points that (roughly) traverse it. I attempted the following, as an example to see how it would work:
     arc = new Arc2D.Double(50,50,150,150,135,-270,Arc2D.OPEN);
     PathIterator pi = arc.getPathIterator(null);
     double[] coords = new double[6];
     int code;
     while (!pi.isDone()) {
          code = pi.currentSegment(coords);
          switch (code) {
          case PathIterator.SEG_CLOSE:
               System.out.print("Close: ");
               break;
          case PathIterator.SEG_CUBICTO:
               System.out.print("Cubic To: ");
               break;
          case PathIterator.SEG_LINETO:
               System.out.print("Line To: ");
               break;
          case PathIterator.SEG_MOVETO:
               System.out.print("Move To: ");
               break;
          case PathIterator.SEG_QUADTO:
               System.out.print("Quad To: ");
               break;
          default:
               break;
          System.out.println(coords[0] + "," + coords[1] + "   " + coords[2] + "," + coords[3] + "   " + coords[4] + "," + coords[5]);
          pi.next();
     }The output was this:
Move To: 71.96699141100893,71.96699141100893   0.0,0.0   0.0,0.0
Cubic To: 101.25631329235418,42.6776695296637   148.74368670764582,42.6776695296637   178.03300858899107,71.96699141100893
Cubic To: 207.32233047033628,101.25631329235418   207.32233047033628,148.74368670764582   178.03300858899107,178.03300858899107
Cubic To: 148.74368670764582,207.32233047033628   101.25631329235418,207.32233047033628   71.96699141100893,178.03300858899107Clearly this isn't what I'm looking for. Does anyone have any suggestions on how I might go about doing this?
Any input is appreciated.

import java.awt.*;
import java.awt.geom.*;
import java.util.List;
import java.util.*;
import javax.swing.*;
public class TraversePoints extends JPanel {
    Arc2D.Double arc = new Arc2D.Double(50,50,150,150,135,-270,Arc2D.OPEN);
    protected void paintComponent(Graphics g) {
        super.paintComponent(g);
        Graphics2D g2 = (Graphics2D)g;
        g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
                            RenderingHints.VALUE_ANTIALIAS_ON);
        g2.setPaint(Color.blue);
        g2.draw(arc);
        g2.setPaint(Color.red);
        AffineTransform at = AffineTransform.getTranslateInstance(150, 100);
        Point2D.Double[] points = getTraversalPoints(at, 1.0);
        for(int j = 0; j < points.length; j++)
            g2.fill(new Ellipse2D.Double(points[j].x-2, points[j].y-2, 4, 4));
    private Point2D.Double[] getTraversalPoints(AffineTransform at,
                                                double flatness) {
        List<Point2D.Double> list = new ArrayList<Point2D.Double>();
        PathIterator pit = arc.getPathIterator(at, flatness);
        double[] coords = new double[6];
        int count = 0;
        while(!pit.isDone()) {
            int type = pit.currentSegment(coords);
            switch(type) {
                case PathIterator.SEG_MOVETO:
                    // fall through
                case PathIterator.SEG_LINETO:
                    list.add(new Point2D.Double(coords[0], coords[1]));
                    break;
                case PathIterator.SEG_CLOSE:
                    System.out.println("CLOSE");
                    break;
                default:
                    System.out.println("unexpected type = : " + type);
            count++;
            pit.next();
        System.out.printf("%d points at flatness = %.1f%n",
                           count, flatness);
        return list.toArray(new Point2D.Double[list.size()]);
    public static void main(String[] args) {
        JFrame f = new JFrame();
        f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        f.add(new TraversePoints());
        f.setSize(400,400);
        f.setLocation(200,200);
        f.setVisible(true);
}

Similar Messages

  • Client unable to get the javax.activation.DataHandler object from Server

    Hi All,
    I am trying to download the file from the server to the client using Javax.Activation.Data Handler object with IBM web services. But server always returning the Data Handler object is null. I am wondering why it is behaving like this.
    My requirement is add the file to the Data Handler object from the server and read the same from the client. But I am always getting Data Handler object is  null at the client place.
    Please see the client side code and server side code below.
    Server side Code:
    This is the simple web service method, its creating the Data Handler object and adding it to the Hash Map and returning the Hash Map object to the client.
    public Hashtable download()
              DataHandler dh = null;
              HashMap hashMap =new HashMap();
              try{
                   //Sample test files contains data
                   String downLoadFName="C:/ADP/downLoadData.txt";
                   //Creating the DataHandler Object with sample file
                   dh      =      new DataHandler(new FileDataSource(new File(downLoadFName)));
                   //Keeping the DataHandler object in the HashMap.
                   hashMap.put("DATAHANDLER",dh);
                   //keeping the sample test message object in the HashMap
                   hashMap.put("TEST","Keeping the DataHandler and test messages in the hashTable");                         
              }catch(Exception e){
                   logger.error("Error :while sending the data:"+e.getMessage(), e);
              //retrun the HashMap object to the client.
              return hashMap;
    Client Side Code:
    This is the simple client code, and connecting to the server and invoking the web service method
    //This is the client code,Just invoking the webservice method from the Webspehre server.
    public class WebserviceClient {
         static DocumentTransfer controller     =     null;
         public static void main(String args[]){     
                DocumentTransferService service          =     null;
              try{
                   //Creating the service Object
                   service               =     new DocumentTransferServiceLocator();
                   //Getting the Server connection
                    controller          =      (DocumentTransfer)service.getDocumentTransfer(new java.net.URL("http://localhost:9081/eNetsRuntimeEngine/services/DocumentTransfer"));
                    //Calling the download method from the server and it returns HashMap object.
                   HashMap hashMap     = controller.download();
                   //Getting the DataHandler Object from the HashMap
                    DataHandler dh=(DataHandler)hashMap.get("DATAHANDLER");
                   System.out.println("DATAHANDLER: :"+dh);
                   //Getting the String object from the HashMap.
                   String message=(String)hashMap.get("TEST");
                   System.out.println(": :"+message);
               }catch(Exception e){
                    System.out.println("Exception :Not able to get the file :"+e.getMessage());
    Could you please give me some inputs on this?
    Thanks in advance,
    Sreeni.

    Hi Stif,
    Thanks for your response.I did debug from server side,it has printing content of Data Handler properly.
    Also i have debug request and response messages using TCP/IP monitor(RAD environment has this feature).The response from the server is going proplery.
    But the client side Data Handler is coming null.
    Any advice or solution would be greatly appreciated.
    Thanks,
    Sreeni.

  • Get a reference to an object from a touch

    I have no idea how to get the reference to an UIImageView object from a touch gesture. So far all I know how to do is get a reference to the touch. This is the code I have so far:
    - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
    printf("TOUCH ");
    UITouch *touch = [touches anyObject];
    CGPoint touchPoint = [touch locationInView:self.view];
    Any help would be greatly appreciated

    There may be more elegant methods, but what I did was to find out which sub views bounds covered the coordinates of the selected point. My task was easy since I had a sudoku grid, so converting coordinates into the index into an array of view instances was easy.
    - (unsigned int) setSelectedIndexForXCoordinate:(float) x YCoordinate:(float) y
    int column = (int) ( ( 9.0 * x ) / 320.0 );
    int row = (int) ( ( 9.0 * y ) / 320.0 );
    unsigned int index = ( ( row * 9 ) + column );
    [self setSelectedIndex:index];
    return index;

  • Getting hold of browsers document object, from an applet

    Well, at least that's how i think the problem will be solved.
    The purpose is to insert some text into a hidden field on a form in the html where the applet is embedded.
    so that this can be submitted along with the rest of the information that is entered through that page.
    i've been looking at the AppletContext but i don't think this will provide what's necessary.
    an alternate way of solving this would be to make an http-post with the information, since i prefer using our webserver to perform this.if this is the only way, is there a http-post object i can use for this, from an applet?

    One way is to move the entire form into your applet so that it can do a post and send all the data itself (or vice-versa; avoid using the applet).
    Another option might be to do it in two steps, have your form on one page then post all the details to the next page which contains the applet.
    The only other option I can think of is to use JSObject to call a javascript function. Look at this link http://java.sun.com/products/plugin/1.2/docs/jsobject.html
    Rob.

  • Record Management: get logical document object from physical doc. object

    Hello,
    I'd like to get logical document from physical document (sdok object - stricture containing class and objid).
    There is BAPI for "opposite direction": SDOK_LOIO_PHYSICAL_OBJECT_GET. By this FM I can get physical document's sdok object from logical document's sdok object.
    Can anybody tell me BAPI's name for it?
    I tried SDOK_PHIO_LOGICAL_OBJECT_GET, but this BAPI doesn't exist.
    Best regards,
    Josef Motl

    Josef,
    There are I don't believe there are any bapi's for this. You probably have to do this via ABAP OO. Create an object of the type CL_SRM_DOCUMENT. This is your logical (LOIO) object of your document. You have to enter the documentclass and the objectid of the document. This class has a method get_variant. This variant is your fysical (PHIO) object of the document. Use version and variant 0 so you will get the latest version object of your document.
    If this isn't the answer, can you please explain where do you get the fysical object from if you haven't got the logical first?
    Regards,
    Tjalling-Jan

  • How to execute Custom java data source LOV view object from a common mthd?

    Hi,
    My application contains Custom java data source implemented LOVs. I want to have a util method which gets the view accessor name, find the view accessor and execute it. But i couldn't find any API to get the view accessors by passing the name.
    Can anyone help me iin how best view accessors can be accessed in common but no by creating ViewRowImpl class (By every developer) and by accessing the RowSet getters?
    Thanks in advance.

    I am sorrry, let me tell my requirement clearly.
    My application is not data base driven. Data transaction happens using tuxedo server.
    We have entity driven VOs as well as programmatic VOs. Both are custom java data source implemented. Entity driven VOs will participate in transactions whereas programmatic VOs are used as List view object to show List of values.
    Custom java datasource implementation in BaseService Viewobject Impl class looks like
            private boolean callService = false;
        private List serviceCallInputParams = null;
        public BaseServiceViewObjectImpl()
            super();
         * Overridden for custom java data source support.
        protected void executeQueryForCollection(Object qc, Object[] params, int noUserParams)
            List dataFromService = null;
            if(callService)
                callService = retrieveDataFromService(serviceCallInputParams);
            setUserDataForCollection(qc, dataFromService != null? dataFromService.iterator(): null);   
            super.executeQueryForCollection(qc, params, noUserParams);
         * Overridden for custom java data source support.
        protected boolean hasNextForCollection(Object qc)
            Iterator<BaseDatum> datumItr = (Iterator<BaseDatum>) getUserDataForCollection(qc);
            if (datumItr != null && datumItr.hasNext())
                return true;
            callService = false;
            serviceCallInputParams = null;
            setFetchCompleteForCollection(qc, true);
            return false;
        }Individual screen developer, who want to load data to VO, will do something like the below code in their VO impl class
        public void fetch()
            BaseServiceViewObjectImpl vo = this;
            vo.setCallService(true);
            vo.setServiceCallInputParams(new ArrayList());
            vo.executeQuery();
        }As these custom java data source implemented LOV VOs comes across the screens, i want to have a util method at Base VOImpl class, that gets the view accessor name, finds the LOV VO instance, retrieves data for that. I want to do something like
         * Wrapper method available at Base Service ViewObject impl class
        public void fetchLOVData(String viewAccessorName, List serviewInputParams)
            // find the LOV View object instance
            BaseServiceViewObjectImpl lovViewObject  = (BaseServiceViewObjectImpl) findViewAccessor(viewAccessorName);
            // Get data for LOV view object from service
            lovViewObject.setCallService(true);
            lovViewObject.setServiceCallInputParams(serviewInputParams);
            lovViewObject.executeQuery();
    Question:
    1. Is it achievable?
    1. Is there any API available at View Object Impl class level, that gets the view accessor name and returns the exact LOV view object instance? If not, how can i achieve it?

  • Only edit objects from package ZPACKAGE in local requests

    Hi Experts,
    I was adding a secondary index to a Ztable present in a package ZPACKAGE. When I tried to save in a workbench request, I got the error message "You cannot use request XXXXXX". I then created a local change request where the target system is not mentioned in the transport request. I was able to save the index and later I mentioned the target system. When I tried to release the transport request, I get the message "Only edit objects from package ZPACKAGE in local requests". Kindly suggest what can I do save the changes in a transport request and release it.
    Thanks

    Check out the transport layer and target system for that transport layer. As someone suggested, talk to your basis.
    This is most common when you have the actual table in temp folder but the index stored in Zpackage.
    I would first check my objects package to make sure that they are in right package. If everything @ right place, then i will check the package transport layer and software component then check the 'use access' of the package. if the package is good then check the transport path and target systems for each transport later.

  • Getting Sequence object from pre-step substep of Sequence Call based step type

    How to obtain reference to Sequence object from within pre-step substep of Sequence Call based custom step type?
    Given: new custom step type which based on NI Sequence Call step type. There is Pre-Step substep exist for this step type.
    How to get reference to Sequence object representing Sequence which will run?
    Although there is possible to examine SequenceAdapter and SequenceCallModule properties, it seems redundant since module (Sequence) is already loaded by TestStand ("NI TestStand Reference Manual. Table 3-4. Order of Actions that a Step Performs"   Action #6, while my code is running as Action #13).
    Thanks.
    Misha

    Could you explain what you want to do ?
    Why do you want to get the sequence object within a pre-step substep ?
    I give you some informations but I don't know if it's the better way to do what you want (because I don't know what you want to do with the sequence object).
    If the substep uses the ActiveX adapter :
    You can get the sequence object but you should save the object reference in a StationGlobals variable.
    And you should release the object reference within your sequence when you don't need it any more.
    If the substep uses another module adapter: 
    Get the step module, then the sequence name (module property).
    Then get the sequence object by the sequence name from the sequence file.
    Here are the paths to use for both methods :
    Sequence Name property path : Step.Module.SeqName
    Sequence Object path : RunState.SequenceFile.GetSequenceByName (seqname)

  • Getting intermittent AccessViolationExceptions when accessing stores from Outlook.Stores object

    We have a very strange situation in which we get random AccessViolationExceptions when trying to access stores (in particular our own) via the Outlook.Stores.
    Here's a code snippet of how we're calling this (currently done in our Outlook.ExplorerEvents_ActivateEventHandler handler, and only the first time is is called)
    Outlook.NameSpace ns = ThisAddIn.OutlookApplication.GetNamespace("MAPI");
    Outlook.Stores stores = ns.Stores;
    Outlook.Store store = null;
    int nStoreCount = stores.Count;
    for (int i = 1; i < nStoreCount; i++)
    store = stores[i];
    String name = store.DisplayName;
    store = null;
    When we get to the point of accessing a store via index, we will sometimes get the AccessViolationException, but only sometimes and only (as far as I can tell, since the order isn't always the same from run to run) our message store.
    We originally had this bit of code in our ThisAddin_Startup sequence, but it would actually crash Outlook completely when the exception occurred, so I moved it out of there and it at least now doesn't bring down the whole application.
    MFCMAPI has no trouble opening the message store ever.
    I have seen some references in my research to problems with .net 4.0 and earlier with regards to SynchronizationContext being null, and we are using 4.0 and getting null SynchronizationContext.current values. But we get that when the exception doesn't happen,
    too, so I don't know if that's a red herring. However, this code is a back-port from a newer version of our software that was coded against .Net 4.5, and we don't see the issue there at all. As this is going into a patch, build with VS2010, we can't change
    the target platform.
    I have tried moving the call to worker threads, and I even saw one suggestion of trying to do it in our Outlook.ExplorerEvents_SelectionChangeEventHandler code, but nothing seems to work.
    I should note that after the exception occurs, and the Outlook Explorer window opens and populates, if the user manually clicks our message store node, the MSProviderInit->IMSProvider::Logon sequence fires, and fires without the MDB_NO_DIALOG flag being
    sent in. During Outlook's start-up, we get that sequence of calls several times, but always with the MDB_NO_DIALOG set, so we return MAPI_E_LOGON_FAILED and don't execute the code which creates our IMsgStore object. So the user's manual operation causes our
    IMsgStore to get created and everything is fine. The reason the above code is added is to try to simulate the user's manual action and sort of 'tickle' the store creation process.
    When the AccessViolationException does not occur, we get the full MSProviderInit->IMSProvider::Logon, etc sequence. When it does except, we don't even get our MSProviderInit entry point called. It's almost as if our dll gets loaded and then Outlook loses
    it.
    Any thoughts on this?

    Hi Kevin Delgado,
    >>if somebody knows what these other flags mean/are defined as in the context of the IMSProvider::Logon call, that would be great<<
    Did you mean that the value of ulFlags? If yes, you can refer to the document below:
    ulFlags                               
    [in] A bitmask of flags that controls how the logon is performed. The following flags can be set:
    MAPI_DEFERRED_ERRORS                   
    The call is allowed to succeed even if the underlying object is not available to the calling implementation. If the object is not available, a subsequent call to the object might raise an error.
    MAPI_UNICODE                   
    The passed-in strings are in Unicode format. If MAPI_UNICODE is not set, the strings are in ANSI format.
    MDB_NO_DIALOG                   
    Prevents the display of logon dialog boxes. If this flag is set, the error value MAPI_E_LOGON_FAILED is returned if the logon is unsuccessful. If this flag is not set, the message store provider can prompt the user to correct a name or password, to insert
    a disk, or to perform other actions that are necessary to establish connection to the store.
    MDB_NO_MAIL                   
    The message store should not be used for sending or receiving mail. The flag signals MAPI not to notify the MAPI spooler that this message store is being opened. If this flag is set and the message store is tightly coupled with a transport provider,
    the provider does not need to call the IMAPISupport::SpoolerNotify method.
    MDB_TEMPORARY                   
    Logs on the store so that information can be retrieved programmatically from the profile section, without use of dialog boxes. This flag instructs MAPI that the store is not to be added to the message store table and that the store cannot be made permanent.
    If this flag is set, message store providers do not need to call the IMAPISupport::ModifyProfile method.
    MDB_WRITE                   
    Requests read/write permission.
    Also you can get more detail about IMSProvider::Logon function from link below:
    https://msdn.microsoft.com/en-us/library/office/cc842201.aspx
    Hope it is hlepful.
    Regards & Fei
    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click
    HERE to participate the survey.

  • How can I get the underlying object from the ObjectReference

    Dear friends,
    I think this question has been asked a couple of times. But, I am still wondering if anybody has found an answer to it. Maybe this is some common need ...
    I would like to get the underlying object for which the ObjectReference is
    a mirror For example, I have a class Customer in my application, and I can get an ObjectReference through JDI during runtime. But how can I get the target VM's object which is a real instance of Customer, by which I can invoke methods defined in Customer?
    Thank you so much for any input!
    SunnyDay

    I'll preface this response by admitting this far from an elegant solution, but I did write a function addressing this question, mostly as an exercise.
    If passed an object with an InTextFrame property (Pgf, AFrame, Cell, Fn) that resides in an open document, the function will return the Doc object. Otherwise, it returns undefined.
    function getParentDoc(testObj) {
        //Get object for current page
        try { var curPage = testObj.InTextFrame.FrameParent.PageFramePage; }
        catch(er) {return;}
        //Step backwards to first page in document
        var prevPage = curPage.PagePrev;
        while (prevPage.ObjectValid())
            curPage = prevPage;
            prevPage = prevPage.PagePrev;
        //Compare with first pages of open documents
        var testDoc = app.FirstOpenDoc;
        while (testDoc.ObjectValid())
            if (curPage.id==testDoc.FirstBodyPageInDoc.id) return testDoc;
            testDoc = testDoc.NextOpenDocInSession;    
        return;
    To your PPS: Rather than seeing the native framework grow bloated to address additional features, I would love to see Adobe and other developers publish libraries of useful functions and class extensions.

  • Getting error while passing implicit request object from JSP to JavaBean

    Hi,
    I am getting error while passing implicit object ie( request object)
    from within JSP to JavaBean.
    Following is source for JSP, JavaBean and Error message I am getting.
    vaLookup.jsp Source
    <jsp:useBean id="db" class="advisorinsight.javabeans.DisplayPages"
    scope="request">
    <jsp:setProperty name="db" property="request" value="<%= request %>"
    />
    </jsp:useBean>
    <jsp:getProperty name="db" property="totalrecords" />
    JAVABEAN DisplayPages.java source
    package javabeans;
    import java.io.Serializable;
    import javax.servlet.http.HttpServletRequest;
    public final class DisplayPages implements Serializable {
    private String totalrecords;
    private HttpServletRequest request;
    public void setRequest(HttpServletRequest req){
    this.request = req;
    public java.lang.String getTotalrecords()
    this.totalrecords =
    this.request.getParameter("totalrecords");
    return this.totalrecords;
    public DisplayPages(){
    totalrecords = "";
    request = null;
    error after executing vaLookup.jsp
    [30/Nov/2001 11:56:04:5] info: EXTMGR-006: GXExtensionManager: Extension
    service JavaExtData successfully loaded
    [30/Nov/2001 11:56:04:5] info: EXTMGR-006: GXExtensionManager: Extension
    service LockManager successfully loaded
    [30/Nov/2001 11:56:04:5] info: EXTMGR-006: GXExtensionManager: Extension
    service RLOPManager successfully loaded
    [30/Nov/2001 11:56:04:5] info: REQ-012: thread add
    [30/Nov/2001 11:56:04:5] info: REQ-012: thread add
    [30/Nov/2001 11:56:04:5] info: REQ-012: thread add
    [30/Nov/2001 11:56:04:5] info: REQ-012: thread add
    [30/Nov/2001 11:56:04:5] info: REQ-012: thread add
    [30/Nov/2001 11:56:04:5] info: REQ-012: thread add
    [30/Nov/2001 11:56:04:5] info: REQ-012: thread add
    [30/Nov/2001 11:56:04:5] info: REQ-012: thread add
    [30/Nov/2001 11:56:04:7] info: ENGINE-ready: ready: 10819
    [30/Nov/2001 11:56:46:0] info: --------------------------------------
    [30/Nov/2001 11:56:46:0] info: JSPRunnerSticky: init
    [30/Nov/2001 11:56:46:0] info: --------------------------------------
    [30/Nov/2001 11:56:51:7] error: Exception: SERVLET-compile_failed:
    Failed in compiling template: /va/valookup.jsp, javac error:
    c:\iplanet\ias6\ias\APPS\variabl
    S\va\valookup.java:76: Undefined variable: JSP_8
    db.setRequest(_JSP__8);
    ^
    1 error
    Exception Stack Trace:
    java.lang.Exception: javac error:
    c:\iplanet\ias6\ias\APPS\variableannuity\va\WEB-INF\compiled_jsp\jsp\APPS\va\valookup.java:76:
    Undefined variable: JSP_8
    db.setRequest(_JSP__8);
    ^
    1 error
    at
    com.netscape.server.servlet.jsp.JSPCompiler.compileJSP(Unknown Source)
    at
    com.netscape.server.servlet.jsp.JSPCompiler.compileOrLoadJSP(Unknown
    Source)
    at
    com.netscape.server.servlet.jsp.JSPCompiler.compileInstance(Unknown
    Source)
    at
    com.netscape.server.servlet.jsp.JSPCompiler.compileInstance(Unknown
    Source)
    at
    com.netscape.server.servlet.platformhttp.PlatformHttpServletResponse.callJspCompiler(Unknown
    Source)
    at
    com.netscape.server.servlet.platformhttp.PlatformHttpServletResponse.callUri(Unknown
    Source)
    at
    com.netscape.server.servlet.platformhttp.PlatformHttpServletResponse.callUriRestrictOutput(Unknown
    Source)
    at
    com.netscape.server.servlet.platformhttp.PlatformRequestDispatcher.forward(Unknown
    Source)
    at com.netscape.server.servlet.jsp.JSPRunner.service(Unknown
    Source)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:865)
    at
    com.netscape.server.servlet.servletrunner.ServletInfo.service(Unknown
    Source)
    at
    com.netscape.server.servlet.servletrunner.ServletRunner.execute(Unknown
    Source)
    at com.kivasoft.applogic.AppLogic.execute(Unknown Source)
    at com.kivasoft.applogic.AppLogic.execute(Unknown Source)
    at com.kivasoft.thread.ThreadBasic.run(Native Method)
    at java.lang.Thread.run(Thread.java:479)

    The only thing that I see that looks funny to me is when you pass the request object into the method using <%=request%>, Im not sure whats going to happen here because that is suppose to print the results. Have you tried simply using <%request%>?

  • How to Use AccessibleObjectFromWindow API in VBA to Get Excel Application Object from Excel Instance Window Handle

    I need to get the Excel.application object from a window handle using AccessibleObjectFromWindow. I can't seem to make the code work. First, I successfully search for the XLMAIN windows. Then, when I get a handle, I execute the AccessibleObjectFromWindow
    function. It seems to return a value of -2147467262 in all cases. Therefore, I believe that it is returning an error value. I can't figure out how to determine the meaning of this value.
    If it is an error value, I believe that one or more arguments are in error. My best guess at present is that the GUID argument is incorrect. I have tried two GUID values: {00020400-0000-0000-C000-000000000046} and {90140000-0016-0409-0000-0000000FF1CE}.
    I have seen both used in conjunction with OBJID_NATIVEOM. Neither one seems to work. I really would prefer not to use the second one as it has an Excel major and minor version number. I would hate to have to change this code, if a new minor version appeared.
    The attached code has been commented to show which parts have been shown to work and which not. I'm at my wits end and really need help.
    Thanks
    'This module is located in Access 2010, but this is an Excel question.
    Option Compare Database
    Option Explicit
    ' Module-Level Declarations
    'The GetDesktopWindow function and FindWindowEx function work just fine.
    Public Declare Function GetDesktopWindow Lib "user32" () As Long
    Public Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" _
    (ByVal hWnd1 As Long, _
    ByVal hWnd2 As Long, _
    ByVal lpsz1 As String, _
    ByVal lpsz2 As String) _
    As Long
    'I'm not getting the expected output from this function (see below)
    Private Declare Function AccessibleObjectFromWindow& Lib "oleacc.dll" _
    (ByVal hwnd&, _
    ByVal dwId&, _
    riid As GUID, _
    xlwb As Object)
    Type GUID
    lData1 As Long
    iData2 As Integer
    iData3 As Integer
    aBData4(0 To 7) As Byte
    End Type
    Function ExcelInstances() As Long
    ' Procedure-Level Declarations
    ' Value of OBJID_NATIVEOM verified by checking list of Windows API constants _
    on this site: http://www.lw-tech.com/q1/base.htm
    Const OBJID_NATIVEOM = &HFFFFFFF0
    Dim hWndDesk As Long 'Desktop window
    Dim hWndXL As Long 'Child window
    Dim objExcelApp As Object 'Final result wanted: Excel application object
    'Following variable (xlapp) to be set by AccessibleObjectFromWindow function
    Dim xlapp As Object
    Dim IDispatch As GUID 'GUID used in call to AccessibleObjectFrom Window function
    'Set up GUID to be used for all instances of Excel that are found
    Dim tmp1 As Variant 'Return value from AccessibleObjectFromWindow
    ' Executable Statements
    SetIDispatch IDispatch
    IDispatch = IDispatch
    'Get a handle to the desktop
    hWndDesk = GetDesktopWindow 'This seems to work
    Do
    'Get the next Excel window
    'The following statement seems to work. We are finding and counting _
    correctly all the instances of Excel. hWndXL is non-zero for each _
    instance of Excel
    hWndXL = FindWindowEx(GetDesktopWindow, hWndXL, "XLMAIN", vbNullString)
    'If we got one, increment the count
    If hWndXL > 0 Then
    'This works. We correctly count all _
    instances of Excel
    ExcelInstances = ExcelInstances + 1
    'Here is the problem. The following statement executes and returns a value of _
    -2147467262. xlapp, which is passed by reference to AccessibleObjectFromWindow, _
    is set to nothing. It should be set to the object for Excel.application. _
    I believe that this value is not an object. I tried to reference tmp1. in the _
    immediate window. There was no Intellisense.
    'I think that the function in returning an error value, but I can't figure _
    out what it is. I believe that AccessibleObjectFromWindow returns error _
    values, but I don't know where to find their values so I can interpret the _
    function's results.
    'As best I can tell, the hWndXL parameter is correct. It is the handle for _
    an instance of Excel. OBJID_NATIVEOM is set correctly (see constant declaration _
    above). xlapp is passed by reference as a non-initialized object variable, which _
    will be set by AccessiblObjectFromWindow. IDispatch may be the problem. It is set _
    as shown below in the procedure SetIDispatch(ByRef ID As GUID). This procedure _
    appears to work. I can see that IDispatch is set as I intended and correctly _
    passed to AccessibleObjectFromWindow.
    tmp1 = AccessibleObjectFromWindow(hWndXL, OBJID_NATIVEOM, IDispatch, xlapp)
    'Need to write code to test tmp1 for error. If none, then set objExcelApp = _
    object. Also, I exect xlapp to be set to Excel.application
    End If
    'Loop until we've found them all
    Loop Until hWndXL = 0
    End Function
    Private Sub SetIDispatch(ByRef ID As GUID)
    'Defines the IDispatch variable. The interface _
    ID is {90140000-0016-0409-0000-0000000FF1CE}.
    'NOT USING {00020400-0000-0000-C000-000000000046}, _
    which could be the problem
    '9 is release version - first version shipped (initial release)
    '0 is release type - retail/oem
    '14 is major version
    '0000 is minor version
    '0016 is product ID - MS Excel 2010
    '0409 is language identifier - English
    '0 is x86 or x64 - this is x86
    '000 reserved
    '0 is debug/ship
    '000000FF1CE is office family ID
    With ID
    .lData1 = &H90140000
    .iData2 = &H16
    .iData3 = &H409
    .aBData4(0) = &H0
    .aBData4(1) = &H0
    .aBData4(2) = &H0
    .aBData4(3) = &H0
    .aBData4(4) = &H0
    .aBData4(5) = &HF
    .aBData4(6) = &HF1
    .aBData4(7) = &HCE
    End With
    End Sub
    DaveInCalabasas

    I don't think you can return a reference to Excel's main window like that as you are attempting to do.
    Ref:
    http://msdn.microsoft.com/en-us/library/windows/desktop/dd317978(v=vs.85).aspx 
    It's relatively straightforward to return any workbook's window in any given instance, and in turn it's parent Excel app. Try the following and adapt as required (and include error handling) -
    Option Explicit
    Private Declare Function FindWindowEx Lib "User32" Alias "FindWindowExA" _
    (ByVal hWnd1 As Long, ByVal hWnd2 As Long, ByVal lpsz1 As String, _
    ByVal lpsz2 As String) As Long
    Private Declare Function IIDFromString Lib "ole32" _
    (ByVal lpsz As Long, ByRef lpiid As GUID) As Long
    Private Declare Function AccessibleObjectFromWindow Lib "oleacc" _
    (ByVal hWnd As Long, ByVal dwId As Long, ByRef riid As GUID, _
    ByRef ppvObject As Object) As Long
    Private Type GUID
    Data1 As Long
    Data2 As Integer
    Data3 As Integer
    Data4(7) As Byte
    End Type
    Private Const S_OK As Long = &H0
    Private Const IID_IDispatch As String = "{00020400-0000-0000-C000-000000000046}"
    Private Const OBJID_NATIVEOM As Long = &HFFFFFFF0
    Sub test()
    Dim i As Long
    Dim hWinXL As Long
    Dim xlApp As Object ' Excel.Application
    Dim wb As Object ' Excel.Workbook
    hWinXL = FindWindowEx(0&, 0&, "XLMAIN", vbNullString)
    While hWinXL > 0
    i = i + 1
    Debug.Print "Instance_" & i; hWinXL
    If GetXLapp(hWinXL, xlApp) Then
    For Each wb In xlApp.Workbooks
    Debug.Print , wb.Name
    Next
    End If
    hWinXL = FindWindowEx(0, hWinXL, "XLMAIN", vbNullString)
    Wend
    End Sub
    'Function GetXLapp(hWinXL As Long, xlApp As Excel.Application) As Boolean
    Function GetXLapp(hWinXL As Long, xlApp As Object) As Boolean
    Dim hWinDesk As Long, hWin7 As Long
    Dim obj As Object
    Dim iid As GUID
    Call IIDFromString(StrPtr(IID_IDispatch), iid)
    hWinDesk = FindWindowEx(hWinXL, 0&, "XLDESK", vbNullString)
    hWin7 = FindWindowEx(hWinDesk, 0&, "EXCEL7", vbNullString)
    If AccessibleObjectFromWindow(hWin7, OBJID_NATIVEOM, iid, obj) = S_OK Then
    Set xlApp = obj.Application
    GetXLapp = True
    End If
    End Function
    Note as written if an instance does not have any loaded workbooks a reference will not be returned (though a workbook can be added using DDE, but convoluted!)
    FWIW there are two other very different approaches to grab all running Excel instances though something along the lines of the above is simplest.
    Peter Thornton

  • Getting information about an object from JList

    Hi
    I have created a movie application and i have a JList displaying all registered movies, it uses a DefaultListModel to display these.
    I want to be able to click on an element in the JList and then push a button called "Show movie details" to display all information about the selected movie.'.
    Every new movie is added to the DefaultListModel as an object with "Titlle", "Genere" etc. If someone click on a movie, what do i do to get information about which object that was clicked. All i can see is that integers can be returned with the getSelectedIndex/Value methods. If i use one of these methods to get the object from the DefaultListModel, that would work i guess, but what when someone deletes a movie in the middle of the JList, then the indexes wouldnt match.
    Can someone help me out here? :)

    I get a big fat exception when trying to cast the returned object to a Movie object which im using.
    Exception in thread "AWT-EventQueue-0" java.lang.ClassCastException: java.lang.S
    tring cannot be cast to Movie
    ...sure that this is the way to do it? If so, what am i doing wrong..

  • Problem in getting the function template object from the repository.

    Hi all,
    I have created a par file. I have a JCO connection in that. I am facing problems in getting the function template object from the repository. This thing is running successfully when i try to deploy it in Tomcat. But i am facing problems when i try to deploy it in SAP EP 6.0.
    Below is statement which is giving error after being deployed to SAP EP6.
    This is executing fine when executed in Tomcat Server.
    // getting the object of function template
    IFunctionTemplate functionTemplate =
    aRepository.getFunctionTemplate("YADDNEWUSER");
    Note : YADDNEWUSER is the name of the RFC which I am calling from my JAVA Code.
    Thanks in advance,
    Divija

    This sounds like a bug in the smart upload code. I have used this stuff before, but it's probably an older version, so maybe they broke something. Enumerations aren't usually guaranteed to keep things in any particular order. I would say for now, make a method to take the enumeration and a param name to find the value. And write to the JSPSmart people.

  • How to get stylesheet object from JAVA RESOURCE stored in DB

    Hi,
    I stored a xslt file in the database and have a JAVA RESOURCE file now. How can i get a stylesheet object from this resource file?
    I took the following class to get an impression how to get the contents of the resource but -although the name of the resource was spelled correctly- i got a file not found exception.
    Whats wrong?
    public class PrintRessource {
    public static void print (String p_ressource){
    try {
    Class c = PrintRessource.class;
    System.out.println(c.toString());
    InputStream file = c.getResourceAsStream(p_ressource);
    if (file == null)
    throw new FileNotFoundException("XSLT file not in DB");
    byte[] buffer = new byte[4096];
    int bytes_read;
    while ((bytes_read = file.read(buffer)) != -1)
    System.out.println(new String(buffer, 0 , buffer.length));
    catch (Exception exp) {
    System.out.println(exp);
    Thanks

    The code works as is. I just forgot to add the slash in front of the Resource file name.

Maybe you are looking for

  • Snow Leopard 10.6.2/10.6.3 + Xserve + Time Machine = crash

    We have an Xserve (Xserve 2.1) with two 1TB internal drives. Drive 1 is configured as the root drive and has users' home directories. Drive 2 is configured as a backup. Under Leopard, we used Time Machine to backup drive 1 to drive 2. All worked well

  • App problem urgent

    hi i am making pmt to vendor through app,while doing proposal run,the message is displaying that proposal has been schedule and job was cancelled can anybody help me guna

  • I cannot connect to the internet in my home with my new 4g itouch and new d link router

    I have gone to the router manufacture and walked through the set up, no luck.  I tried the troubleshooting pages for the itouch.  I am still shut out.  I see the ssid and the lock I use the password still no luck.  It works in other locations, but do

  • SAP MDG - How to activate user settings for Dropdown box Change request?

    Hello Expert, I have a question related to Hide DropDown Box Change request. When i save change request via collective processing, Change request Dropdown box is displayed. When, i select Change request dropdown list, only change request description

  • Truncate text after first line in TextFlow

    I have a TextFlow object which is rendered in a Sprite with multiple lines. For a compact display I now want to display only the first line, followed by 3 dots (...). I didn't find a good approach so far.