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.
Related
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 can I start Firefox as hidden application in my C# application?
The ProcessStartInfo.CreateNoWindow property only applies to console mode apps. A regular GUI app requires a window to be functional. It is supposed to observe the ProcessStartInfo.WindowStyle property but not all GUI apps are well behaved, particularly when you ask for ProcessWindowStyle.Hidden. Which presents a user interface problem, can't get the window activated when it is hidden.
A minimized window is usually the best you can get, with a taskbar button.
I think. You are asking how to run a program without displaying in Task manager. ?? if its true, then You Can Set ShowInTaskBar Property to false of that Form. if not then can u explain what "Hidden Mode" means ? so that it is easy to solve the problem
Form.ShowInTaskBar=false;
http://msdn.microsoft.com/en-us/library/system.windows.forms.form.showintaskbar.aspx
I have an application that I want to stick to the desktop. Stick to the desktop means that every time that someone click windows+D or the show desktop icon the desktop will appear with the application on it.
The user can locate the application on the desktop and change the location at any time but it always remains on the desktop.
We manage to do it on XP by setting the application’s parent to be the desktop using the winAPI methods SetParent (this .Handle, FindWindow ( "Progman " , null ));.
On Vista we manage to stick it to the desktop, whenever the desktop gets focus, it draws a gray background around we window. this background doesn't disappear when my window is moved, leaving ugly squares on the desktop. when I click Windows+D they all vanish.
Note that this doesn't happen on XP at all.
The client is based on .NET 3.0 and WPF .
Any idea why it happens and how to solve it?
use the following code and pass the window handle to the function while form load hope fully this resolves your problem
public void SetFormOnDesktop(IntPtr hwnd) {
IntPtr hwndf = hwnd;
IntPtr hwndParent = FindWindow("ProgMan", null);
SetParent(hwndf, hwndParent);
}
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.
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.