home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / cenvi23.zip / WINQLIST.CMD < prev    next >
OS/2 REXX Batch file  |  1995-02-09  |  4KB  |  128 lines

  1. EXTPROC CEnvi2.exe
  2. //***********************************************************
  3. //*** WinQList.cmd - Show a list of all PM queues, their  ***
  4. //*** ver.1          sizes, and how many windows use them ***
  5. //***********************************************************
  6.  
  7. #define HWND_DESKTOP 1
  8. #define HWND_OBJECT  2
  9.  
  10. printf("\nBuild Queue List from Window handles...");
  11.  
  12. QueueCount = BuildQueueList(QueueList);
  13.  
  14. printf("\rProcess      ID      Queue    Size   Desktop Windows  Object Windows");
  15. printf("\n---------- ------    -----   ------  ---------------  --------------\n\n");
  16.  
  17. for ( q = 0; q < QueueCount; q++ ) {
  18.    hmq = QueueList[q].Queue;
  19.    if ( GetQueueData(hmq,ProcessList(),ProcessName,ProcessID,QueueSize) )
  20.       printf("%-10.10s   %-5d %04X    %-6d       %-6d        %-6d\n",
  21.              ProcessName,ProcessID,hmq,QueueSize,
  22.              QueueList[q].DesktopCount,QueueList[q].ObjectCount);
  23. }
  24.  
  25. /////////////////////////////////////////////////////////////////////////
  26.  
  27. BuildQueueList(QList)
  28. {
  29.    AddQueueForWindowAndChildren(QList,HWND_DESKTOP,True);
  30.    AddQueueForWindowAndChildren(QList,HWND_OBJECT,False);
  31.    return 1 + GetArraySpan(QList);
  32. }
  33.  
  34. AddQueueForWindowAndChildren(QList,ParentHandle,IsDesktopWindow)
  35. {
  36.    // Get the queue for this parent handle
  37.    Queue = GetWindowQueue(ParentHandle);
  38.  
  39.    // If this queue is not already in the queue list, then add it
  40.    if ( !defined(QList) ) {
  41.       QList[0].Queue = Queue;
  42.       QList[0].DesktopCount = IsDesktopWindow ? 1 : 0;
  43.       QList[0].ObjectCount = IsDesktopWindow ? 0 : 1;
  44.    } else {
  45.       // only show this queue if it hasn't already been shown
  46.       for ( i = GetArraySpan(QList); 0 <= i; i-- ) {
  47.          if ( Queue == QList[i].Queue ) {
  48.             if ( IsDesktopWindow )
  49.                QList[i].DesktopCount++;
  50.             else
  51.                QList[i].ObjectCount++;
  52.             break;
  53.          }
  54.       }
  55.       if ( i < 0 ) {
  56.          NewEntry.Queue = Queue;
  57.          NewEntry.DesktopCount = IsDesktopWindow ? 1 : 0;
  58.          NewEntry.ObjectCount = IsDesktopWindow ? 0 : 1;
  59.          QList[1+GetArraySpan(QList)] = NewEntry;
  60.       }
  61.    }
  62.  
  63.    // recursively call this routine for all its children
  64.    EnumHandle = WinBeginEnumWindows(ParentHandle);
  65.    while ( NULL != (WinHandle = WinGetNextWindow(EnumHandle)) ) {
  66.       AddQueueForWindowAndChildren(QList,WinHandle,IsDesktopWindow);
  67.    }
  68.    WinEndEnumWindows(EnumHandle);
  69. }
  70.  
  71. WinBeginEnumWindows(pHwndParent)
  72. {
  73.    #define ORD_WIN32BEGINENUMWINDOWS   702
  74.    return DynamicLink("PMWIN",ORD_WIN32BEGINENUMWINDOWS,BIT32,CDECL,pHwndParent)
  75. }
  76.  
  77. WinGetNextWindow(pHEnum)
  78. {
  79.    #define ORD_WIN32GETNEXTWINDOW      756
  80.    return DynamicLink("PMWIN",ORD_WIN32GETNEXTWINDOW,BIT32,CDECL,pHEnum)
  81. }
  82.  
  83. WinEndEnumWindows(pHEnum)
  84. {
  85.    #define ORD_WIN32ENDENUMWINDOWS     737
  86.    return DynamicLink("PMWIN",ORD_WIN32ENDENUMWINDOWS,BIT32,CDECL,pHEnum)
  87. }
  88.  
  89. GetWindowQueue(hwnd)
  90. {
  91.    #define ORD_WIN32QUERYWINDOWULONG   843
  92.    #define QWL_HMQ   (-4)
  93.    return DynamicLink("PMWIN",ORD_WIN32QUERYWINDOWULONG,BIT32,CDECL,
  94.                       hwnd,QWL_HMQ)
  95. }
  96.  
  97. GetQueueInfo(hmq,count,pid)
  98. {
  99.    #define ORD_WIN32QUERYQUEUEINFO  824
  100.    BLOBSize(qinfo,4 * 5);
  101.    success = DynamicLink("PMWIN",ORD_WIN32QUERYQUEUEINFO,BIT32,CDECL,
  102.                          hmq,qinfo,BLObSize(qinfo));
  103.    if ( success ) {
  104.       pid = BLObGet(qinfo,4 * 1,UWORD32);
  105.       count = BLObGet(qinfo,4 * 3,UWORD32);
  106.    }
  107.    return(success);
  108. }
  109.  
  110. GetQueueData(hmq,PList,ProcessName,ProcessID,QueueSize)
  111.    // return data about this queue and who owns it; False if cannot
  112. {
  113.    if ( !GetQueueInfo(hmq,QueueSize,ProcessID) )
  114.       return(False);
  115.  
  116.    // to find process name, match processID to id in PList
  117.    for ( p = GetArraySpan(PList); 0 <= p; p-- ) {
  118.       if ( ProcessID == PList[p].id ) {
  119.          ProcessName = SplitFileName(PList[p].name).name;
  120.          return(True);
  121.       }
  122.    }
  123.    // if got here, then all OK except for process name
  124.    ProcessName = "?????";
  125.    return(True);
  126. }
  127.  
  128.