Desktop app noob question: best cross-platform library that can listen for window-change events (focus, lose focus, etc)? - user-interface

I've only ever done server, web, and database programming, never any desktop programming. I now want to learn and have a small project I want to attempt, but am not sure which library/framework to use.
I'd like to create a small cross-platform app that runs in the system tray (and whatever the OSX equivalent is), and listens for changes to windows on the Desktop. Specifically:
Windows XP, Vista, 7, Gnome, KDE, OSX. BSD, Android, and/or iOS would be nice too but not required.
Listens for when any window gains focus, loses focus, is opened or closed, or if the window title changes (for example when switching tabs in a tabbed browser). Any other information it can scrape from the window would be useful as well.
Can store these events, preferably in an embedded database like SQLLite.
The lighter-weight the better.
Includes an options GUI accessible via a right-click menu from the system-tray icon.
Preferably FOSS, but if you know any non-FOSS please list too.
Is there a single library or framework that can do all that across multiple platforms? QT? Python? Java? Something else? TIA.

Almost any GUI framework can easily let you know when your own application gains or loses focus (or the other operations you mention). However, listening for these events for other arbitrary applications is definitely platform-specific and may or may not even be possible.
One framework for doing this on Windows is the CBT callback hook. See the question CBT Hook not working in Windows Vista for information about possible limitations on using this technique.

Related

Win32 Detect if my window is running in Dark Mode on Windows 10+

I would like my Win32 application to be able to detect if a window is actually running in Dark Mode. I know about this answer, which suggests reading a registry key for the user setting. That's fine, and it works for me. But many applications do not honor that setting.
I would like to find out which appearance my actual window has. My program is a 3rd-party plugin that runs inside an application I do not control. Currently that host application does not support Dark Mode on Windows, but a new version could potentially start supporting it. I would like to allow my program to detect if it does. I would also like to continue to support older versions of the app, without having to resort to a manual list of versions that do or don't support Dark Mode.
For readers that know something about macOS APIs, I am hoping to find something similar to the effectiveAppearance property on macOS views.
Individual windows do not have light/dark modes, as far as the OS is concerned, so there is nothing you can query for that. A window doesn't report back to the OS whether or not it is honoring the user's display setting. If it honors the user's setting, it simply draws its UI using appropriate colorings as it deems fit. If it don't honor the user's setting, it simply draws itself using whatever normal/custom colors it wants.

How to reliably give a window focus?

I need to give a Chrome window focus over all other running applications. Javascript's window.focus() only gives focus over other windows of the same browser.
When my Chrome extension executes:
chrome.windows.update(theWindowId, {focused: true});
I experience different behaviors on Mac versus Windows 7:
On a Mac, the intended window gains focus over all other running applications.
In Windows 7, the intended window gains focus only over other Chrome windows, but not over other running applications.
Does anyone know a way to reliably give the intended window focus over all applications on Windows?
Unfortunately, the chrome.windows.update() API is still very unreliable in how it handles window focus cross-platform. I've even noticed inconsistencies at various times in the same platform. A lot of this has to do with the varying security policies that different OSes use for window management, so there really isn't much that you can do about it in terms of how it functions for the end user who may or may not have applied the appropriate registry hack.

Is it possible to display "on screen" text on Windows OSes without an actual window?

This library does exactly what I am talking about on Linux systems: http://ichi2.net/pyosd/
My knowledge of Win32 API is limited but it seems to me that unless you create a window and enter the win32 main loop, you cannot do it. Some Googling also confirmed that.
Even so, are they newer GUI frameworks or technologies that would make it happen on windows?
Thanks
You don't need no stinkin' GUI frameworks. You can either:
Draw directly on the desktop. Of course, this is not generally considered a good idea, since it's mucking around with the internals of another application. Drawing this way is also quite fragile because your changes are erased each time the desktop repaints itself.
Create a transparent, layered window that you draw onto, which will appear over the desktop. If you specify that this window should be a top-level window, you could also have it appear over all of the other windows on the desktop.
There is absolutely nothing that forces windows to be rectangular gray-colored boxes, and since each window provides a device context that you can draw into, you can let your imagination run wild.

How to hide an application based on the NetBeans Platform?

I'm not referring to a GUI-less application. I'm trying to have an application based on the NetBeans platform as a System Tray application. I was able to do the System Tray part quite easy but I'm having issues trying to figure out how to Hide/Show the GUI. I'll keep looking in the API meanwhile.
Any ideas?
WindowManager.getDefault().getMainWindow().setVisible(true/false) should work to hide and show the entire GUI, unless it has multiple windows (pure Swing Frame.getFrames() should give you all JFrame based windows, if that helps).
Not sure if that will solve the problem if you want the main window hidden on startup (but if it is a very simple UI, as is true of many tray apps, you might be able to just work with a dead-simple implementation of WindowManager such as WindowManager.Trivial and leave out the standard NetBeans windowing system entirely).

Painting directly on the Windows desktop

I'd like to play animations on the Windows desktop without relying on 3rd-party products such as StarDock DeskScapes or Windows DreamScene. What APIs should I look into?
you can read this thread...
http://www.gamedev.net/community/forums/topic.asp?topic_id=113986
it is long, but in it, is a discussion of writing to the desktop...
hope this helps...
~Bolt
I've never done this, but here's the approach I'd take.
Inject a dll into explorer via SetWindowsHookEx.
Grab a handle by using GetDesktopWindow.
Subclass the Desktop using GetWindowLongPtr & SetWindowLongPtr.
Do all your fancy rendering in the new WndProc you've hooked up.
Be aware that breaking the Desktop window will probably lock up your machine, as all its decedent windows (read: every window for that User) will likely be adversely affected.
Also, given the um rich compatibility history of Windows, be on the lookout for dummies meant to absorb abuse. In particular, I wouldn't be at all surprised if GetDesktopWindow does not in fact return the Desktop window you're looking for. You might have to do some digging with Spy++ or the like, basically.

Resources