How to remove an 3rd party application from the Windows taskbar by its handle?
I've found this:
Remove application from taskbar with C# wrapper?
But it doesnt worked for me.
It only sets another style (small x to close, no maximize/minimize button) to the Window i selected (notepad).
Any ideas about this?
EDIT: I dont want to remove MY application from the taskbar, i want to remove an external application by handle
If you have the handle to the window you can call ShowWindow() through the Win32 API. Then you can do:
// Let the window disappear (even from taskbar)
ShowWindow(this.Handle, WindowShowStyle.Hide);
// Revive the window back to the user
ShowWindow(this.Handle, WindowShowStyle.ShowNoActivate);
So from now, all your problem is to get the handle of the window you like to hide:
Process[] procs = Process.GetProcesses();
IntPtr hWnd;
foreach(Process proc in procs)
{
if ((hWnd = proc.MainWindowHandle) != IntPtr.Zero)
{
Console.WriteLine("{0} : {1}", proc.ProcessName, hWnd);
}
}
To hide it from windows task bar you just need to set ShowInTaskbar property to false :
this.ShowInTaskbar = false;
As for moving of windows you can use spy++ to check windows events and identify it.
How to remove an application from the Windows taskbar?
this.ShowInTaskbar = false;
Easy:
this.ShowInTaskbar = false;
As for the Form movement: you can use the Move event under Layout events
Related
I am building a Windows App SDK app that needs to stay alive and display a tray icon when the main window is closed.
For WPF, I know this can be achieved by setting ShutdownMode="OnExplicitShutdown". And I wonder how can I do this with Windows App SDK 1.2.
Appreciate any useful information.
You can try this. AppWindow.Hide
public MainWindow()
{
this.InitializeComponent();
IntPtr windowHandle = WinRT.Interop.WindowNative.GetWindowHandle(this);
WindowId windowId = Microsoft.UI.Win32Interop.GetWindowIdFromWindow(windowHandle);
AppWindow appWindow = Microsoft.UI.Windowing.AppWindow.GetFromWindowId(windowId);
Closed += (s, e) =>
{
e.Handled = true;
appWindow.Hide();
};
}
I found the solution:
Hook class AppWindow's Closing event and set AppWindowClosingEventArgs.Cancel = true to prevent the window from closing. Then, call window.Hide() to hide the window.
I want to create a Spotify-like behavior for my WPF application. When the application is running, but minimized in the taskbar and the user tries to start a new instace, it should restore it from the taskbar, and give focus to the already running instance. The problem is stumble upon is to open to application from minimized state in the taskbar to be in focus. It works if the application is open, but other windows are placed over it.
var processHndl = FindWindow(null, "MyApplicationName!");
if (processHndl != IntPtr.Zero)
{
var isIconic = IsIconic(processHndl);
MessageBox.Show("Iconic: " + isIconic);
if (IsIconic(processHndl))
{
ShowWindow(processHndl, 9);
}
SetForegroundWindow(processHndl);
}
Any ideas?
Please try
SwitchToThisWindow
Windows Function Reference.
in a C# winform, I have an app that has a 'silent mode' in it, in that mode it gets minimized and hidden from the task bar, AKA:
this.WindowState = FormWindowState.Minimized;
this.ShowInTaskbar = false;
But at a certain point, I want the main window of the program to show up again by pressing a certain key combo on the keyboard, like for example Alt+Ctrl+Shift+S
But i just don't know how to do that.
The way i got around this was totally different, if the user wanna gets the window back, he'd have to create a file called 'SilentMode.OFF' in a specific directory.
doing so will get the window back.
I managed to do this by a timer in my app, the timer checks to see if that file is created in that dir, if so, show the window.
Not that's not really a pro way to do things.
My Q: how can I communicate with a minimized window ?
how can i send it and make it respond to the keys that i want it to respond to ?
I tried some of the events' like the Leave event and some other, but didn't really work.
Any tips would be of great help, Thank you.
AFAIK there is no .NET-wrapper for the hotkey functions in the winapapi. but you can use RegisterHotkey via pinvoke. Here is a detailed explanation: http://www.codeproject.com/Articles/5914/Simple-steps-to-enable-Hotkey-and-ShortcutInput-us
You can make a method like:
[DllImport("user32.dll")]
static extern short GetAsyncKeyState(System.Windows.Forms.Keys vKey);
private void WaitForHotKeys()
{
if(GetAsyncKeyState(Keys.Alt) != 0 && GetAsyncKeyState(Keys.Control) != 0 &&
GetAsyncKeyState(Keys.Shift) != 0 && GetAsyncKeyState(Keys.S) != 0)
{
this.WindowState = FormWindowState.Normal;
this.ShowInTaskbar = true;
}
}
And add in your load method:
Thread myThread = new Thread(new ThreadStart(WaitForHotKeys));
myThread.Start();
I want to open few windows (IE window, Outlook mail windows, notepad windows) by a click of a button on my application.
Problem: When I click on the button and all these applications open one after the other. My own application (on which the user clicked) is lost in the window clutter.
I want to open all these windows behind my application. Any suggestions ? Any standard API's which I can use to achieve this kind of behavior ?
Logic: I want to do something like open window with window placement = 2 in the Z order of windows. This way, my window, which is active will always be at the top (z order = 1) when other windows are opening.
Any pointers will be helpful.
Thanks
Karephul
UPDATE:
http://msdn.microsoft.com/en-us/library/windows/desktop/ms633545%28v=vs.85%29.aspx
I used this PInvoke to set my application window as topmost. then all the other windows will automatically open behind it. Once done, I un-set the topmost window flag using the same PInvoke. More details in the link I posted.
You can set the TopMost property of your form to True.
Make sure you allow users to change that or only do it for a short period, because it does get annoying to users.
You have two ways, call the win32 command SetForgroundWindow or toggle topmost.
To toggle topmost do the following. This will bring the window to the front but not leave it as topmost which is pretty annoying.
// Launch applications (Process.Start(...))
TopMost = true;
TopMost = false;
To call the Win32 Command
[DllImport("user32.dll")]
[return: MarshalAs(UnmanagedType.Bool)]
static extern bool SetForegroundWindow(IntPtr hWnd);
...
// Launch applications (Process.Start(...))
SetForegroundWindow(this.Handle);
...
It might be more intrusive than you like but I discovered by accident while doing some Office interop that after opening the office apps and files that you can issue
MessageBox.Show("All files have been opened.")
And this should bring your app (and the messagebox)frontmost.
If you are using System.Diagnostics.Process Classes Start method you can set Application variables for the process state when launched using the ProcessStartInfo class and passing it into the overridden method Start(ProcessStartInfo startInfo) as a parameter. There is a property ProcessStartInfo.WindowStyle which is of type ProcessWindowStyle which has 4 values Normal, Hidden, Minimized and Maximized, by setting the value to Minimized you can regain focus and be easily brought to the front.
Code from MSDN
// Uses the ProcessStartInfo class to start new processes,
// both in a minimized mode.
void OpenWithStartInfo()
{
ProcessStartInfo startInfo = new ProcessStartInfo("IExplore.exe");
startInfo.WindowStyle = ProcessWindowStyle.Minimized;
Process.Start(startInfo);
startInfo.Arguments = "www.northwindtraders.com";
Process.Start(startInfo);
}
I'm trying to make an app that gives a quake style drop-down HUD console. I can get it to show and hide the window, but I can't figure out how to set it as the active window after showing it. Im using Win API calls to show and hide the window. I've tried SetForegroundWindow(IntPtr hWnd) and SetFocus(IntPtr hWnd) to no avail. Anyone have any ideas?
http://pastebin.com/DgtJJGiv
public void ShowApp()
{
IntPtr h = FindWindow(null, "C:\\Windows\\system32\\cmd.exe");
ShowWindow(h, SW_SHOW);
//EnableWindow(h, true);
isHidden = false;
// set focus to console window
SetForegroundWindow(h);
System.Diagnostics.Debug.WriteLine(h);
}
I found an answer here:
How to show form in front in C#
The winAPI approaches were not working correctly for me but this did:
form.TopMost = true;
form.TopMost = false;
I originally was only setting TopMost to true but I ran into problems with dialog boxes displaying behind the form. It appears that setting TopMost to true pulls the form to the front and holds it there. Setting it to false doesn't push it back but does allow other forms to be shown in front. I was still having problems with focus so I ended up going with the following:
form.Activate();
You may use SetActiveWindow winAPI method. Hope this helps...
Try this (works for me):
public static void ShowApp()
{
IntPtr h = FindWindow(null, "C:\\Windows\\system32\\cmd.exe");
ShowWindow(h, ShowWindowCommands.Show);
SetForegroundWindow(h);
SetFocus(h);
System.Diagnostics.Debug.WriteLine(h);
}
Is there any reason why you can't implement your own console window? What I mean is a simple Form with a Textbox set to the correct style. You would probably have more control over how it works than trying to use the 'cmd' process.
Just a thought.