Fog Creek Software
g
Discussion Board




Win32: Task Manager->Applications List

It really shouldn't be this difficult,... but it is.  And our beloved Google did not find any solutions.  Just the same repetitive questions.

Now I'm in the Windows CE world, but that shouldn't make a difference in this case.

[Q:]  How to mimic the identical "Running Applications List" as displayed within Windows Task Manager?

*NOT* all the processes (which EnumWindows and even GetWindow, et al. seem to pick up as well).

Somehow, MS 'filters' the correct windows to display which belong to current running applications and those that do not.  And we all know that some apps. create multiple windows, yet the Task Manager intelligently still only displays one instance.

So far, my greatest success is the following:


case WM_INITDIALOG:

  memset( Apps, 0, sizeof(Apps) );
  Appcount = 0;

  hWnd = GetDesktopWindow ();

  while(hWnd != NULL)
  {
    GetWindowText( hWnd, *&Apps[Appcount], 64 );
    style = GetWindowLong(hWnd, GWL_STYLE);
    EXstyle = GetWindowLong(hWnd, GWL_EXSTYLE);
    GetWindowRect( hWnd, &rect );

    if( IsWindow(hWnd) )
    if( GetWindowTextLength(hWnd) != 0 )
    if( wcscmp(*&Apps[Appcount], szMyWindowTitle) != 0 )    // Omit our own.
    if( hWnd != GetParent(hDlg) )                // Omit our own.
    if( !(EXstyle & WS_EX_ABOVESTARTUP) )
    if( !(EXstyle & WS_EX_NOACTIVATE) )
    if( !((rect.top < 10) && (rect.left < 10) && (rect.bottom < 10) && (rect.right < 10)) )
    if( GetWindow(hWnd, GW_CHILD) != NULL )
        Appcount++;

    hWnd = GetWindow(hWnd, GW_HWNDNEXT);
  }


Yet still, some background apps. squeeze through and get displayed.

Are there some hidden 'Window' characteristics I'm still missing that could identify a regular user app versus some random background process?

My purpose is to fill a Listbox and allow the user to select which App. they would like incoming data to be relayed to. (Wedge stuff).

It frustrates me when 'straight-forward' theories crumble in the real world.

C'est la vie.

sedwo
Wednesday, April 28, 2004

HOWTO: Enumerate Applications Using Win32 APIs

http://support.microsoft.com/default.aspx?scid=kb;EN-US;175030

Just me (Sir to you)
Wednesday, April 28, 2004

Use the toolhelp library

PaulT
Wednesday, April 28, 2004

You guys are awesome.  Thank you!

sedwo
Wednesday, April 28, 2004

No:

google.com + microsoft.com = awsome

Just me (Sir to you)
Wednesday, April 28, 2004

*  Recent Topics

*  Fog Creek Home