Getting a control position of a Java GUI application - c++

Having a Java GUI application, I need to get the location of one of its buttons, so I'll be able to simulate a mouse click.
What is the most straightforward way of doing this from a C++/WinAPI application?
I need to embed this solution into a downloadable application, so preferably it should not require using a multimegabyte library.
For example, having an app similar to this (screenshot from Wikipedia):
How can I get the RECT of the button?

Related

Trying to write a c++ console program to change a setting controlled by a windows checkbox

Is it possible to create a keyboard shortcut to switch between the monitor and portion selection of this wacom preferences window, via a c++ console program?
Sorry if this is poorly worded, I've had trouble trying to find the right words to search for ways to do it.
I think it should be possible, although a bit tedious. You should be able to use the Windows API, and try to EnumWindows/EnumDesktopWindows to identify the respective application Window, and its respective controls (which are also Windows).
You should identify the window title, and class ids, for the app window, and the checkbox button controls, then when you enumerate through all the desktop windows, you can identify the ones you are interested in.
Then you can use the SendMessage() API to send messages to the controls (Windows) of interest to manipulate them.
It's a bit tedious, but sounds possible.
An example of use here to get an idea:
http://www.cplusplus.com/forum/windows/25280/

How to simulate a mouse click without interfering with actual mouse in Python

I've made a simple click bot to automatically play an android game on my Windows PC. It currently identifies when certain things change on the screen then moves the mouse and clicks the correct button.
Currently I am using the following win32api functions to achieve this:
Win32api.SetCursorPos(Position)
Win32api.mouse_event(winn32con.MOUSEEVENTF_LEFTDOWN,0,0)
Win32api.mouse_event(winn32con.MOUSEEVENTF_LEFTUP,0,0)
These work great however when I use the bot it takes over my computer's mouse and I basically have to let it run. Is there anyway I could simulate a click without it actually using my mouse, or is there a way I could isolate the bot on one of my other screens and be able to work freely on the other?
There is a lib specific for deal with user interaction components and periferics: pyautogui
Here, is a short and easy to try documentation for performing/simulating mouse click DOWN & UP
https://pyautogui.readthedocs.org/en/latest/mouse.html#the-mousedown-and-mouseup-functions

Usage of software input panel in DirectX based app

I am trying to add text input functionality into existing DirectX application that was being ported to Windows Store / Phone 8.1. The problem is that I can't even get the sample code provided by microsoft in this article to compile:
http://msdn.microsoft.com/en-us/library/windows/apps/jj247546%28v=vs.105%29.aspx
I am using Universal App project as a base and I have no acces to Windows::Phone::UI::Core (there is no Core namespace at all!)
I was trying to add dummy textbox and hid it somewhere but without luck as to appear the software keyboard you need to focus the textbox - the moment it receives focus it appears on the screen (we draw our own controls so I don't want the system one) despite the fact being set to Transparent, both foreground and background and width to 0.
How can I manipulate SIP to show/hide and retrieve input from the keyboard without having to hack my way through XAML and stuff?
On Windows Phone (but not Windows) apps can request the InputPane hide and show programmatically by calling InputPane.TryShow and TryHide.
If you want the InputPane to show automatically then you need to set focus to a control which identifies itself as a text control to the automation system (see the Touch Keyboard documentation on MSDN. Windows Phone works essentially the same as Windows 8 here).
There are two ways to do this in a DirectX app:
As the other thread describes and as you've tried, you can use a Xaml TextBox on top of your DirectX surface. This has the advantage of being easy as the Xaml controls already implement the accessibility and IME interfaces needed for full text support. It has the disadvantage of being external to the DX scene so it can require some care to place it nicely. You can't really hide the TextBox and divert the input, but need to use the TextBox for input. I prefer to do the full interactive form in Xaml rather than trying to merge a single TextBox into a full scene.
The other option is to implement a text control in DirectX. Windows uses the UI Automation API to identify and interact with text controls. If you implement the TextPattern and focus for your control within DirectX then the keyboad will automatically invoke when the user sets focus to it. There's a sample at Input: Touch keyboard sample which demonstrates the necessary interfaces within a custom Xaml control context. It won't apply directly to DX, but will give the general idea. The UI Automation Provider Programmer's Guide has more in depth information on implementing UI Automation interfaces. Again, while these docs target Windows they will also apply to Windows Phone.
I'm not sure exactly which code didn't compile for you. The linked pages are a bit out of date (SwapChainPanel is now preferred over SwapChainBackgroundPanel), but the classes and techniques involved should be valid for Windows Phone Runtime apps.

Can i use Global System Hooks to capture which file was clicked on?

I am new to Windows programming, mostly done Java(Java SE, Java ME, Android, Java EE), so be detailed and gentle.
I want to capture "the name of the file/path that was clicked in windows, like clicking a file on the desktop"?
Further research http://www.codeproject.com/Articles/6362/Global-System-Hooks-in-NET, which is a small c#/c++ nice app that uses Global System Hooks, to capture mouse events such as coordinates,clicks,etc.
So what is the right API or Global System Hook that captures events on file icons?
There is no single API that provides that level of detail.
The WH_MOUSE and WH_MOUSE_LL hooks of SetWindowsHookEx(), or the WM_INPUT message delivered by RegisterRawInputDevices(), can tell when the mouse is being intereacted with, and the GetCursorPos() function can tell you where the mouse cursor is located onscreen at the time of a click, but it cannot tell you what it is clicking on. You have to figure that out manually.
For instance, the Desktop is implemented as a ListView control, so you can use the WindowFromPoint() and GetDesktopWindow() functions to check if the mouse is located at coordinates corresponding to the desktop window itself instead of an application window, and if so then use the LVM_HITTEST and LVM_GETITEM messages to determine which icon onthe desktop is being clicked on and extract its display text. Then use the SHGetDesktopFolder() function and the IShellFolder interface, or the SHParseDisplayName() function, to parse that text and see if it returns a PIDL that represents a path/file, and if so then use SHGetPathFromIDList() to get the actual path/file name.
If you want to do the same thing with the Windows Explorer app, it gets a bit more complicated. Use WindowFromPoint(), GetWindowThreadProcessId(), OpenProcess(), and EnumProcessModules() to determine if the mouse is over the Windows Explorer app. However, its UI changes from on Windows version to the next, but the jist is that you have to manually locate the focused control via AttachThreadInput() and GetActiveWindow(), check if it is a TreeView/ListView control, and if so then use control-specific messages to get information about the item/icon underneath the mouse cursor coordinates, and use IShellFolder again to figure out what the text of that item/icon actually represents.
Shell programming is very complex system and not for the feint of heart to interact with. So you need to ask yourself, why do you need this information in the first place?

How does the draggable crosshair in Process Explorer work?

There is a feature in Sysinternal's Process Explorer that allows a crosshair to be dragged from the application to a control in any other application you are running and highlights said control.
Does anyone know how this was achieved or if there is a .NET/C++ library out there that can be reused?
Using Win32 API
GetCursorPos: to get the cursor position (maybe .NET has its own function to do that)
WindowFromPoint: to get the handle of the window from a specific point in the screen
more info