4

I'm trying to simulate keyboard events to a Java Application running on Firefox, checking with Spy++ I could see that the keyboard events were been sent to the handler ID X, I check it using Spy++ too and it returned that it was a "window" called "SunAwtFrame", but I can't get this window handler dinamically at all, I tried a lot of things, like FindWindow(), checking the process modules, etc.

Someone knows if is possible to get that?

Here is the firefox window, with the Java running inside it: enter image description here

And the last coded I tried was:

[DllImport("user32.dll", SetLastError = true)]
        static extern IntPtr FindWindow(string lpClassName, string lpWindowName);

IntPtr hWnd = (IntPtr)FindWindow("SunAwtFrame", "TibiaME - Web Client - XHTML - Mozilla Firefox");

It returns 0, if I remove the first parameter, it gets the Firefox handler.

Kyore
  • 388
  • 2
  • 7
  • 29

2 Answers2

1

Unfortunately, You cannot do it with windows API!

In this case, You can use Windows OS APIs to get top-level window's handle only(Firefox window in this case - Use Spy++).

All Enterprise libraries such as Java, Qt and many other frameworks expose control handles and other properties when each control needs to communicate with Windows OS. This behaviour can only expose from inside of framework to out; Otherwise, You cannot access that control(s).

(i.e) When we create a window with four controls in Java and run that application in Windows OS; We can access only top-level window and other controls manages by Java and do not expose their properties to Windows OS.

Solution(Probably): You can use Java Framework to access and manage properties of that window in FireFox. google it.

Ehsan Mohammadi
  • 415
  • 4
  • 15
  • I used Spy++ and it showed me that the messages are been sent to the "SunAwtFrame", that's why I'm trying to simulate the keyboard press in that part, because sending to the firefox window handler, it just don't do anything. About this solution, the Java Framework one, that would be possible to be used only in a java application right? Or there is some way to work wit that on C#.net ? – Kyore Nov 22 '15 at 19:46
  • Message queue send many information about a message. (i.e handle of target child control or object (Private or Public)). You cannot spy++ firefox internals; So, you don't know how it works. Try using Java framework to access more options (I wrote above). – Ehsan Mohammadi Nov 23 '15 at 08:21
0

The FindWindow approach did not work for me but this did.

 Process[] pList = Process.GetProcessesByName("appName");

 if (pList.Count()>0)
 {
    handle = pList[0].MainWindowHandle;
 }
Dawit
  • 591
  • 8
  • 24