detect all windows minimized from c# application - c#

how to detect all windows(of other applications) minimized from c# application

Use example from here http://pinvoke.net/default.aspx/user32.EnumDesktopWindows then just check window state

If you want to monitor what's going on in the system, then you want to set up a CBT Hook. That will keep you notified when windows are created, destroyed, minimized, maximized, moved, activated, etc etc.

Use GetWindowState() WinAPI function

For Windows Forms you can look at the property WindowState on the Form object. Minimized windows will have a state of FormWindowState.Minimized.

Related

getting correct window style as configured by windows shortcut

When you create a shortcut in windows to an application, in its properties you can define under "Run:" the initial window state (Minimized / Maximized / Normal).
C# applications do not, apparently, start up their forms according to this configuration out-of-the-box, so I figured I need to get this information somehow and write a code that does that programmatically on start up.
I cannot find a way to get this information in my c# application.
I have tried:
Process.GetCurrentProcess().StartInfo.WindowStyle
But for some reason this is always "Normal" regardless of the configuration in the file shortcut.
Does anyone have any idea how to come around this?
Just made a quick test and it does work out-of-the-box only if your main form is set to start as Normal window state. If you choose Minimized or Maximized it will override the shortcut settings.
In case your main form is set as Normal you can detect the actual state using such code:
FormWindowState actualState = Application.OpenForms["Form1"].WindowState;
if (actualState != FormWindowState.Normal)
{
//probably launched via shortcut overriding the state, handle.
}

How to activate a window of an external application

I've used FindWindow to get a handle to a window of an external application. How can I use this handle to activate the window of the external application, if it is minimized or behind other applications on the windows desktop?
To prevent focus-stealing (or at least make accidental focus-stealing harder), Windows puts up some roadblocks to one process bringing another process's window to the top.
Check MSDN for SetForegroundWindow (especially in the Remarks section) and AllowSetForegroundWindow.
You should either send a message to the process to tell it to restore its own window, or that process has to explicitly allow your process to do this.
FindWindow() followed by ShowWindow().

How to bring Windows Taskbar on foreground while running maximized?

I've got an app running maximized in a borderless window and need access to the windows taskbar on a given user event.
How would I bring the taskbar in foreground in .NET while running maximized?
Also an hint with regards to how to make it reliably go away wouldn't hurt! :)
EDIT: please note that I don't want the taskbar always on, I want it popping up on foreground just on a given user event, and then I want it to go away at will!
Um, don't run fullscreen? Maybe run maximized? Fullscreen app with taskbar is not a standard UI pattern.
What you could try doing is run maximized without the UI chrome (borderless window). Would let the taskbar in on the fun while still looking like a fullscreen app.
Interestingly enough, your desired solution seems to be the problem that caused this question. See my answer there. You may have to experiment a little with setting the FormBorderStyle and WindowState properties in a certain order, and try to minimize disturbance for the user.

Form top most?

How can I display something over all other application. I want to to display something over all form of my program and all other programs open on my desktop (not mine).
*Top Most doesn't work I have tested and my browser can go OVER my application :S
Here is an image of when I use TopMost to TRUE. You can see my browser is over it...
http://www.freeimagehosting.net/uploads/5a98165605.png
You can use the form instance and set the property TopMost to True.
If you want to be over all Windows, there are another way with Win32 Api calls.
Here is what you could do:
In your form class add :
[System.Runtime.InteropServices.DllImport("user32.dll")]
public static extern bool SetForegroundWindow(IntPtr hWnd);
In the form load you can add :
SetForegroundWindow(this.Handle);
This should do the trick.
Update
TopMost should do the job BUT: Top most OR/AND the Win32 Api call will only work not inside Visual Studio (well for Vista and with VS2008 I tested it... I can't tell for other). Try running the program with the .Exe from the /bin directory, it will works.
The Form.TopMost property will set your form the top form above all other running windows applications (not just your forms.)
myForm.TopMost = true; // This will do the job
TopMost property is what you need (never had a problem with that)
On MSDN it says:
A topmost form is a form that overlaps all the other (non-topmost) forms even if it is not the active or foreground form. Topmost forms are always displayed at the highest point in the z-order of the windows on the desktop.
http://msdn.microsoft.com/en-us/library/system.windows.forms.form.topmost.aspx
In my team we had a internal tool that keeps on running after Windows startup. It is a WinForm with TopMost set to ture. On Vista, sometimes we had the same problem. At very random times, the form will lost TopMost property and other non-topmost window can appear above it.
I had a log of researches but found no answer and many other people had this same problem, it seems that on Vista at very low level there is a bug about TopMost property.

Sending a mouse click to a button in the taskbar using C#

In an application that I am currently working on, a requirement is to bring a window of an external application to the foreground. Making Win32 API calls such as BringWindowToTop and SetForeground window do not work all the time. This is due to some restrictions within Windows XP. What I would like to do instead is send simulate a mouse click the window's button on the taskbar which I am hoping will bring the window to the front. Does anyone know how this is possible?
Check out the section "How to steal focus on 2K/XP" at http://www.codeproject.com/KB/dialog/dlgboxtricks.aspx, as this is exactly what you need. I wouldn't go the taskbar route as the taskbar could be hidden or simply not there.
It's possible. But it's extremely sketchy. Your application may also break with the next version of Windows, since it's undocumented. What you need to do is find the window handle of the taskbar, then find the window handle of the child window representing the button, then send it a WM_MOUSEDOWN (I think) message.
Here's a bit on finding the window handle of the taskbar:
http://www.codeproject.com/
FWIW, the restrictions on BringWindowToTop/SetForeground are there because it's irritating when a window steals focus. That may not matter if you're working on a corporate environment. Just keep it in mind. :)
I used this in a program where I needed to simulate clicks and mouse movements;
Global Mouse and Keyboard Library
To be honest I've never had an issue bringing a window to the foreground on XP/Vista/2003/2000.
You need to make sure you do the following:
Check if IsIconic (minimized)
If #1 results in true then call
ShowWindow passing SW_RESTORE
Then call SetForegroundWindow
I've never had problems that I can think of doing it with those steps.

Categories

Resources