How can I print screen minimized windows? - c#

How can I print screen minimized windows? I believe it's possible, since Windows task-bar can create a preview of a window even if it is minimized.

This guy managed to do exactly what you are after: http://www.codeproject.com/Articles/20651/Capturing-Minimized-Window-A-Kid-s-Trick
I know this question is really old, but it can still be valid for someone.

I'm pretty confident that this is not possible, at least by an external application like yours. When an application window is minimized, the window cannot (and does not) receive WM_PAINT messages, meaning that it is impossible to ask the window to redraw itself while it is minimized (or, "take a picture of it"). This is a limitation (or a rule) of the Windows API.
The taskbar "gets around this" by displaying a cached image (which is the last snapshot the DWM took of the window before it was minimized) and so it is not in fact taking a current picture of the window. You can test this by running an application which periodically updates itself, and then minimizing it -- you will see that the preview image will not be updated until it is restored.
The only way you could get around this is to do what the taskbar does -- periodically take a picture of the window you want, and when it is minimized, use the cached image instead. Of course, this means your app will have had to have been following the target window some time in advance (this obviously won't work if the first time you want to take a snapshot of the window is while it is minimized).

Related

Restore Windows to Size They Were Previous to Being Minimized

I'm trying to use WinAPI to bring any open window to the foreground. I've tried many different ways of accomplishing this but none that worked out perfectly. Methods I've tried include SwitchToThisWindow, BringWindowToTop, SetActiveWindow, and SetForegroundWindow using the AttachInputThread and they all tended to fail if the target window was minimized. More recently I've tried OpenIcon and ShowWindow (with the RESTORE command) to unminimize windows, but that too has presented a problem, in that, both of those methods unminimize the window to it's "Normal" or "Original" state regardless of whether it was "Normal" or "Maximized" before it was minimized.
The current solution I can think of is to intercept the minimize message to any open window and store its state before it's minimized and restore it using that stored state. However, this would require me hooking into every process I'd want to restore which I'd really rather not do.
So my question is, how do unminimize a window to the state it was in before it was minimized?
Your solution is correct. You have to store the window size so you can "reconstitute it" to the same size. You should also store position, as well as size, if you want it to look correct. Much of this is abstracted if you don't dig into the bowels like this.

Send/Post Message to other Application

I would like to know if it is possible to SendMessage and PostMessage to/in other application even if it is not activated, or somehow to interact with that application without disturbing the user....
So far all I want to do is detect Pixels at specific coordinates than to Click on specific coordinates.
Note: Please do not misunderstood, the reason I want to detect Pixels and than Click, is because the button does not has Class ID.
It is possible to use SendMessage and PostMessage to send mouse clicks at specific coordinates to a window. The messages to send would be like WM_LBUTTONDOWN, WM_LBUTTONUP, and WM_LBUTTONDBLCLK. These messages can be sent with the window minimized or hidden.
If you have Visual Studio, there is an included application called Spy++ (and Spy++ 64 Bit). If you use those programs and have them monitor the window messages to your target application, you can see the exact window messages that are sent when you manually click on the button.
It is difficult if not impossible to detect pixels when the window is not visible either due to being minimized, hidden, or just covered by another window. If the application will be running in Vista or later, you might try creating a DWM Live Thumbnail of the application inside your app and scanning the pixels from there to determine the button's location.
Hopefully this information will get you started or at least let you know how complicated this may be so you can make an informed decision to continue or not.

How to be OnTop but not OnTop of a full screen application

So I have tried searching for the better part of a day for the answer to a simple question. I want my C# application to popup another winform on a timer and then close it after a delay. Simple enough, done and done. Now my issue is that I want it to actually be on top of other applications UNLESS they are full screen. By that I mean a true full screen application such as a game. I do not want to interfere with such an application since it should take priority over my application.
The issue is that I am using the 'OnTop' property on the popup form and, while it works perfectly for any other applications I have been testing it while playing a full screen game and the form, when it "Show()"s, takes the full screen application and drops it into windowed mode.
Is this the intended effect of the 'OnTop' property with full screen applications? If so is there a way that I can have my form popup on top of normal windowed windows and not interfere with full screen applications?
Any links, example, a kick in the general direction is great. The only hits that I come up with when searching for winforms involving full screen is people trying to get their application into full screen or having their application take focus away from another application.
Thanks on advance.
(I didn't post any code due to it just being a simple winform that is "formX:Show()" on a timer with the "onTop" property set)
(EDIT) So thanks to awilson53 for putting me on the right track I was able to find a method (albeit somewhat picky) to determine if an application is full screen. Seems kinda simple, and an "well duh", answer after all is said and done.
95% of the credit goes to the author of the article: http://www.richard-banks.org/2007/09/how-to-detect-if-another-application-is.html
~5% goes to awilson53 for getting me on the right track. :)
Check out this wrapper for the EnumWindows function. This will allow you to enumerate all open windows and determine their window state. You will want to check the EnumWindowItem.Maximized property, and if it is true set your OnTop property to false. If none of the EnumWindowItem's return Maximised you can set OnTop to true.

Screensaver Hides Desktop

we would like to build a screensaver that shows the desktop and the running applications but prevents user input by showing the login screen. The idea was to build a windows app with no window or a transparent window. However, as soon as the screensaver gets activated the desktop and all applications are hidden from the screen.
Is it possible to start the screensaver without hiding the desktop?
Thx,
bja
Is it possible for you to implement this as something other than a screensaver? I'm assuming that the Windows API does have a method that allows you to tell how long the computer has been idle (otherwise, how does the stuff that manages screensavers do it?), so if you use that you could just set up your application such that it's continuously running as a background process, and will pop up a modal dialog box (or your idea of a transparent window) or something that prompts for the user's login info when the computer has been idle for a certain amount of time.
Why can't you just grab an image of the screen when the SS kicks off. Then use that as the backdrop of your SS.
Vista has a bubbles screen saver that just starts putting bubbles on the screen. Not sure how they do it.
You are better off just creating a full-screen application with a transparent window that starts up on a timer like a screensaver. The screensaver functionality while similar to what you are doing, functions much differently.
As an alternative suggestion, you could always use a service (or background app) to gather the information you want these monitoring tools to display, or even just to grab periodic screenshots of the (hidden) desktop, and then have your screensaver query that app to get the data it needs to display.
That way, you get the benefit (the secure desktop, the usual Windows login sequence, etc.) of a screensaver, but still get to display what you need to.

calling the user attention outside of app

I want to create an alarm app for myself. On certain conditions (i need to poll websites) i want my app to inform me and make it HARD TO MISS. So i can take appropriate action or ignore it if i need to do something else.
I wrote a test app and using a BalloonTip (ShowBalloonTip with notifyIcon) isnt great. One of my previous apps brings the window in front of you and does a MessageBox however that doesnt always work or work well (if i somehow miss it or accidentally forget to click ok no futher messages will occur).
What are your suggestions?
You could also make it a system tray application and change the icon out if there is something which requires attention, a la a messenger application. That may not be "hard to miss" but I am trained (for better or worse) to look down at the icon tray when I see something blinking.
Where I work, we have a TimeTracker application (built in house) with which developers are supposed to log what we worked on and when. I am notorious for not using it. So, I wrote my own (Windows Forms) version for my own use which, every hour opens up and takes over my screen:
It is a frameless dialog which consumes the entire screen.
TopMost = True.
On resize, it sets WindowsState = Normal and resizes to fill the screen.
While it is open, it polls for taskmgr.exe and procexp.exe and kills them if found.
It disables the start menu to prevent cmd.exe commands from the menu in Windows 7.
The only way to close it is to enter a log, only then is the OK button shown!
So far, it's working out well - no one has been able to break it!
My less drastic suggestion would be to have a notification which pops up momentarily above the system tray. After a second or two, fade it out. Keep showing the notification every 30 seconds or so until it is dismissed.
Always-on-top window in the corner of the screen?
You could always set your window to be a top most window, make it full screen, and activate it. It would be very, very hard to miss...
Granted, it would also be very annoying, and not something I'd do to other users...
My "real" suggestion would be to use sound along with standard notification methods if this is going to be used by other people, as that's an easy way to grab attention without necessarily killing their workflow. A modeless window that appears in a corner of the screen, especially if combined with sound and color, can be very effective to grab attention.
The industry has been adopting these ambient orb devices and variations of it when such a hard-to-miss notification is required. It is used for tracking the stock-market and for broken-daily-builds.
http://www.ambientdevices.com/cat/orb/MAN_Ambient%20Orb_3-23-03.pdf
Regards

Categories