2 Replies Latest reply: Aug 21, 2006 2:09 PM by 800556 RSS

    JAWIN AND FindWindowEx API

    843804
      I seek help on how can I write some code using jawin to do the
      following task, I need my code to act as barcode reader driver to take data from java
      application to focused native application on position of cursor. My aim is to integrate the
      existing systems (Developed using native language and neither source code
      nor API are available) with my application developed using java.

      This is a scenario:
      some number will be stored in the javacard smartcard. when card
      inserted take this number from the card to java application and then send them to native
      application which currently has fucus.java application will be all the
      time running on the back like any service in the system.
      I managed to do all task except one of transferring data from java to
      any native application.
      I want my application to replace barcode reader apart from getting
      input from the barcode in put will come from the card.
      Action sequence:
      1. Student arrive to the library
      2. Student bring his card to the Librarian
      3. Librarian insert the card into card reader
      4. Student Identification number appear on the edit box of
      the Libaray system window ( Native application)

      I tried to use jawin to write method for doing that task but I have problem on using
      FindWindowEx API. look my code below
      public void setText(String text) throws Exception {
          FuncPtr wndText = null;
          FuncPtr getWnd = null;
          FuncPtr wndEx = null;
          try {
       //GetForegroundWindow API: Get the handle of the window that currently has focus
            getWnd = new FuncPtr("USER32.DLL", "GetForegroundWindow");
      //FindWindowExW API: Find the Edit inside the window and returns the window handle for the edit box
            wndEx = new FuncPtr("USER32.DLL", "FindWindowExW"); 
      //SetWindowTextW API: set the text to edit box of native aplication
            wndText = new FuncPtr("USER32.DLL", "SetWindowTextW");
      
            int focus = getWnd.invoke_I(ReturnFlags.CHECK_FALSE);
            int edit = wndEx.invoke_I(focus,ReturnFlags.CHECK_FALSE); //help me on this line if   //the rest are ok
            wndText.invoke_I(edit, text, ReturnFlags.CHECK_FALSE);
          }
          catch (COMException e) {
            // handle exception
            e.printStackTrace();
            throw e;
          }
          finally {
            if (wndText != null) {
              try {
                wndText.close();
              }
              catch (COMException e) {
                // handle fatal exception
                e.printStackTrace();
                throw e;
              }
            }
          } 
        }
      Any help me on this
        • 1. Re: JAWIN AND FindWindowEx API
          843804
          I personally use NativeCall, which is an open source library that interfaces into JNI. This is the function call I use to find a control within a window:
               public static Integer FindWindowEx(Integer parentHandle, Integer childAfter, String lclassName, String windowTitle) {
                    int tempVal;
                    
                    IntCall cT = new IntCall("user32", "FindWindowExA");
                    tempVal = cT.executeCall(new Object[] {parentHandle, childAfter, lclassName, windowTitle});
                    cT.destroy();
                    
                    return new Integer(tempVal);
               }
          To find a control named "Radians" on the Calculator, and I happen to have the handle to the Calculator window already, I can do the following command:
          radianButtonHandle = FindWindowEx(calculatorHandle, null, null, "Radians")
          Then in theory, all you would have to do is copy the barcode into the clipboard, set focus to the textbox in the native app, and paste it in. To do the keystrokes for pasting, use the Robot class which is part of AWT (there's tons of tutorials on how to use it.)

          Hope that helps.
          • 2. Re: JAWIN AND FindWindowEx API
            800556
            JAWIN project may be called "Much Ado About Nothing"!
            They declare much more than can be done with it.