Having a window with ShowInTaskbar, Topmost, but also a notification area icon - c#

I have a program I want to be able to handle all three states:
Not showing in taskbar, acting just as a widget like the Windows sound, network programs etc
Showing in taskbar - but not Topmost. The window would still show the notification area icon, and should still behave in the same way as #1, but also show the window in the taskbar.
Showing in taskbar with topmost. The window should behave the same as #2, but now the window will show topmost. Note: it should still be capable of being minimised, in the same way that clicking on a taskbar icon minimises a program.
These are my criteria, and I have been working on having them all working nicely together, but I can't seem to get the last few tweaks ironed out. #1 is fine - I have sorted that out easily enough. #2 and #3 cause more issues.
My first question is, how does Windows handle the user clicking on a taskbar icon to get it to minimise/switch back to normal? As I'd prefer to emulate that with #2 and #3.
For #1 I currently hide the window simply by setting Window.Visibility to Visibility.Hidden. And to show the window, call Show() and then Activate().
Like I said, for #2 and #3, I'd like to copy what Windows does when the user clicks on the taskbar icon. Can I do that? Or would I have to find another way to do this?

1- this is called thumbnail buttons
You can check http://elegantcode.com/2010/12/17/wpf-adding-thumbnail-buttons-to-windows-7-task-bar/ OR http://shareourideas.com/2010/12/19/windows-7-taskbar-thumbnail-buttons-in-wpf/ OR http://msdn.microsoft.com/en-us/library/ff699128.aspx
2- there is property called TopMost in the Window class.
3- for the taskbar icon
you can use this library it is easy to use and powerful http://www.codeproject.com/Articles/22876/WPF-Taskbar-Notifier-A-WPF-Taskbar-Notification-Wi
4- to minimize and maximize you can simply use
this.WindowState = FormWindowState.Maximized;
* that is all the info you need to create your application as you want, if you face any problems read the articles well if the problem still there find where is the problem exactly and ask again.
hope this help...

Related

Change application name shown in Windows 10 taskbar [duplicate]

I develop with VS2010 in C# and I would like to create a WPF Window which have a taskbar text different from the Window title.
The property Title set both the window title and the taskbar text. Is there a way to set them separatly?
First, let me reinforce what Cody Gray said in both his answer and comment - this is non-standard behavior, and you should have a darn good reason for doing this.
That being said, I would take a nearly opposite approach to Cody's point #1. I would create a window WindowStyle set to None, and recreate the title bar (which could include the icon, your "pseudo-title," minimize, maximize, and close buttons, and perhaps even the standard Windows menu. You will also need to handle resizing (which can be done by setting ResizeMode to CanResizeWithGrip, but it adds a Grip control to the bottom of your window, which makes it look slightly different than a "normal" window).
The Title property of this window would then be the Title you want to show in the Taskbar, and the "pseudo-title" in the title bar you create would just be a Label or TextBlock bound to whatever you want your window to show.
It is a little complex, but really not too difficult to do. You will probably run into some Gotchas along the way (for instance, how the Window looks on different OS's or with different Windows themes applied). The nice thing is that it requires no Interop, and a majority of it can be attained using XAML only.
There are lots of examples online (here is one I picked at random).
Again, you'll have to decide if it is worth the effort to create a non-standard behavior. YMMV.
Basically, you have two options:
Draw the taskbar button yourself, rather than letting Windows handle it. This is actually reasonably simple, as far as owner drawing things goes.
Manage two different forms/windows simultaneously. You'll need to create a hidden main window that will appear on the taskbar and own your second window. Your second window will be visible, display its own caption on its title bar, and contain your actual user interface, but won't show up on the taskbar (set its ShowInTaskbar property to "False"). You'll have to write code to show the second window whenever the first one is activated using the taskbar.
I recommend that before starting down either one of these paths, you carefully consider whether you really need this "functionality". It's difficult to tell what goes with what if you have what is effectively one window with different names in different places.
try to use this:
http://www.codeguru.com/forum/showthread.php?t=3833
in conjunction with
http://social.msdn.microsoft.com/Forums/en-US/wpf/thread/6b97a6de-0480-4339-8ed0-cb7cdb27bd83
The first one works fine for me in classical .NET form application when I have made window without title bar and want some text in task bar icon.
The second one you need to handle low level WIN32 messages in WPF window (but this works only for top level one).

Cycle through open windows in C# using ALT+TAB/ESC and have the current window in focus and forced to be maximized (if already minimized to taskbar)?

I am writing a small application to automatically rotate through open windows on Windows 7/8.1/10 PC's. I have written the majority of the code and it is working well except I cannot figure out or find out what key presses to use to cycle through open applications.
I have tried SendKeys.Send("%{Tab 2}"); but this seems to only actually press the TAB button once as it keeps switching between the same two windows (even though more are open).
I have tried SendKeys.Send("%+{Esc}"); but this doesn't maximize windows that are minimized to the taskbar. It will effectively cycle through each open windows and bring them into focus (as evident by watching the white semi-transparent overlay on the taskbar item) but it won't show them on screen - I'm assuming because they started minimized. Only the maximized ones will show on screen when it's their turn.
Can anyone please assist? I'm sure it's a simple fix of maximizing the window it cycles to but I'm unsure how to implement this.
I haven't included the code of the entire application as I don't think it is relevant. If you do require it please let me know and I will add it.
Many thanks.

Hide console window, not the taskbar button

I am in a need of hiding the console window, which I quickly resolved by P/Invoking ShowWindow. However, the call hides the console window as well as the taskbar button of the console window. I need the taskbar button to remain visible. I am not, however, looking for a way to minimize the console window. Clicking the taskbar button show not do anything. I tried to use SetWinEventHook and hide the window every time it was activated, but to no avail, as the window calling this function must run message loop in order to receive the events (and my console window didn't, no matter if I set OutOfContext or InContext flag).
Is there a way I can make my console application run, show itself in taskbar, then hide itself (or never show itself in a first place) and just keep running with no window but taskbar button visible?
The normal way to get a button on the taskbar is to create a visible unowned top-level window. So that's no use to you. One possible alternative is to use ITaskbarList::AddTab to add a button. I don't know whether or not this will do anything for an invisible window. Either way you'd need to run a message loop for your window. Even if you could do this the net result would not feel very nice for the user.

TopMost window going behind non-TopMost fullscreen window sometimes

I have a "control toolbar" app that needs to float on top of everything else on the primary screen of a dual monitor system. It positions itself at the top of the primary screen and sets TopMost=true.
This control toolbar can be used to launch two other processes which run fullscreen but NOT TopMost, one on each monitor on the dual monitor system. These windows are setup to run fullscreen by setting BorderStyle to None and setting the bounds of the window to fit exactly into the screen dimensions. The fullscreen windows have no problem covering the taskbar, and I can focus and interact with the fullscreen window on the primary monitor all day and the toolbar stays on top.
All is not peachy in the kingdom of software however - certain actions make the TopMost toolbar pop under the non-TopMost fullscreen windows. One of those actions is giving focus to the fullscreen app on the secondary monitor, then giving focus back to the fullscreen app on the primary monitor. This is the easiest situation to reproduce as it happens every time I follow this sequence. I have a hard time reproducing other scenarios reliably, but if I hit the windows key to pull up the start menu and start browsing in Internet Explorer, sometimes when I am done browsing and close IE and give focus back to the primary monitor fullscreen app it pops over the TopMost window.
Any idea how to keep the TopMost window on top, and not allow it to pop under a non-TopMost fullscreen window? I wouldn't mind doing something like polling WindowFromPoint once a second to see if the toolbar is still on top and if not then pop it back over somehow, but I don't want to take focus away from the fullscreen app if that's what the user is using, so Activate() isn't a particularly good solution.
I don't think this really matters, but the toolbar is a WPF window and the fullscreen apps are WinForms.
UPDATE:
The easiest way to test this is to press F11 to go fullscreen in two browser windows on each monitor to simulate the full screen apps and then have a TopMost window floating anywhere. Click between the two fullscreen windows and you will see the TopMost window pop under them. I opened IE on one monitor and Chrome on another since IE doesn't let me do two fullscreen windows.
I implemented the Activate() hack for now, but it's a rather ugly solution because it activates the toolbar app which unfocuses the fullscreen app, which in turn makes the taskbar pop over the fullscreen app. Kind of hacky when all you want to do is switch which fullscreen app has focus.
Okay, here is what I ended up doing...I came up with one more idea before I was going to give up and this works well. In the toolbar window I have a timer that polls the top most window over the toolbar area once a second, like this:
var topMostHandle = WindowFromPoint((int)(Left + ActualWidth / 2), (int)ActualHeight / 2);
if (topMostHandle != new WindowInteropHelper(this).Handle)
{
Topmost = false;
Topmost = true;
}
So I basically just take a point in the middle of the toolbar and test to see if the toolbar is on top. If not, I set TopMost to false and back to true, which seems to bring it back on top without activating it. The flash where it disappears for a second is slightly annoying but I don't expect this to happen often.
Credit to Hans Passant for finding a hotfix for Win7 SP1 that addresses the problem: http://support.microsoft.com/kb/2733420
I kept my hack in the code in case clients can't/aren't running the hotfix as a workaround.

Setting focus on control causes windows tool bar to appear

When I set focus on a text box, on a forms load event in Windows Mobile 5.0, the Windows tool bar appears even though my form is maximized.
When I do not set the focus on the text box the form opens maximized. I do not want the windows tool bar appearing.
How do I prevent this from happening?
TThe start bar in WinMo is actually not part of your app - it is a separate process managed by the Shell and it really wants to always be on top. Trying to get your app above it goes against the design goals of WinMo (though it's a common thing to want to do).
I'd recommend doing some searching and reading on "kiosk mode" to garner what knowledge you can from others who have been down this road, but what you're seeing is that the StartBar is getting set topmost.
Raffaelle Limosani has a pretty decent blog entry that covers kiosk mode, so it's a good place to start (take a look at the other blogs he links to as well).
The toolbar at the top is actually a separate window, and it has a habit of appearing when not wanted over top of a full-screen ("kiosk" mode) app. For example, if you ShowDialog a second full-screen window from the first, the Start window flickers up for a split second before going away.
The only way I ever found of dealing with it was to hack into the API and actually make the Start window hidden while my application was open. This is a big potential problem, because if your app crashes without making the Start window visible again, it will stay invisible until you reset the device (or run you app again successfully).
I'd advice against doing this unless you absolutely have to. As ctacke points out, this would be an example of an app not playing nicely with Windows Mobile.

Categories

Resources