-1

I need to create a sample windows application where the application should be hidden but the application icon should be there on the taskbar(not as a tray icon) How to do this? or is it possible to do this? When i use ShowWindow(hWnd, SW_HIDE), the application gets hidden but not seen on the taskbar. so i can't use this. I don't want to add it to trayicon. Please help me to do this

Akshatha
  • 39
  • 4
  • 1
    Sounds like you want to minimise it. – Andrew Truckle Mar 15 '17 at 06:46
  • no i don't want to minimize. actually it is kind of minimize but when you click on the taskbar menu, the application should not open. – Akshatha Mar 15 '17 at 06:52
  • Well, can you handle the OnSysCommand and if it is set to restore just suppress the call? I think the code is there by default. Not sure why you want to do this though. – Andrew Truckle Mar 15 '17 at 06:54
  • No. You want to minimise the window. That is how you keep the taskbar button showing. – David Heffernan Mar 15 '17 at 07:11
  • `ShowWindow(hWnd, SW_MINIMIZE)` – zett42 Mar 15 '17 at 07:39
  • ShowWindow(hWnd, SW_MINIMIZE) this i had tried. with this window gets minimised, but allows user to open it. This i not accepted. at any point we should give access to window to user. but button should be seen on the task bar. This is basically for client window. – Akshatha Mar 15 '17 at 08:06
  • 1
    This is making no sense at all. You want a button on the taskbar with no window behind it? Do you hate your users? Do you enjoy confusing them? – David Heffernan Mar 15 '17 at 08:35
  • As I explained you can suppress the restore message from processing but I agree that this is bad design and not what users expect. Maybe give more context in your question. – Andrew Truckle Mar 15 '17 at 09:10
  • no. i don't want to confuse the user. Say this is a client-server scenario. i don't want to show some window on the client. but there should be an icon on the taskbar to know the client that some application is running – Akshatha Mar 15 '17 at 09:13
  • 2
    But that is what the system tray is for. – Andrew Truckle Mar 15 '17 at 12:12
  • Sounds like you want to run a program to do something that does not have a GUI but for the time it runs show the icon on the task bar. – Andrew Truckle Mar 15 '17 at 15:59
  • Exactly.. system tray can be one of the option but the icon on the tray is very small. That's y decided to showing the taskbar and hide the window – Akshatha Mar 15 '17 at 17:43
  • @Akshatha: The systray is meant for notifications and status displays, just like you are describing. Just because the systray icon is small does not mean it can't show a larger window if the user clicks on it. – Remy Lebeau Mar 15 '17 at 19:00

2 Answers2

0

When i use ShowWindow(hWnd, SW_HIDE), the application gets hidden but not seen on the taskbar. so i can't use this.

When you hide/show a window, it also hides/shows its Taskbar button accordingly. A window on the Taskbar controls the visibility of its Taskbar button to match its own visibility. There is no option to prevent that behavior.

To do what you are asking, you would need to either:

  1. use SW_MINIMIZE instead of SW_HIDE, and then make your window discard any WM_SYSCOMMAND messages is receives that have their wParam set to either SC_RESTORE or SC_MAXIMIZE.

  2. create a separate window just to manage the Taskbar button. Don't hide that window, but you can create it with 0x0 dimensions, or move it off-screen. Just know that any activity the user performs on the Taskbar button will be reflected on this separate window, so you will have to delegate any user actions to your real window as needed. Also, to support things like Live Previews on the Taskbar and Alt-Tab/Flip3D dialogs, you will have to handle the WM_DWMSENDICONICLIVEPREVIEWBITMAP and WM_DWMSENDICONICTHUMBNAIL messages, rendering your real window to an in-memory BMP when requested.

That being said, either approach is the wrong solution.

Say this is a client-server scenario. i don't want to show some window on the client. but there should be an icon on the taskbar to know the client that some application is running

You shouldn't be using the Taskbar just to show the user that an app is running without a visible window. That is not what the Taskbar is meant for. Use the Notification Area instead (more commonly known as the "System Tray"). This is exactly the kind of scenario that the Notification Area is intended for.

I don't want to add it to trayicon.

Regardless of what you want, this is what you should be doing. That is what Microsoft expects you to do, and what users will be expecting as well.

You can display a status icon in the Notification Area while your app is running, and if the user wants more details then you should display a window when the user clicks on and/or hovers over the icon.

i don't want to confuse the user.

Then don't do things that the user is not expecting. Ever since the Taskbar was first introduced in Windows 95, users have become accustomed to only seeing visible windows on the Taskbar, and status icons in the System Tray. Don't break that expectation. And don't break the UI guidelines that Microsoft has established.

  • Following User Interface Guidelines

  • Taskbar

    A program that normally runs without desktop presence should use its notification area icon instead, even though it might not always be visible.

  • Notification Area

    The notification area is a portion of the taskbar that provides a temporary source for notifications and status. It can also be used to display icons for system and program features that have no presence on the desktop.

Community
  • 1
  • 1
Remy Lebeau
  • 555,201
  • 31
  • 458
  • 770
  • i am planning to with first option.i.e use SW_MINIMIZE instead of SW_HIDE, and then make your window discard any WM_SYSCOMMAND messages is receives that have their wParam set to either SC_RESTORE or SC_MAXIMIZE. – Akshatha Mar 16 '17 at 12:31
  • Can some one help me how to do this?i.e how to discard the any WM_SYSCOMMAND messages – Akshatha Mar 16 '17 at 12:33
  • @Akshatha: what is unclear about it exactly? You have a window, it has a window procedure assigned to it for handling incoming messages. Simply have that procedure check each message, and if it needs to be discarded then don't pass it along to the default message handler. – Remy Lebeau Mar 16 '17 at 18:13
  • Yes i have checked for each message in windows procedure. after that how to discarded if i don't want to respond to a particular message ( like you said don't pass it along to the default message handler. how to do this?) – Akshatha Mar 23 '17 at 12:10
  • @Aks what part of "don't pass it to the default handler" is unclear? Just exit the procedure with a default result (usually zero). – Remy Lebeau Mar 23 '17 at 14:38
  • i did this way. but it is not working.case WM_ACTIVATEAPP: if(wParam & WM_LBUTTONDOWN) {return -1; } what am I doing wrong here? – Akshatha Mar 23 '17 at 14:43
  • @Aks well for starters, you clearly did not read the [documentation](https://msdn.microsoft.com/en-us/library/windows/desktop/ms632614.aspx). Where does it say that `wParam` will contain `WM_LBUTTONDOWN`? It doesn't. The `wParam` contains a `BOOL` value in that message, it will be either `TRUE` or `FALSE` only. And you are suppose to return 0, not -1. But `WM_ACTIVATEAPP` is just a notification, it does not matter if it is discarded or not. What matters more is discarding command messages, not notification messages. – Remy Lebeau Mar 23 '17 at 14:55
0

::MoveWindow(hwnd_MyMainWnd, -5000, -5000, 10, 10, FALSE);

  • 1
    As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Apr 05 '22 at 08:42