Solved

How to hide an application from Alt-Tab?

Posted on 1997-12-15
13
598 Views
Last Modified: 2013-12-03
Hi,
I've be able to remove my application from the task bar, without resorting to use WS_EX_TOOLWINDOW (which would make my window looks extremely crappy, without system menu, icon, and minimize/maximize).  (The application would provide UI through the system tray icon.)  But the problem is that it still left in the selection on Alt-Tab.  Is there anyway to remove it from Alt-Tab?
0
Comment
Question by:tflai
  • 5
  • 2
  • 2
  • +4
13 Comments
 
LVL 23

Expert Comment

by:chensu
ID: 1409574
How to prevent Alt-Tab has been asked several times on this topic area. The answer is that you cannot disable it in Windows 95 and Windows NT. For a system tray application, why don't you hide it and show it when it is activated?
0
 
LVL 11

Expert Comment

by:alexo
ID: 1409575

Hmmm...

Chesnu seemes to misunderstand the question.

Take a look at this bit of code.  I've copied it from one of my programs.  Doesn't show on ALT-TAB

(The spacing will probably be botched.)

int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
      WNDCLASS            wc            = { 0 };
      NOTIFYICONDATA      nid            = { sizeof(NOTIFYICONDATA) };
      HWND                  hwnd;

      UNREFERENCED_PARAMETER(hPrevInstance);
      UNREFERENCED_PARAMETER(lpCmdLine);
      UNREFERENCED_PARAMETER(nCmdShow);

      // Register the window class for the application main window
      wc.style             = CS_HREDRAW | CS_VREDRAW;            // Class style(s)
      wc.lpfnWndProc       = (WNDPROC) WindowProc;            // Window Procedure
      wc.hInstance       = hInstance;                              // Owner of this class
      wc.lpszMenuName  = MAKEINTRESOURCE(IDR_MENU);      // Menu
      wc.lpszClassName = APP_NAME;                              // Name to register as

      if (!RegisterClass(&wc))
            return 0;

      // Create a main window for this application instance.
      hwnd = CreateWindow(APP_NAME, APP_NAME,                              // Class and title
                                    WS_OVERLAPPEDWINDOW,                        // Window style
                                    CW_USEDEFAULT, 0,                              // Use default positioning
                                    CW_USEDEFAULT, 0,                              // Use default size
                                    NULL, NULL,                                          // No parent, no menu
                                    hInstance,                                          // This instance owns this window
                                    NULL);                                                // Don't need data in WM_CREATE
      if (!hwnd)
            return 0;

      // Link with tray icon
      nid.hWnd = hwnd;
      nid.uID = IDI_TRAYICON;
      nid.uFlags = NIF_MESSAGE | NIF_ICON | NIF_TIP;
      nid.uCallbackMessage = MYWM_NOTIFYICON;
      nid.hIcon = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_TRAYICON));
      lstrcpy(nid.szTip, APP_NAME);

      if (!Shell_NotifyIcon(NIM_ADD, &nid))
            return 0;


0
 
LVL 4

Author Comment

by:tflai
ID: 1409576
Hmm...  I've tried alexo's approach, and doesn't seems to work.  Am I missing something?  Actually, I've a MFC dialog-based application that also create a system tray icon and notification.  So, the icon notification basically just does show/close the main dialog window (left-double click or right-click to show pop-up menu).  It's this dialog box that I can't seem to get ride of in Alt-Tab.  I did forcefully remove it from the taskbar after Windows create it in the taskbar.  I know that by making the dialog window WS_EX_TOOLWINDOW, it will disappear, but I don't want to do that.
0
 

Expert Comment

by:plummer
ID: 1409577
Create a window but do not show it.  Make it the parent of the window you want to not appear in the alt-tab or tray (ie: create your main window as a child of the dummy window just described).  Your main window is not WS_CHILD, but has a parent, and is therefore owned and will not appear on the tray or in the alt-tab list.
0
 
LVL 4

Author Comment

by:tflai
ID: 1409578
Sorry to reject the answer.  But I just couldn't duplicate what alexo
and plummer were talking about.  If you could, can you e-mail me
a simplified version of how to hide application from Alt-Tab on
a MFC dialog-based application.  (Actually I do have source code
for hidding a MDI-based application, but it didn't work when I tried
to duplicate what it is doing to MainFrame as to my main
DialogBox.)  Also, I've found out that even
if I made the main window WS_EX_TOOLWINDOW, any
subsequent pop-up modal dialog boxes will shows up itself in
both taskbar and Alt-Tab.
0
 
LVL 3

Expert Comment

by:Melange
ID: 1409579
What's wrong with letting the dialog appear in the task bar? Take the volume control, for example. Normally it's sitting there innocently on the task bar with its window (dialog) completely hidden. But, when clicked the window pops up and appears in the task bar becoming a fully functional app.

To me this behaviour would be more desirable.
0
Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

 
LVL 1

Expert Comment

by:Arkadiy
ID: 1409580
OK, when you want to hide a window from task bar you make it a popup window with an invisible owner (i.e. create a hidden main window (overlapped) and create a modeless dialog with that main window as an owner). But I agree with Melange: when you only have an icon, hide the dialog, it will not appear on the task bar. And when the dialog is activated, you really want it to be on the task bar.
0
 
LVL 4

Author Comment

by:tflai
ID: 1409581
Okay, then, I'll just leave it on the taskbar.  Thanks.  Hmm....  How do I resolve the problem of giving grade away?  Who get the point?
0
 
LVL 11

Expert Comment

by:alexo
ID: 1409582
Who do you want to give the points to?
Ask a specifig person to submit an answer and grade it.

If you want to split the points between several persons, just enter some dummy questions titled "for <name>".

You can also ask the admins to cancel the question and refund the points since you didn't get the answer.

However, it's a shame to leave the question unanswerd.
Since you're using MFC, try to check the MFC sources to see whether it does things behind the scenes that might interfere with your goal.

Check the window style, maybe it will work if you change it.  However, see the help file topic "FAQ: Changing the Styles of a Window Created by MFC".

Maybe you'll need to hide the window (or to disable it) after creation.

Also, you can ask a zero-points question in the MFC area, in which you point to this question.  Something like "Please answer my question in another area" and in the body give the question name, number and URL.

Best of luck.



0
 
LVL 4

Author Comment

by:tflai
ID: 1409583
Well, I've decided to withdraw this question and save my points for
tougher questions in the future, :-)  Thanks for everyone's help, but
I can't reallyjudge how to distribute the points if I wanted to do that...
0
 
LVL 7

Expert Comment

by:ahalya
ID: 1409584
hi there,

if you're still interested in an answer then let me know.

i have the answer. (for Win 95).
0
 
LVL 4

Author Comment

by:tflai
ID: 1409585
Ok, ahalya, I'm all ear if you've got the answer.
0
 
LVL 7

Accepted Solution

by:
ahalya earned 100 total points
ID: 1409586
OK. Here i open my mind  !

You have to use the "RegisterServiceProcess" function to pretend that your prog is a service (yeah, kind of) in Win 95.

Declaration:

function RegisterServiceProcess (ThreadID:THandle;Flags:Integer):
Integer; stdcall; external kernel32 name 'RegisterServiceProcess';

Usage: {say in your formcreate event}
const      RSP_SIMPLE_SERVICE = 1;
      RSP_UNREGISTER_SERVICE = 0;

ok := RegisterServiceProcess (0, RSP_SIMPLE_SERVICE);
if ok  = 0 then ShowMessage ('Error Registering Service');

As you'd figure out a "side effect" of calling RSP is that you program will not appear in the task list anymore ! (isn't that nice !)

yeah, you can pass RSP_UNREGISTER_SERVICE and make your app a regular one at any time !
0

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

This article describes a technique for converting RTF (Rich Text Format) data to HTML and provides C++ source that does it all in just a few lines of code. Although RTF is coming to be considered a "legacy" format, it is still in common use... po…
zlib is a free compression library (a DLL) on which the popular gzip utility is built.  In this article, we'll see how to use the zlib functions to compress and decompress data in memory; that is, without needing to use a temporary file.  We'll be c…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now