Win32 force windowed mode on process - c#

I'm looking to force an application to be windowed (like you would with alt+enter) even if it starts in full screen mode.
My initial thought was to use user32.dll "ShowWindow" with either "Restore" or "ShowNormal". However if it started full screen it will not work.
Is there any way to force any given application to be windowed using c#?

You can try to send messages to the app's window to get it behave. I remember there is this app for a MMORPG game and it was called "Windower" It forced the game, Final Fantasy 11, to run in a window. It was used until the vendor made their own windowing code back in 2007 or 2008.

Related

Why does my Blink based browser play hide and seek?

We have a C# tool (that I wrote) that records online broadcasts taking place a custom written (that we wrote) flash app. (There are no DRM or copyright issues here.)
We've coded up a system whereby this tool is installed on a Windows Server 2012 R2 Amazon AWS instance. After we boot the instance, the tool loads, waits for the right time to start recording, launches a browser and passes the command line argument of the URL to access the broadcast. The browser will then load the flash app and the interview audio and video will start arriving at the browser instance on AWS
By way of a virtual audio cable driver, screen / audio capture directshow filters and ffmpeg a screen recording is taken. The C# tool calls ffmpeg and ffmpeg will record the screen reliably for the entire interview, then the tool shuts the whole thing down
The problem I'm having is that both Chrome and Electron browser sometimes simply don't draw themselves on the screen so all ffmpeg ends up recording is a blank desktop and the audio of the broadcast (hence, the browser IS running)
We found this out when recordings started turning up with X hours of merely recording the windows desktop and the tool's main window with a countdown timer.
A screenshotting facility was built into the tool and added to its web control interface, and this way we can test whether the browser is visible - a human looks at the screenshot of every broadcast, just after recording has started (the browser is supposed to be on show by this time)
We notice that 50% of the time, the browser isn't drawing itself on screen. By 50% I mean that every other recording that the AWS instance carries out, will be blank: AWS starts, records ok, shuts down. AWS starts again an hour later for a different broadcast, recording is blank, shuts down.. Starts/ok/shutdown. Starts/blank/shutdown. Repeat ad infinitum
What's even more strange is that if I run VNCviewer on my dev machine and connect up to an instance that is having a problem, the instant that the VNC connection is up and the remote desktop is showing on my screen, the browser suddenly appears as if nothing was ever wrong. A screenshot from before the VNC connect shows blank desktop, connect VNC, take another screenshot and the browser is there. All through it the audio is fine - the browser connected to the boadcast is fine, for sure
It's as though Chrome/Electron thinks "you know what, noone is looking at me so I'm not going to bother drawing myself". No screen saver is set, though the power plan has the setting "turn off the display after 15 minutes".
Perhaps Chrome/Electron have a test amounts to "if the display is off, don't draw". I can't explain the inconsistency though - the recorder launches at least 1 hour before it's needed, and sits there idle until it's time to start the browser. You'd hence imagine that the "power off the monitor after 15 mins" setting would reliably have ensured the "monitor" is "off" by the time every recording start comes around
This behaviour doesn't happen with any of the other browsers (but unfortunately the app doesn't and cannot work in them because it uses some weird chrome-only technology/API).
Can anyone suggest anything to look at to help debug this, or anything I can build into the C# tool to overcome the problem? Coding it up to connect to itself via VNC for a few seconds after it has launched the browser.. Well that just tastes nasty.
Naturally, as soon as I connect to the machine via VNC (rather than RDP - RDP isn't usable because the recording context is in a logged on session for a particular user) the problem goes away, which makes it frustratingly hard to debug.
I am not sure what exactly causes your problem, but it sounds like interacting wit the system prevents it. One way to interact with a system is to use the keyboard and this can be automated.
You could try sending a keystroke (like "F15") evey so many seconds in C# using
Windows Input Simulator or maybe SendKeys.Send and
Combine the above with some kind of Timer
Maybe take a quick peek at this app called Caffeine...it presses the "F15" key for you every so many seconds. They claim "F15" generally doesnt trigger anything in windows (since a release they made back in 2010).
Caffeine App

How to determine whether a program uses DirectX, and if so, what's the DirectX surface size?

I'm using Spazzarama's Direct3DHook to capture screenshots from an application (with the purpose of streaming them over the Internet). Although this works well when the application uses DirectX, it fails if the application does not use DirectX (e.g. Notepad).
How can I determine whether a running application (process) uses DirectX? The reason is that in that case, I would need to use a different way to capture a screen, e.g. using GDI+.
When this DirectX application is not running in full screen mode, how do I get the size of the DirectX surface? E.g. when I capture the screen of a game running in windowed mode, the application size includes the size of the window frame etc. too, and my captured screen is typically too large.

WIndows Mobile full screen problem

I have a windows mobile professional 6.1 application and I want it to be full screen in all pages so I put the code below into my every pages constructor;
this.WindowState = FormWindowState.Maximized;
this works OK but "sometimes" for example when I use
MessageBox.Show("alert");
or when I try to connect internet within application and there is a problem and Windows shows me some messages popping up from the top of the screen..in this cases I lose my full screen and the top menu bar of windows becomes visible again..
any ideas?
You can use SHFullScreen to hide the start icon and other system areas of the screen. There is an undocumented function named AllKeys which will allow you to block some of the hardware keys (notes, recorder, green + red phone keys) from running. It will require a lot of work because there are many ways to run programs and the taskbar has a habit of reappearing after a program is run. Simply calling SHFullScreen once is not enough. You'll have to handle WM_ACTIVATE messages and call SHFullScreen again and force your program to the top again. It's a struggle against the operating system to have a true kiosk application on Windows Mobile.
Getting an app to "kiosk mode" in Windows Mobile is challenging becasue the platform simply isn't designed for it. This page has a lot of links to resources of getting it working. Using your favorite search engine to look for "compact framework kiosk mode" is likely to bring up more as well.

Screen information while Windows system is locked (.NET)

We have a nightly process that updates applications on a user's pc, and that requires bringing the application down and back up again (not looking to get into changing that process).
The problem is that we are building a Windows AppBar on launch which requires a valid screen, and when the system is locked there isn't one in the Screen class. So none of the visual effects are enabled and it shows up real ugly.
The only way we currently have around this is to detect a locked screen and just spin and wait until the user unlocks the desktop, then continue launching. Leaving it down isn't an option, as this is a key part of our user's workflow, and they expect it to be up and running if they left it that way the night before.
Any ideas?? I can't seem to find the display information anywhere, but it has to be stored off someplace, since the user is still logged in.
The contents of the Screen.AllScreens array:
** When Locked:
Device Name : DISPLAY
Primary : True
Bits Per Pixel : 0
Bounds : {X=-1280,Y=0,Width=2560,Height=1024}
Working Area : {X=0,Y=0,Width=1280,Height=1024}
** When Unlocked:
Device Name : \\.\DISPLAY1
Primary : True
Bits Per Pixel : 32
Bounds : {X=0,Y=0,Width=1280,Height=1024}
Working Area : {X=0,Y=0,Width=1280,Height=994}
Device Name : \\.\DISPLAY2
Primary : False
Bits Per Pixel : 32
Bounds : {X=-1280,Y=0,Width=1280,Height=1024}
Working Area : {X=-1280,Y=0,Width=1280,Height=964}
There is no clean solution for this, Windows doesn't provide a way to detect that the work station is locked and that the "wrong" desktop is active. You can only detect the session switch, sample code is here. To make this work, you're pretty much forced to include this code in the app and have it leave a breadcrumb that it could read back when it starts back up. Be sure to reset it after you used it once so that the app cannot get stuck permanently.
This screen lock problem is dependant on what version you are using, either XP which uses GINA that locks the screen and Vista which uses ContentProvider, both of these mechanisms are ultimately responsible for this.
The only way to see if the screen is locked, is a screensaver kicks in, (this can be easily queried by running a pinvoke to query SystemsParameterInfo, to find out if the Screensaver is active or not - SPI_GETSCREENSAVERRUNNING and SPI_GETSCREENSAVESECURE to determine if that will trigger GINA or Content Provider) when pressing WinKey + L to kick in the screensaver, after the specified period of time, if no activity, then GINA or ContentProvider kicks in and replaces the screen-saver with a lock screen... I have included two relevant links that was posted here about the secure logging information under Windows...
'Invoking the Windows Security Dialog'
'Login into Windows from .NET application'
It would require a little work, however you could utilize EnumDisplayDevices, EnumDisplaySettingsEx, MonitorFromPoint, GetMonitorInfo all from user32 and grab a screen shot of the device.
If the PC is locked, or if there is an active screen saver, then the screen capture is always a beige color. You could check for that condition to know the system is locked. This works on systems being RDPed into also (Thin client to XP VDI for example.)
At least that works in my environment. Code samples can be found by Googling.

Take screenshot of any external application using C#

We have a C# (WPF) application in which we want to take a screenshot of an arbitrary application launched by us (i.e. so we have a reference to the Process we started).
The application may be minimized or behind other windows but we still only want the image of the individual application, not overlapping pixels.
I know the typical P/Invoke solutions using BitBlt or PrintWindow work most of the time, but those fail (I only get black/transparent pixels) when dealing with an DirectX or OpenGL application that draws directly to the graphics device. I have found this article on taking a screenshot of a Direct3D app from C#, so I think I have that case covered.
So my question is this:
How would I do this for an OpenGL application?
What is the easiest way to determine the appropriate method to use (PW/DX/GL)?
Is there a single universal way of doing this?
For #2, am I relegated to inspecting the modules loaded by the executable and seeing if an DirectX or OpenGL DLL/Assembly is loaded?
This only has to run on Windows XP (not cross-platform and not going to Vista/7 anytime soon if ever for this application).
Answer to 1: In OpenGL, you can call glReadBuffer and glReadPixels to get the screen bitmap. However, this is slow (so you don't call it repeatedly every frame) and you might also have problems when th GL window is overlapped by another application / window. The correct way to do this is to "render to texture" (google it) by using a pbuffer.
Idea for 2: If you have the handle to window, you might be able to get the pixelformatdescriptor structure it has and check it. Never tried it though.
For 3: By the way, I don't think there is a single universal way of doing this without any problems..

Categories