Hide console window, not the taskbar button - c#

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.

Related

MFC app - Class library WPF window icon does not show up in taskbar

I have an MFC window-based app. I added a C# class library that provides a second window for login to the app. This second window is meant to show before the main MFC window and once the user successfully logs in, it will go away and the main window will launch. The problem I am having is that when the login window is showing there is no taskbar icon for it. This did work correctly when the login window was an MFC dialog.
To make debugging this window easier I made a small MFC test app from which I can launch the login window with a button click. (the main program is cumbersome to test with). I added a C# class library to it just as it is in the main program. When I launch the app the main MFC dialog app shows up and the app's icon appears on the taskbar. When I click the button to launch the WPF window, it appears but there is no icon in the taskbar. This window does not show on the taskbar as a second window of the app as I would expect.
I am having a really hard time with google finding relevant info.
I have tried specifying an icon for the window vs. not specifying one.
I have tried adding ShowInTaskbar="True" to the window.
I have tried changing WindowStyle
I have tried playing with TaskbarItemInfo.
I tried following New taskbar icon when opening a window in WPF, but I don't really understand it well enough to say that it will fix my issue since I do not get my window showing up at all and if I did I would be fine with it being stacked.
I am not sure where else to go with this. Please let me know if there is anything unclear.

Click outside wpf window without losing focus

I was wondering if there is a window property, for a wpf application, that disables any actions outside of the window. For example, when you open a message dialog and click outside of it, the message dialog background flashes. Kind of saying you can't do any actions outside of the message dialog untill you click the 'OK' button. I want that implemented in some windows that I open in a program i'm developing but can't seem to find any info on it. Looking for ways on how i might approach this.
Try ShowDialog() instead of Show()
Opens a window and returns only when the newly opened window is closed.
Window childWindow = new Window();
childWindow.ShowDialog();
Note that it will prevent clicks only on parent window(s). Clicks on other applications or Desktop can't be prevented by the Dialog.

close a WPF Dialog Window when the user clicks outside it

GoodDay, Here i want to minimize the WPF Window, While user clicking outside of the window.
I can easily minimize the window by this code
mywindow.WindowState= WindowState.Minimized;
but i want minimize the window at the time of clicking outside of the window.
i searched about that. But i can only got the output of various events like, FocusChanged,MouseMove,MouseDown like that. those are not solve my issue
You could use the Deactivatedevent. Have a look at the MSDN for further information.
A window is deactivated (becomes a background window) when:
A user switches to another window in the current application.
A user switches to the window in another application by using ALT+TAB or by using Task Manager.
A user clicks the taskbar button for a window in another application.

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

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...

Show modal window when parent window is activated

I am using C# and WinForms to create UI of my application.
I have main window and dialog, which is shown modal to the main window. Dialog window is not shown in task bar. I go to another application and return back by clicking at the main window task bat icon. I can see locked main window but cannot see dialog unless I select it in Alt-Tab. This is confusing for an application user.
How can I ensure showing modal window in this situation? I can see similar but unfortunately unsolved question ALT+TAB in Vista activates main window instead of previously active child window which regards to Vista (and I have Windows 7).
This is probably because you don't use the ShowDialog(owner) overload. You should fret a little bit about the exact reason that ShowDialog() cannot find an owner by itself and picked the desktop window instead. It isn't healthy. I cannot guess why from your post. See what explicitly setting the owner buys you.
Oh, this will happen when the dialog runs on its own thread. In which case ShowDialog(owner) is going to bomb.
It sounds like your dialog is not properly owned by the main window. Make sure you have assigned the main window to the dialog object's Owner property before showing the modal dialog.

Categories

Resources