I want to detect on which screen a window is displayed when I got its handle. I found a SetWindowPos() function in Win API, but unfortunately there is no GetWindowPos() just a GetWindowRect(), but this results some odd values.
I got two devices, left one 1280x1024 and right one (primary) 1680x1050. When I want to get the position of a minimized firefox, I get b/l/r/t -31973/-32000/-31840/-32000 for either screen.
How do I know that it is my left or my right screen?
WinAPI has a MonitorFromRect function, which is probably what you need. I'm not sure if there's a C# equivalent, but you can call it through interop.
Be aware that the window can be on both monitors, or on neither. The API has flags for that, e.g. MONITOR_DEFAULTTONEAREST.
Try GetWindowPlacement, in order to find the rectangle that the window will use if it were restored.
Related
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.
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.
I want to move a Window (HWND) in a second monitor. The thing is that I tried many things like double the resolution or putting negative values and it never was able to put the window on my second monitor.
Any clue of how to do that in C/C++/c#
Screen and the Form.StartPosition should get you there.
See the first answer to this post (for C#/WinForms solution): How do I ensure a form displays on the "additional" monitor in a dual monitor scenario?
The desktop layout is user-configurable, a second monitor can be to the left, to the right, above, below, or positioned weirdly compared to the primary.
The GetMonitorInfo function will help you find out where the second monitor is, in virtual screen coordinates. As #holtavolt mentioned, the .NET Screen class is a convenient wrapper.
I know it's possible to capture a screen of an application that is behind another application, but I can't seem to find anything on capturing the screen of a minimized application.
Anyone happen to know if this is possible? I don't want to get into things like maximizing and minimizing the application really quick.
As #ziplin said with newer version of windows it may be possible (via DWM apis). From c# you can use the Windows API codepack to access the new apis
I don't believe so, simply because i've noticed programs that try to preview a window that is minimized seem to draw a blank on occasion if the window is minimized. Although, some new versions of windows (vista and 7, I believe) do this very thing, but I'm not sure how easy it is to replicate (at all)
: http://www.stardock.com/products/objectdock/
You can't without restoring the window. When a window is minimized, the application is not in a state to render a UI for your application to capture.
If anyone still wants to no a workable solution I tried this one and worked well for me. It does a trick for minimized windows (because windows does not refresh them, on the taskbar the iconic picture shows the last image of the window before it was minimized). And Ziplin above mentioned that Objectdock can capture minimized windows, actually it does the same as Windows, it uses the last image captured before minimizing.
So here is the link: http://www.codeproject.com/Articles/20651/Capturing-Minimized-Window-A-Kid-s-Trick
I've never tried it. This code claims looks reasonable, but has caveats about minimized windows. It is, if nothing else, a place to start.
As a last resort: why not capture window just before it gets minimized?
I know its too late, maybe it might help others.
I thought of a different approach, instead of minimizing, I moved my form outside my screen co-ordinates before capturing the screen and later respawned it.
Below is my code example:
//Move the form beyond the screen
this.StartPosition = FormStartPosition.Manual;
this.Location = new Point(Screen.PrimaryScreen.Bounds.Width + 10, Screen.PrimaryScreen.Bounds.Height + 10);
// Screenshot code here...
//Respawn the form to origin location
this.Location = currentPosition;
I have a fullscreen window, and I want to prevent pop up windows that appear at the right bottom corner of my screen. I set the Topmost property to true, but apparently it does not help. I also tried activating the form and giving it the focus once it got deactivated, but that did not help either. What is a way to ignore such windows while the user is engaged with the fullscreen app? I am .NET programming in C#.
You can't do it, this fails the "what if two programs tried to do this" test:
those popups are just normal windows like yours, they also use the same top-most style you are using.
if there was a way to always be above other topmost windows they would have used it too rendering it useless (because the authors of the other apps are just as concerned about the user missing their "super important" notifications as you are about them interfering with your full screen app).
You can try and play dirty tricks to force your window to the top of the top-most z-order, but those popups are likely to use the exact same tricks, again making this all useless (and as an extra bonus all those dirty tricks can turn your app into a compatibility nightmare).
You can disable these balloon notifications using these steps:
Click Start, Run and type regedit
Navigate to the following subkey:
HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced
In the right pane, create a DWORD value named EnableBalloonTips
Double-click the new entry, and give it a value of 0.
Quit Registry Editor.
Log off Windows (this is not very cool...), and then log back on for the changes to take effect.
if you need help in how doing this by program, don't hesitate to ask ;)
I don't think that you can block all the popups, windows might not let you do that. But you can try with SetWindowPos function and pass it HWND_TOP parameter. It might work a little better than Topmost = true.
I used a sys tray popup control on my personal project SvnRadar written in WPF.
The control is at the http://www.hardcodet.net/projects/wpf-notifyicon written by Philipp Sumi.
Very nice.Only thing you will be need to "detach" it from the SysTray screen coordinates and
make it appear where you wish.
Hope it helps.
Good luck.