How to hide an application from Alt-Tab?

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?
LVL 4
tflaiAsked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
ahalyaConnect With a Mentor Commented:
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
 
chensuCommented:
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
 
alexoCommented:

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
Receive 1:1 tech help

Solve your biggest tech problems alongside global tech experts with 1:1 help.

 
tflaiAuthor Commented:
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
 
plummerCommented:
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
 
tflaiAuthor Commented:
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
 
MelangeCommented:
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
 
ArkadiyCommented:
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
 
tflaiAuthor Commented:
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
 
alexoCommented:
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
 
tflaiAuthor Commented:
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
 
ahalyaCommented:
hi there,

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

i have the answer. (for Win 95).
0
 
tflaiAuthor Commented:
Ok, ahalya, I'm all ear if you've got the answer.
0
All Courses

From novice to tech pro — start learning today.