WinAPI - Determine if a window has maximize/restore capability - java

Problem: Determining if a window (by, say, hWnd) has the capability of being maximized or restored. Purpose of this is to programmatically send maximize/restore events to windows (for automation) but exclude windows which can't handle it.
Please consider the following two example windows while trying to determine this from GetWindowLong with GWL_STYLE:
a) The Discord client app (it is built with Electron). It has styles:
WS_CAPTION
WS_SIZEBOX
It does NOT have styles:
WS_SYSMENU
WS_MAXIMIZEBOX
This window does display a restore/maximize button and behaves properly when SW_MAXIMIZE/SW_RESTORE are posted to it.
b) The "Are you sure you want to quit?" prompt in InteliJ IDEA. It has styles:
WS_CAPTION
WS_SIZEBOX
WS_SYSMENU
It does NOT have style:
WS_MAXIMIZEBOX
This window does NOT display a restore/maximize button and does NOT behave properly when SW_MAXIMIZE/SW_RESTORE are posted to it (it crashes the whole IDE).
So, given these two examples, the following facts are true:
1) A window with WS_SIZEBOX style may not respond to SW_MAXIMIZE/SW_RESTORE messages properly (wasn't designed to);
2) A window without WS_SYSMENU nor WS_MAXIMIZEBOX may still respond to SW_MAXIMIZE/SW_RESTORE messages properly (draws system menu and/or buttons itself in a non-standard way)
3) Both of them have a native system menu that opens via title bar secondary-click and they correctly list maximize/restore as enabled or disabled (whatever matches their capability).
Given those two facts, how do I actually determine if a window can or cannot handle being maximized/restored? It seems it is not possible from window style alone, but I can't find anything in the Win32 API WinAPI to do this.
Note that I am deciding on whether to send SW_MAXIMIZE/SW_RESTORE by calling GetWindowPlacement and checking the showCmd.
Also note that I am using Java/JNA but I understand C++ or C# perfectly fine if you want to share code snippets.

I found that as a last resort I can use GetSystemMenu > GetMenuItemInfo to check if either Restore or Maximize system menu entry is enabled. So this is a decent fallback if the window has no WS_MAXIMIZEBOX style for whatever reason.

Related

Selenium WebDriver: Multiple Drivers - Getting a CSS property from one when focussing on it changes it in the other

This question is conceptual, and I am asking on this help forum in order to look for a lead to go off and research, and will not contain any code examples other than one to demo what I am using to grab the element value described below, here is some background:
The test I am writing involves signing in to the same application using two driver sessions each of which open a webdriver chrome window. Each one logs in to our app as a different user, and then from one, you can see the "online/offline" status of the other.
We use one class of methods for the first session, and another class of methods for the second session, and if a feature file title appears in a third class containing a LinkedList of strings, then the system knows to open the second session, and we then call methods in the relevant class to run jobs in the appropriate window.
In the current test case I am creating, the objective is to assert in a window we shall call "A", that the element being checked has a specific CSS property, namely its color property. It is grey when the other window that we shall call "B" does not have focus, and it is green, meaning online, when it does have focus, and is logged in.
The logged in side I can take care of, and manually I can see that it is working, but after this log in, when I use from the class that runs commands for window "A" the following line, directly after the last line that directs window "B" to have focus and do something, then it writes the value for "offline" in to the variable shown, as the window "B" has had to lose focus in order to check the element in window "A".
String color = seleniumClient.getWebDriver().findElement(By.xpath("//div[#id='user-content-button']/span/span")).getCssValue("background-color");
I am not able to influence the development of our app, as I am a QA, but I am asking if anyone knows how to maybe freeze the state of the chrome session for window A showing window B to be online before I run the above line, or any other way that I can get my test to see the correct state when the focus is not on the window "B"
Thanks.

How to change the color of the Title bar when running a GUI program?

I want to change the color of the title bar and also the Java icon on the upper left of the frame, so I can make my program (GUI) look better. Is there a simple way to change it?
I'm not sure how useful this observation is, but under the X Window System (e.g. on Linux), the titlebar and the icons in it aren't usually under the control of the application, they're “decorations” under the control of the window manager (WM). I'm not sure exactly how this might impact a Java program — they might be able to use undecorated windows and add their own equivalent — but it's equally possible that what you want to do simply isn't possible (without an inordinate amount of effort) on any platform.

Capturing events in X11 even after the loss of focus

I am trying to develop an application which responds to multiple digital pens (IRIS Pens) so that if any of the pen writes on paper; I relay the output to a single screen. Thus making a multi-input whiteboard for myself.
In Ubuntu these pens are recognized as mouse and thus can be handled in a similar manner as mouse events are handled.
So now what I plan to do is to handle these events in C/C++ using XLib and pass these events to a Java Swing application using JNI callback. I am able to do this but when the X11 window looses focus no events are transferred to the Swing frame. I also tried to use the root window in X11 but it does not seem to work.
Any help would be really appreciated. Thanking you in advance.
How about maximizing the C/X11 window in front of the Java one, and making it transparent? You should be able to see the Java window while still focusing on the C/X11 one.
Since you are using Ubuntu, you can achieve this using the "Opacity, brightness and saturation" plugin for Compiz. It is in the compiz-plugins-main package, and you can activate it with Compiz Settings Manager (from the compizconfig-settings-manager package). When you activate the plugin, alt+wheel is bound by default to change the transparency of the focused window.
Try reading the mouse directly. I don't remember the exact location, but you should find it in something like '/dev/input/mouseX', where X is the number of your device, ranging from 0 to n-1 devices..
When you read the packet, your application should block until the mouse moves and then your read function will return a raw mouse packet which describes the delta (which is probably more useful then the screen coordinates, in your case) and the mouse button statuses.
The raw packet can be decoded as described here: http://www.computer-engineering.org/ps2mouse/
Create a modal dialog and set it to XmDIALOG_SYSTEM_MODAL (the actual name of the property depends on your toolkit: Motif, Gtk, Qt, ...). Dialogs like this block the whole display and can never loose focus.
The drawback is of course that you can't do anything else while this dialog is on the screen.
This entry in the X11 FAQ might help.

How to make button highlighted or pale in java swing properly?

I'm using Swing with default UI (without any special skins).
How to make some buttons/textfields more bright or more pale? It means the user is expected/not expected(although not completely disabled) to press the button.
Example: user had changed a field - "save" button becomes more bright (for example, green). Status is "compilation failed" - "execute" button is pale (although user can still execute previous version of something). User filled in "password" field - he expected to fill in "password confirmation" - so it becomes bright.
I have: {normal, disabled, invisible}
I want: {bright, normal, pale, disabled, invisibe}.
How to make it properly, without hacking with drawing things, with separation of content and presentation? I want it to look well even if user overridden colour settings in the system. Should I use some other toolkit?
I expect something like I set hints for the given control, and then skin read hints and applies additional look and feel options (such as brighter background) without me dealing with concrete colours. May be one skin will use other background and some other skin will use other font for this effect. Like in enabled/disabled case, but more flexible.
Just use setBackground() to change the color to match the component's status. Maybe even create a Custom Component that has a method to change the status and it knowns which color matches that status.
I'm not sure that I see the value in what you're trying to achieve from the examples that you've provided. Is it possible that users could get confused about how the application works if you give them functionality that differs from their expected user experience?
If the user hasn't yet changed a field, the save button could be completely disabled. What's the value in being able to save if there have been no changes made. Alternatively, if you still dead set on making this distinction, can you do it in another way? Perhaps a visual queue, an icon next to the field that's changed, cell highlighting, or a * appended to the end of the text on the window name to show that there are unsaved changes in a window, perhaps?
From a purely user experience perspective, I don't think you want to go messing with the way people expect applications to behave unless you have a really good reason!

how to handle focus lost and focus gain event using "shift + tab" and "tab"?

I want the ability to gain the focus on the next focusable component on clicking tab and to get the focus back on the previous component on shift + tab. So need a help on how to achieve the same.
thanks
Unless I misunderstand your question, what you describe is the default behavior of java Swing on Windows and probably on Linux too. Mac OSX handles tab focus a bit differently (not all elements are reachable by default).
If you want to customize the keyboard focus order and things like that, the default API to do that is via java.awt.KeyboardFocusManager.

Categories