home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / cenvi23.zip / EXAMINEW.CMD < prev    next >
OS/2 REXX Batch file  |  1995-03-28  |  15KB  |  400 lines

  1. EXTPROC CEnvi2
  2. //************************************************************************
  3. //*** ExamineW.cmm - CEnvi2 utility to examine properties of the active ***
  4. //*** ver.1          window. This provides information to use with     ***
  5. //***                other window menu, dialog, and message calls.     ***
  6. //************************************************************************
  7.  
  8. #define CHECK_INTERVAL  2000  // approx. milliseconds between check for ctrl-shift
  9.  
  10. #include <WinTools.lib>
  11. #include <GiveMem.lib>
  12. //#include <Window.lib>
  13. //#include <MenuCtrl.lib>
  14.  
  15.  
  16. #define HWND_DESKTOP    1
  17.  
  18. printf("ExamineW - Examine properties of the active window.  At any time\n"
  19.        "           press and hold Ctrl-Shift to bring up this window to\n"
  20.        "           describe great detail about the state of the currently\n"
  21.        "           active window.\n");
  22.  
  23. // many routines here require that the PM process making these calls also
  24. // have access to the shared memory
  25. GiveMemoryToProcess(PMInfo().Process);
  26.  
  27.  
  28. printf("\n***************************************************************************");
  29. printf("\nWaiting for Ctrl-Shift...");
  30. WaitForKeysHeld();
  31. printf("\a\r                                                    \r");
  32.  
  33. DescribeCurrentWindow();
  34.  
  35. WaitForKeysHeld() // wait for keys to be held
  36. {
  37.    #define VK_SHIFT     0x09
  38.    #define VK_CTRL      0x0A
  39.    // first wait for keys to not all be down before continuing
  40.    while ( KeyPressed(VK_SHIFT)  &&  KeyPressed(VK_CTRL) ) ;
  41.  
  42.    do {
  43.       suspend( CHECK_INTERVAL );
  44.    } while ( !KeyPressed(VK_SHIFT)  ||  !KeyPressed(VK_CTRL) );
  45. }
  46.  
  47.  
  48. DescribeCurrentWindow()
  49. {
  50.    // show title and handle for active window
  51.    if ( !(ActiveHwnd = GetActiveWindow()) ) {
  52.       printf("Active window handle unknown.\n");
  53.       return;
  54.    }
  55.    if ( !(ActiveTitle = GetWindowTitle(ActiveHwnd)) ) ActiveTitle = "<Unknown>";
  56.    printf("Active window \"%s\", handle = %08X\n",ActiveTitle,ActiveHwnd);
  57.  
  58.    // show title and handle for focus window
  59.    if ( !(FocusHwnd = GetFocusChild(ActiveHwnd)) ) {
  60.       printf("No focus window\n");
  61.    } else {
  62.       printf("Focus window");
  63.       if ( FocusTitle = GetWindowText(FocusHwnd) )
  64.          printf(" \"%s\"",FocusTitle);
  65.       printf(" handle = %04X\n",FocusHwnd);
  66.    }
  67.  
  68.    ShowWindowDetails(ActiveHwnd,0);
  69. }
  70.  
  71. ShowWindowDetails(hwnd,Level)
  72. {
  73.    printf("%04X",hwnd);
  74.    if ( Title = GetWindowText(hwnd) )
  75.       printf(" \"%s\"", Title);
  76.    printf("\n");
  77.  
  78.    in = Level + 1;
  79.  
  80.    #define QWS_ID (-1)
  81.    inprintf(in,"ID: ");
  82.    ShowWindowID(WinQueryWindowUShort(hwnd,QWS_ID));
  83.  
  84.    GetWindowRect(hwnd,lRect);
  85.    inprintf(in,"Coordinates: (L,B,R,T) %d, %d, %d, %d\n",
  86.             lRect.left,lRect.bottom,lRect.right,lRect.top);
  87.  
  88.    #define QWL_STYLE (-2)
  89.    ShowStyle(in,lStyle = WinQueryWindowULong(hwnd,GWL_STYLE));
  90.  
  91.    //inprintf(in,"ExtendedStyle: %08X\n",GetWindowLong(hwnd,GWL_EXSTYLE));
  92.  
  93.    ShowClass(in,hwnd);
  94.  
  95.    //if ( (lStyle & WS_SYSMENU)  &&  0 != (lMenu = GetSystemMenu(hwnd)) ) {
  96.    //   inprintf(in,"SYSTEM MENU:\n");
  97.    //   ShowMenu(in,lMenu);
  98.    //}
  99.  
  100.    //if ( !(lStyle & WS_CHILD)  &&  0 != (lMenu = GetMenu(hwnd)) )
  101.    //   ShowMenu(in,lMenu);
  102.  
  103.    // Do this same routine for each child window of this window
  104.    lEnum = WinBeginEnumWindows(hwnd);
  105.    while ( lChild = WinGetNextWindow(lEnum) ) {
  106.       printf("\n");
  107.       inprintf(Level,"  ");
  108.       ShowWindowDetails(lChild,in);
  109.    }
  110.    WinEndEnumWindows(lEnum);
  111. }
  112.  
  113. ShowWindowID(pID)
  114. {
  115.    #define FID_SYSMENU     0x8002
  116.    #define FID_TITLEBAR    0x8003
  117.    #define FID_MINMAX      0x8004
  118.    #define FID_MENU        0x8005
  119.    #define FID_VERTSCROLL  0x8006
  120.    #define FID_HORZSCROLL  0x8007
  121.    #define FID_CLIENT      0x8008
  122.    #define FID_DBE_APPSTAT 0x8010
  123.    #define FID_DBE_KBDSTAT 0x8011
  124.    #define FID_DBE_PECIC   0x8012
  125.    #define FID_DBE_KKPOPUP 0x8013
  126.    switch ( pID ) {
  127.       case FID_SYSMENU:       lID = "FID_SYSMENU";       break;
  128.       case FID_TITLEBAR:      lID = "FID_TITLEBAR";      break;
  129.       case FID_MINMAX:        lID = "FID_MINMAX";        break;
  130.       case FID_MENU:          lID = "FID_MENU";          break;
  131.       case FID_VERTSCROLL:    lID = "FID_VERTSCROLL";    break;
  132.       case FID_HORZSCROLL:    lID = "FID_HORZSCROLL";    break;
  133.       case FID_CLIENT:        lID = "FID_CLIENT";        break;
  134.       case FID_DBE_APPSTAT:   lID = "FID_DBE_APPSTAT";   break;
  135.       case FID_DBE_KBDSTAT:   lID = "FID_DBE_KBDSTAT";   break;
  136.       case FID_DBE_PECIC:     lID = "FID_DBE_PECIC";     break;
  137.       case FID_DBE_KKPOPUP:   lID = "FID_DBE_KKPOPUP";   break;
  138.       default:
  139.          printf("%04X\n",pID);
  140.          return;
  141.    }
  142.    printf("%s\n",lID);
  143. }
  144.  
  145. ShowStyle(in,pStyle)
  146. {
  147.    #define FS_ICON            0x00000001
  148.    #define FS_ACCELTABLE      0x00000002
  149.    #define FS_SHELLPOSITION   0x00000004
  150.    #define FS_TASKLIST        0x00000008
  151.    #define FS_NOBYTEALIGN     0x00000010
  152.    #define FS_NOMOVEWITHOWNER 0x00000020
  153.    #define FS_SYSMODAL        0x00000040
  154.    #define FS_DLGBORDER       0x00000080
  155.    #define FS_BORDER          0x00000100
  156.    #define FS_SCREENALIGN     0x00000200
  157.    #define FS_MOUSEALIGN      0x00000400
  158.    #define FS_SIZEBORDER      0x00000800
  159.    #define FS_AUTOICON        0x00001000
  160.    #define FS_DBE_APPSTAT     0x00008000
  161.  
  162.    #define WS_GROUP           0x00010000
  163.    #define WS_TABSTOP         0x00020000
  164.    #define WS_MULTISELECT     0x00040000
  165.    #define WS_ANIMATE         0x00400000
  166.    #define WS_MAXIMIZED       0x00800000
  167.    #define WS_MINIMIZED       0x01000000
  168.    #define WS_SYNCPAINT       0x02000000
  169.    #define WS_SAVEBITS        0x04000000
  170.    #define WS_PARENTCLIP      0x08000000
  171.    #define WS_CLIPSIBLINGS    0x10000000
  172.    #define WS_CLIPCHILDREN    0x20000000
  173.    #define WS_DISABLED        0x40000000
  174.    #define WS_VISIBLE         0x80000000
  175.    #define WS_UNUSED_BITS     0x00386000
  176.  
  177.    // show style, and decipher it
  178.    inprintf(in,"Style: %08X\n",pStyle);
  179.    lStr[0] = '\0';
  180.    if ( pStyle & WS_VISIBLE )       strcat(lStr,"VISIBLE|");
  181.    if ( pStyle & WS_DISABLED )      strcat(lStr,"DISABLED|");
  182.    if ( pStyle & WS_CLIPCHILDREN )  strcat(lStr,"CLIPCHILDREN|");
  183.    if ( pStyle & WS_CLIPSIBLINGS )  strcat(lStr,"CLIPSIBLINGS|");
  184.    if ( pStyle & WS_PARENTCLIP )    strcat(lStr,"PARENTCLIP|");
  185.    if ( pStyle & WS_SAVEBITS )      strcat(lStr,"SAVEBITS|");
  186.    if ( pStyle & WS_SYNCPAINT )     strcat(lStr,"SYNCPAINT|");
  187.    if ( pStyle & WS_MINIMIZED )     strcat(lStr,"MINIMIZED|");
  188.    if ( lStr[0] )
  189.       inprintf(in,"       %s\n",lStr);
  190.    lStr[0] = '\0';
  191.    if ( pStyle & WS_MAXIMIZED )     strcat(lStr,"MAXIMIZED|");
  192.    if ( pStyle & WS_ANIMATE )       strcat(lStr,"MAXIMIZED|");
  193.    if ( pStyle & WS_MULTISELECT )   strcat(lStr,"MULTISELECT|");
  194.    if ( pStyle & WS_TABSTOP )       strcat(lStr,"TABSTOP|");
  195.    if ( pStyle & WS_GROUP )         strcat(lStr,"GROUP|");
  196.    if ( pStyle & FS_DBE_APPSTAT )   strcat(lStr,"DBE_APPSTAT|");
  197.    if ( pStyle & FS_AUTOICON )      strcat(lStr,"AUTOICON|");
  198.    if ( pStyle & FS_SIZEBORDER )    strcat(lStr,"SIZEBORDER|");
  199.    if ( lStr[0] )
  200.       inprintf(in,"       %s\n",lStr);
  201.    lStr[0] = '\0';
  202.    if ( pStyle & FS_MOUSEALIGN )    strcat(lStr,"MOUSEALIGN|");
  203.    if ( pStyle & FS_SCREENALIGN )   strcat(lStr,"SCREENALIGN|");
  204.    if ( pStyle & FS_BORDER )        strcat(lStr,"BORDER|");
  205.    if ( pStyle & FS_DLGBORDER )     strcat(lStr,"DLGBORDER|");
  206.    if ( pStyle & FS_SYSMODAL )      strcat(lStr,"SYSMODAL|");
  207.    if ( pStyle & FS_NOMOVEWITHOWNER)strcat(lStr,"NOMOVEWITHOWNER|");
  208.    if ( pStyle & FS_NOBYTEALIGN )   strcat(lStr,"NOBYTEALIGN|");
  209.    if ( pStyle & FS_TASKLIST )      strcat(lStr,"TASKLIST|");
  210.    if ( lStr[0] )
  211.       inprintf(in,"       %s\n",lStr);
  212.    lStr[0] = '\0';
  213.    if ( pStyle & FS_SHELLPOSITION ) strcat(lStr,"SHELLPOSITION|");
  214.    if ( pStyle & FS_ACCELTABLE )    strcat(lStr,"ACCELTABLE|");
  215.    if ( pStyle & FS_ICON )          strcat(lStr,"ICON|");
  216.    inprintf(in,"       %s0x%08X\n",lStr,pStyle & WS_UNUSED_BITS);
  217. }
  218.  
  219. ShowMenu(in,pMenu)
  220. {
  221.    if ( -1 == (lCount = GetMenuItemCount(pMenu)) )
  222.       return;
  223.    inprintf(in,"MENU\n");
  224.    for ( lOrd = 0; lOrd < lCount; lOrd++ ) {
  225.       lMenuString = GetMenuString(pMenu,lOrd,MF_BYPOSITION);
  226.       lMenuID = GetMenuItemID(pMenu,lOrd);
  227.       inprintf(in,"%3d ID: %04X  TEXT: \"%s\"  ",lOrd,lMenuID,lMenuString);
  228.       lState = GetMenuState(pMenu,lOrd,MF_BYPOSITION);
  229.       if ( lState & MF_BITMAP )        printf("|BITMAP");
  230.       if ( lState & MF_CHECKED )       printf("|CHECKED");
  231.       if ( lState & MF_DISABLED )      printf("|DISABLED");
  232.       if ( lState & MF_GRAYED )        printf("|GRAYED");
  233.       if ( lState & MF_POPUP )         printf("|POPUP");
  234.       if ( lState & MF_MENUBREAK )     printf("|MENUBREAK");
  235.       if ( lState & MF_MENUBARBREAK )  printf("|MENUBARBREAK");
  236.       if ( lState & MF_HILITE )        printf("|HILITE");
  237.       if ( lState & MF_SEPARATOR )     printf("|SEPARATOR");
  238.       printf("\n");
  239.       if ( -1 == lMenuID ) {
  240.          // This is a Submenu, so show the submenu
  241.          if ( (lSubMenu = GetSubMenu(pMenu,lOrd)) )
  242.             ShowMenu(in+1,lSubMenu);
  243.       }
  244.    }
  245. }
  246.  
  247. ShowClass(in,pHwnd)
  248. {
  249.    #define WC_FRAME        0xFFFF0001
  250.    #define WC_COMBOBOX     0xFFFF0002
  251.    #define WC_BUTTON       0xFFFF0003
  252.    #define WC_MENU         0xFFFF0004
  253.    #define WC_STATIC       0xFFFF0005
  254.    #define WC_ENTRYFIELD   0xFFFF0006
  255.    #define WC_LISTBOX      0xFFFF0007
  256.    #define WC_SCROLLBAR    0xFFFF0008
  257.    #define WC_TITLEBAR     0xFFFF0009
  258.    #define WC_MLE          0xFFFF000A
  259.    #define WC_APPSTAT      0xFFFF0010
  260.    #define WC_KBDSTAT      0xFFFF0011
  261.    #define WC_PECIC        0xFFFF0012
  262.    #define WC_DBE_KKPOPUP  0xFFFF0013
  263.    #define WC_SPINBUTTON   0xFFFF0020
  264.    #define WC_CONTAINER    0xFFFF0025
  265.    #define WC_SLIDER       0xFFFF0026
  266.    #define WC_VALUESET     0xFFFF0027
  267.    #define WC_NOTEBOOK     0xFFFF0028
  268.    lClassName = GetClassName(pHwnd);
  269.    sprintf(lClassName,"\"%s\"",lClassName);
  270.    if ( '#' == lClassName[1] ) {
  271.       switch ( atoi(lClassName + 2) | 0xFFFF0000 ) {
  272.          case WC_FRAME:       lClassName = "WC_FRAME";         break;
  273.          case WC_COMBOBOX:    lClassName = "WC_COMBOBOX";      break;
  274.          case WC_BUTTON:      lClassName = "WC_BUTTON";        break;
  275.          case WC_MENU:        lClassName = "WC_MENU";          break;
  276.          case WC_STATIC:      lClassName = "WC_STATIC";        break;
  277.          case WC_ENTRYFIELD:  lClassName = "WC_ENTRYFIELD";    break;
  278.          case WC_LISTBOX:     lClassName = "WC_LISTBOX";       break;
  279.          case WC_SCROLLBAR:   lClassName = "WC_SCROLLBAR";     break;
  280.          case WC_TITLEBAR:    lClassName = "WC_TITLEBAR";      break;
  281.          case WC_MLE:         lClassName = "WC_MLE";           break;
  282.          case WC_APPSTAT:     lClassName = "WC_APPSTAT";       break;
  283.          case WC_KBDSTAT:     lClassName = "WC_KBDSTAT";       break;
  284.          case WC_PECIC:       lClassName = "WC_PECIC";         break;
  285.          case WC_DBE_KKPOPUP: lClassName = "WC_DBE_KKPOPUP";   break;
  286.          case WC_SPINBUTTON:  lClassName = "WC_SPINBUTTON";    break;
  287.          case WC_CONTAINER:   lClassName = "WC_CONTAINER";     break;
  288.          case WC_SLIDER:      lClassName = "WC_SLIDER";        break;
  289.          case WC_VALUESET:    lClassName = "WC_VALUESET";      break;
  290.          case WC_NOTEBOOK:    lClassName = "WC_NOTEBOOK";      break;
  291.       }
  292.    }
  293.    inprintf(in,"CLASS: %s\n",lClassName);
  294.    //if ( !stricmp(lClassName,"Button") ) ShowButtonClass(in+1,pHwnd);
  295.    //if ( !stricmp(lClassName,"ComboBox") ) ShowComboBoxClass(in+1,pHwnd);
  296.    //if ( !stricmp(lClassName,"ListBox") ) ShowListBoxClass(in+1,pHwnd);
  297. }
  298.  
  299. ShowButtonClass(in,pHwnd)
  300. {
  301.    inprintf(in,"%s, ",SendMessage(pHwnd,BM_GETCHECK,0,0) ? "CHECKED" : "UNCHECKED" );
  302.    printf("%s\n",SendMessage(pHwnd,BM_GETSTATE,0,0) ? "HILITED" : "PLAIN" );
  303. }
  304.  
  305. ShowComboBoxClass(in,pHwnd)
  306. {
  307.    inprintf(in,"Count: %d",SendMessage(pHwnd,CB_GETCOUNT,0,0));
  308.    lCurSel = SendMessage(pHwnd,CB_GETCURSEL,0,0);
  309.    if ( CB_ERR == lCurSel )
  310.       printf(", None selected");
  311.    else {
  312.       printf(", selected: %d",lCurSel);
  313.       lTextLen = SendMessage(pHwnd,CB_GETLBTEXTLEN,lCurSel,0);
  314.       lText[lTextLen+10] = '\0';
  315.       SendMessage(pHwnd,CB_GETLBTEXT,lCurSel,lText);
  316.       lText[lTextLen] = 0;
  317.       printf(", Text: \"%s\"",lText);
  318.    }
  319.    printf("\n");
  320. }
  321.  
  322. ShowListBoxClass(in,pHwnd)
  323. {
  324.    lStyle = GetWindowLong(pHwnd,GWL_STYLE);
  325.    inprintf(in,"Count: %d",SendMessage(pHwnd,LB_GETCOUNT,0,0));
  326.    // determine if this is a multiple selection listbox
  327.    if ( LBS_MULTIPLESEL & lStyle ) {
  328.       // multiple selections
  329.       lCount = SendMessage(pHwnd,LB_GETSELCOUNT,0,0);
  330.       printf(", %d selected",lCount);
  331.    } else {
  332.       lCurSel = SendMessage(pHwnd,LB_GETCURSEL,0,0);
  333.       if ( LB_ERR == lCurSel )
  334.          printf(", None selected");
  335.       else {
  336.          printf(", selected: %d",lCurSel);
  337.          lTextLen = SendMessage(pHwnd,LB_GETTEXTLEN,lCurSel,0);
  338.          lText[lTextLen+10] = '\0';
  339.          SendMessage(pHwnd,LB_GETTEXT,lCurSel,lText);
  340.          lText[lTextLen] = 0;
  341.          printf(", Text: \"%s\"",lText);
  342.       }
  343.    }
  344.    printf("\n");
  345. }
  346.  
  347. /************ Useful functions ********/
  348. KeyPressed(pKey)  // return boolen TRUE if keypressed now, else FALSE
  349. {
  350.    #define ORD_WIN32SETKEYBOARDSTATETABLE   921
  351.    _table[255] = '\0';   // initialize 256-byte key table
  352.    DynamicLink("PMWIN",ORD_WIN32SETKEYBOARDSTATETABLE,BIT32,CDECL,
  353.                HWND_DESKTOP,_table,FALSE);
  354.    return( 0x80 & _table[pKey] );
  355. }
  356.  
  357. inprintf(IndentLevel,FormatString/*,arg,arg,arg*/)
  358. {  // like printf, but indent IndentLevel characers
  359.    for ( lIn = 0; lIn < IndentLevel; lIn++ )
  360.       printf("  ");
  361.    va_start(va_list,FormatString);
  362.    vprintf(FormatString,va_list);
  363.    va_end(va_list);
  364. }
  365.  
  366. GetClassName(pHwnd)
  367. {
  368.    #define ORD_WIN32QUERYCLASSNAME  805
  369.    lString[1000] = '\0';
  370.    lString[DynamicLink("PMWIN",ORD_WIN32QUERYCLASSNAME,BIT32,CDECL,pHwnd,999,lString)] = 0;
  371.    strcpy(lRet,lString);
  372.    return lRet;
  373. }
  374.  
  375. GetWindowText(pHwnd) // NULL if none
  376. {
  377.    lSharedMem = GiveMemoryToWindow(pHwnd);
  378.    #define ORD_WIN32QUERYWINDOWTEXT 841
  379.    if ( lTextLen = PMDynamicLink("PMWIN",ORD_WIN32QUERYWINDOWTEXT,BIT32,CDECL,pHwnd,1000,lSharedMem) ) {
  380.       lString = peek(lSharedMem,lTextLen);
  381.       lString[lTextLen] = '\0';
  382.    } else
  383.       lString = NULL;
  384.    return lString;
  385. }
  386.  
  387. WinQueryWindowULong(pHwnd,pIndex)
  388. {
  389.    #define ORD_WIN32QUERYWINDOWULONG   843
  390.    return PMDynamicLink("PMWIN",ORD_WIN32QUERYWINDOWULONG,BIT32,CDECL,pHwnd,pIndex);
  391. }
  392.  
  393.  
  394. WinQueryWindowUShort(pHwnd,pIndex)
  395. {
  396.    #define ORD_WIN32QUERYWINDOWUSHORT  844
  397.    return 0xFFFF & PMDynamicLink("PMWIN",ORD_WIN32QUERYWINDOWUSHORT,BIT32,CDECL,pHwnd,pIndex);
  398. }
  399.  
  400.