home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Windows Gam…ming Gurus (2nd Edition) / Disc2.iso / msdn_vcb / samples / vc98 / sdk / sdktools / tlist / tlist.c < prev   
C/C++ Source or Header  |  1996-10-08  |  3KB  |  173 lines

  1.  
  2. /******************************************************************************\
  3. *       This is a part of the Microsoft Source Code Samples. 
  4. *          Copyright (C) 1994-1995 Microsoft Corporation.
  5. *       All rights reserved. 
  6. *       This source code is only intended as a supplement to 
  7. *       Microsoft Development Tools and/or WinHelp documentation.
  8. *       See these sources for detailed information regarding the 
  9. *       Microsoft samples programs.
  10. \******************************************************************************/
  11.  
  12. /*++
  13.  
  14. Copyright (c) 1994  Microsoft Corporation
  15.  
  16. Module Name:
  17.  
  18.     tlist.c
  19.  
  20. Abstract:
  21.  
  22.     This module implements a task list application.
  23.  
  24. --*/
  25.  
  26. #include <windows.h>
  27. #include <stdio.h>
  28. #include <stdlib.h>
  29. #include <string.h>
  30. #include "common.h"
  31.  
  32.  
  33. #define MAX_TASKS           256
  34.  
  35. #define PrintTask(idx) \
  36.         printf( "%4d %-16s", tlist[idx].dwProcessId, tlist[idx].ProcessName ); \
  37.         if (tlist[idx].hwnd) { \
  38.             printf( "  %s", tlist[idx].WindowTitle ); \
  39.         } \
  40.         printf( "\n" );
  41.  
  42.  
  43. DWORD numTasks;
  44. TASK_LIST tlist[MAX_TASKS];
  45.  
  46. VOID Usage(VOID);
  47.  
  48.  
  49. int _cdecl
  50. main(
  51.     int argc,
  52.     char *argv[]
  53.     )
  54.  
  55. /*++
  56.  
  57. Routine Description:
  58.  
  59.     Main entrypoint for the TLIST application.  This app prints
  60.     a task list to stdout.  The task list include the process id,
  61.     task name, ant the window title.
  62.  
  63. Arguments:
  64.  
  65.     argc             - argument count
  66.     argv             - array of pointers to arguments
  67.  
  68. Return Value:
  69.  
  70.     0                - success
  71.  
  72. --*/
  73.  
  74. {
  75.     DWORD             i;
  76.     TASK_LIST_ENUM    te;
  77.     BOOL              fTree;
  78.     OSVERSIONINFO     verInfo = {0};
  79.     LPGetTaskList     GetTaskList;
  80.     LPEnableDebugPriv EnableDebugPriv;
  81.  
  82.  
  83.     if (argc > 1 && (argv[1][0] == '-' || argv[1][0] == '/') && argv[1][1] == '?') {
  84.         Usage();
  85.     }
  86.  
  87.     //
  88.     // Determine what system we're on and do the right thing
  89.     //
  90.  
  91.     verInfo.dwOSVersionInfoSize = sizeof (verInfo);
  92.     GetVersionEx(&verInfo);
  93.  
  94.     switch (verInfo.dwPlatformId)
  95.     {
  96.     case VER_PLATFORM_WIN32_NT:
  97.        GetTaskList     = GetTaskListNT;
  98.        EnableDebugPriv = EnableDebugPrivNT;
  99.        break;
  100.  
  101.     case VER_PLATFORM_WIN32_WINDOWS:
  102.        GetTaskList = GetTaskList95;
  103.        EnableDebugPriv = EnableDebugPriv95;
  104.        break;
  105.  
  106.     default:
  107.        printf ("tlist requires Windows NT or Windows 95\n");
  108.        return 1;
  109.     }
  110.  
  111.  
  112.  
  113.     fTree = FALSE;
  114.  
  115.     //
  116.     // Obtain the ability to manipulate other processes
  117.     //
  118.     EnableDebugPriv();
  119.  
  120.     //
  121.     // get the task list for the system
  122.     //
  123.     numTasks = GetTaskList( tlist, MAX_TASKS );
  124.  
  125.     //
  126.     // enumerate all windows and try to get the window
  127.     // titles for each task
  128.     //
  129.     te.tlist = tlist;
  130.     te.numtasks = numTasks;
  131.     GetWindowTitles( &te );
  132.  
  133.     //
  134.     // print the task list
  135.     //
  136.     for (i=0; i<numTasks; i++) {
  137.     PrintTask( i );
  138.     }
  139.  
  140.     //
  141.     // end of program
  142.     //
  143.     return 0;
  144. }
  145.  
  146. VOID
  147. Usage(
  148.     VOID
  149.     )
  150.  
  151. /*++
  152.  
  153. Routine Description:
  154.  
  155.     Prints usage text for this tool.
  156.  
  157. Arguments:
  158.  
  159.     None.
  160.  
  161. Return Value:
  162.  
  163.     None.
  164.  
  165. --*/
  166.  
  167. {
  168.     fprintf( stderr, "Microsoft (R) Windows NT (TM) Version 3.5 TLIST\n" );
  169.     fprintf( stderr, "Copyright (C) 1994-1995 Microsoft Corp. All rights reserved\n\n" );
  170.     fprintf( stderr, "usage: TLIST\n" );
  171.     ExitProcess(0);
  172. }
  173.