How to know whether my application is visible or not? - delphi

I've seen some software which can detect whether or not a form is visible to the user. This might include being minimized, another screen covering it up, monitor turned off, and even when on remote desktop, knows when the remote desktop view is not visible. I'm guessing it has to do with whether or not anything is being drawn in the application. Perhaps video drivers can provide this information?
How can I make my application to detect this? Is there a Windows message I can monitor for this?
For the record, the mentioned software is one which streams multiple surveillance cameras in real-time (RTSP) which uses this ability to the advantage of pausing streaming when the screen isn't visible.

Most of the conditions do not have window messages associated with them, so you have to detect the conditions manually.
Use the TForm.WindowState property, or the Win32 API IsIconic() function, to detect your window's minimized state. You can also catch WM_SYSCOMMAND messages looking for the SC_MINIMIZE, SC_MAXIMIZE, and SC_RESTORE states.
Use the Win32 API EnumWindows() function to loop through all top-level windows, calling GetWindowRect() on each one, to detect if any areas of your window are not covered by other windows. To account for z-ordering, you may have to use GetTopWindow() and GetNextWindow() to iterate the z-order to see which window is on top of the other window.
Use MonitorFromWindow() and GetDevicePowerState() to detect the local monitor's power state. You can also catch WM_SYSCOMMAND messages looking for the SC_MONITORPOWER notification.
Detecting the Remote Desktop state is a bit trickier. You can use ProcessIdToSessionId() and WTSQuerySessionInformation(WTSIsRemoteSession) (Windows 7+) or GetSystemMetrics(SM_REMOTESESSION) to determine if your app is running inside of a Remote Desktop session, but I don't think you can detect whether the remote display is on/off (although WTSQuerySessionInformation() can query the remote display's resolution and color depth, and even if the session is locked/unlocked).

I'm guessing it has to do with whether or not anything is being drawn in the application.
For partially obscured windows, Canvas.ClipRect (which is equal to the rcPaint member of PAINTSTRUCT or the result gotten from GetUpdateRect) will be the portion of the device context that has to be redrawn. GetUpdateRect can be called outside a WM_PAINT handler, Canvas.ClipRect only within.
But if you could of would solely rely on paint messages being sent, I am not sure. I think Remy's suggestions are more robust. Or a combination of all.

Related

How can I use ARKit while using Slide Over/Split Screen on iPadOS?

I have an app that uses ARKit to detect faces and send over the network the coordinates of interest, which works well. I would like this app to run in background, still sending the data over the network, while I would be using another app (almost) fullscreen.
The option 'Enable multiple windows' is activated in info.plist, but as soon as I launch my other app, the ARKit app stops sending information (the app actually probably stops).
Is there a simple way to do this, and at least is this feasible? Thanks!
This is not possible at this point. Camera and AR stuff is disabled at a system level in apps when they are displayed in Slide Over or Split View.
I'd recommend displaying a warning message when Slide Over/Split Screen is being used saying that you should use the app in full screen mode. See this answer under a different question for details.

Modifying iPhone Camera/Flashlight?

I was wondering if there's anyway to modify how the iPhone takes pictures. Specifically, if you can turn off the dimmer focus flash that shows up before the full flash, so when you take a picture it's just the full flashlight that comes on immediately. Thanks!
Unfortunately, no, I think not. From the apple developer site:
Flash Modes
There are three flash modes:
AVCaptureFlashModeOff: The flash will never fire.
AVCaptureFlashModeOn: The flash will always fire.
AVCaptureFlashModeAuto: The flash will fire dependent on the ambient
light conditions. You use hasFlash to determine whether a device has a
flash. If that method returns YES, you then use the
isFlashModeSupported: method, passing the desired mode to determine
whether a device supports a given flash mode, then set the mode using
the flashMode property.
And there is no mention of the dimmer flash.
EDIT: Maybe you can. There are lots of iOS apps that do this
2nd Edit: After looking at this, I have concluded that you cannot do so.

Delphi - Simulate Click Animation

This is my first post here on stackoverflow so forgive me for anything I'm doing wrong.
I'm making a kind of guide to the users without any computer knowledge of my application where I show him how to use it by signalizing what he should do, more specifically where to click. I want to that by moving a "fake" cursor to the button and simulate a click, and here is where I got my problem, I have to simulate just the animation of the click, and not the event itself but I couldn't find a way to do that, can anyone help me?
What you're describing is exactly what WH_JOURNALPLAYBACK is for. It populates the message queue with the mouse and keyboard messages you want to occur, and the OS interprets them. In your case, activate the playback hook and perform the mouse events necessary for performing a click.
In preparation, you'll probably want to use WH_JOURNALRECORD to discover what messages you need. Once you have them, you can probably winnow them down to a reasonably sized list prior to shipping your product to customers. (In particualr, you'll probably record many more mouse-move messages than you really need.)
In your button's click handler, check whether playback is active. Only perform the rest of the event handler when playback isn't active. That way, your program will behave just as though the button were clicked (including any animation), but it won't execute the real event code.

Preventing execution pause when dragging game window

I have a server and a client. But when ever I start moving the game window, it stops executing code until the window stops moving,causing a connection timed out because the server or client stopped responding for a while.
What do I need to do in order to make the game always run code, even when the game window is being moved?
This is a known issue with XNA games, and there are several ways around it.
One way is to move a fake window frame, which isn't the game window really. Game window will then fit into the fake window's client area, only pausing execution for insignificant amount of time.
Other ways may involve use of windows hooks, unfortunately, that is all I can say about it. Personally, I recommend the approach with fake window.

iOS Music Controls as Arbitrary Input

I'm reading how to handle the events themselves, and I know I could intercept them and use them for my own design, but would Apple allow an app like that into the AppStore?
http://developer.apple.com/library/IOS/#documentation/EventHandling/Conceptual/EventHandlingiPhoneOS/RemoteControl/RemoteControl.html
You could imagine playing a game and giving the option of physical back/forward buttons mapped to left/right in your game. I mean to use them when the app is active in the foreground, nothing outside the app or in the software control tray.
This article doesn't say specifically that it's not allowed, but it does imply that the events are to control music only.
Can anyone with more Apple/iOS background refer me to a document which specifies the rules about using the buttons?

Resources