home *** CD-ROM | disk | FTP | other *** search
/ Monster Media 1994 #1 / monster.zip / monster / PROG_C / CENVIW9.ZIP / EXAMINEW.CMM < prev    next >
Text File  |  1994-03-08  |  9KB  |  255 lines

  1. //************************************************************************
  2. //*** ExamineW.cmm - CEnvi utility to examine properties of the active ***
  3. //*** ver.1          window. This information is useful for calls      ***
  4. //***                to other window, dialog, and message functions.   ***
  5. //************************************************************************
  6.  
  7. #define CHECK_INTERVAL  1000  // approx. milliseconds between check for ctrl-shift
  8.  
  9. #include <WinTools.lib>
  10. #include <Window.lib>
  11. #include <MenuCtrl.lib>
  12.  
  13.  
  14. printf("ExamineW - Examine properties of the active window.  At any time\n"
  15.        "           press and hold Ctrl-Shift to bring up this window to\n"
  16.        "           describe great detail about the state of the currently\n"
  17.        "           active window.\n");
  18.  
  19.  
  20. for( ; ; ) {
  21.    // loop forever waiting for Ctrl-Shift
  22.    printf("\n***************************************************************************");
  23.    printf("\nWaiting for Ctrl-Shift...");
  24.    WaitForKeysHeld();
  25.    printf("\r                                                    \r");
  26.  
  27.    DescribeCurrentWindow();
  28.  
  29. }
  30.  
  31. WaitForKeysHeld() // wait for keys to be held
  32. {
  33.    #define VK_SHIFT     0x10
  34.    #define VK_CONTROL   0x11
  35.    // first wait for keys to not all be down before continuing
  36.    while ( KeyPressed(VK_SHIFT)  &&  KeyPressed(VK_CONTROL) ) ;
  37.  
  38.    do {
  39.       suspend( CHECK_INTERVAL );
  40.    } while ( !KeyPressed(VK_SHIFT)  ||  !KeyPressed(VK_CONTROL) );
  41. }
  42.  
  43.  
  44. DescribeCurrentWindow()
  45. {
  46.    // show title and handle for active window
  47.    if ( !(ActiveHwnd = GetActiveWindow()) ) {
  48.       printf("Active window handle unknown.\n");
  49.       return;
  50.    }
  51.    if ( !(ActiveTitle = GetWindowText(ActiveHwnd)) ) ActiveTitle = "<Unknown>";
  52.    printf("Active window \"%s\", handle = %04X\n",ActiveTitle,ActiveHwnd);
  53.  
  54.    // show title and handle for focus window
  55.    if ( !(FocusHwnd = GetFocus()) ) {
  56.       printf("No focus window\n");
  57.    } else {
  58.       printf("Focus window");
  59.       if ( FocusTitle = GetWindowText(FocusHwnd) )
  60.          printf(" \"%s\"",FocusTitle);
  61.       printf(" handle = %04X\n",FocusHwnd);
  62.    }
  63.  
  64.    ShowWindowDetails(ActiveHwnd,0);
  65.    if ( FocusHwnd  &&  FocusHwnd != ActiveHwnd )
  66.       ShowWindowDetails(FocusHwnd,0);
  67. }
  68.  
  69. ShowWindowDetails(hwnd,Level)
  70. {
  71.    printf("%04X",hwnd);
  72.    if ( Title = GetWindowText(hwnd) )
  73.       printf(" \"%s\"", Title);
  74.    printf("\n");
  75.  
  76.    in = Level + 1;
  77.  
  78.    inprintf(in,"ID: %04X\n",GetWindowWord(hwnd,GWW_ID));
  79.  
  80.    GetWindowRect(hwnd,lRect);
  81.    inprintf(in,"Coordinates: (L,T,R,B) %d, %d, %d, %d\n",
  82.             lRect.left,lRect.top,lRect.right,lRect.bottom);
  83.  
  84.    ShowStyle(in,lStyle = GetWindowLong(hwnd,GWL_STYLE));
  85.  
  86.    inprintf(in,"ExtendedStyle: %08X\n",GetWindowLong(hwnd,GWL_EXSTYLE));
  87.  
  88.    ShowClass(in,hwnd);
  89.  
  90.    if ( (lStyle & WS_SYSMENU)  &&  0 != (lMenu = GetSystemMenu(hwnd)) ) {
  91.       inprintf(in,"SYSTEM MENU:\n");
  92.       ShowMenu(in,lMenu);
  93.    }
  94.  
  95.    if ( !(lStyle & WS_CHILD)  &&  0 != (lMenu = GetMenu(hwnd)) )
  96.       ShowMenu(in,lMenu);
  97.  
  98.    // Do this same routine for each child window of this window
  99.    for ( ChildWindow = GetWindow(hwnd,GW_CHILD); ChildWindow;
  100.          ChildWindow = GetWindow(ChildWindow,GW_HWNDNEXT) ) {
  101.       printf("\n");
  102.       inprintf(Level,"  ");
  103.       ShowWindowDetails(ChildWindow,in);
  104.    }
  105. }
  106.  
  107. ShowStyle(in,pStyle)
  108. {
  109.    // show style, and decipher it
  110.    inprintf(in,"Style: %08X\n",pStyle);
  111.    lStr[0] = '\0';
  112.    if ( pStyle & WS_POPUP )         strcat(lStr,"POPUP|");
  113.    if ( pStyle & WS_CHILD )         strcat(lStr,"CHILD|");
  114.    if ( pStyle & WS_MINIMIZE )      strcat(lStr,"MINIMIZE|");
  115.    if ( pStyle & WS_VISIBLE )       strcat(lStr,"VISIBLE|");
  116.    if ( pStyle & WS_DISABLED )      strcat(lStr,"DISABLED|");
  117.    if ( pStyle & WS_CLIPSIBLINGS )  strcat(lStr,"CLIPSIBLINGS|");
  118.    if ( pStyle & WS_CLIPCHILDREN )  strcat(lStr,"CLIPCHILDREN|");
  119.    if ( pStyle & WS_MAXIMIZE )      strcat(lStr,"MAXIMIZE|");
  120.    if ( lStr[0] )
  121.       inprintf(in,"       %s\n",lStr);
  122.    lStr[0] = '\0';
  123.    if ( pStyle & WS_BORDER )        strcat(lStr,"BORDER|");
  124.    if ( pStyle & WS_DLGFRAME )      strcat(lStr,"DLGFRAME|");
  125.    if ( pStyle & WS_VSCROLL )       strcat(lStr,"VSCROLL|");
  126.    if ( pStyle & WS_HSCROLL )       strcat(lStr,"HSCROLL|");
  127.    if ( pStyle & WS_SYSMENU )       strcat(lStr,"SYSMENU|");
  128.    if ( pStyle & WS_THICKFRAME )    strcat(lStr,"THICKFRAME|");
  129.    if ( pStyle & WS_GROUP )         strcat(lStr,"GROUP|");
  130.    if ( pStyle & WS_TABSTOP )       strcat(lStr,"TABSTOP|");
  131.    inprintf(in,"       %s0x%04X\n",lStr,pStyle & 0xFFFF);
  132. }
  133.  
  134. ShowMenu(in,pMenu)
  135. {
  136.    if ( -1 == (lCount = GetMenuItemCount(pMenu)) )
  137.       return;
  138.    inprintf(in,"MENU\n");
  139.    for ( lOrd = 0; lOrd < lCount; lOrd++ ) {
  140.       lMenuString = GetMenuString(pMenu,lOrd,MF_BYPOSITION);
  141.       lMenuID = GetMenuItemID(pMenu,lOrd);
  142.       inprintf(in,"%3d ID: %04X  TEXT: \"%s\"  ",lOrd,lMenuID,lMenuString);
  143.       lState = GetMenuState(pMenu,lOrd,MF_BYPOSITION);
  144.       if ( lState & MF_BITMAP )        printf("|BITMAP");
  145.       if ( lState & MF_CHECKED )       printf("|CHECKED");
  146.       if ( lState & MF_DISABLED )      printf("|DISABLED");
  147.       if ( lState & MF_GRAYED )        printf("|GRAYED");
  148.       if ( lState & MF_POPUP )         printf("|POPUP");
  149.       if ( lState & MF_MENUBREAK )     printf("|MENUBREAK");
  150.       if ( lState & MF_MENUBARBREAK )  printf("|MENUBARBREAK");
  151.       if ( lState & MF_HILITE )        printf("|HILITE");
  152.       if ( lState & MF_SEPARATOR )     printf("|SEPARATOR");
  153.       printf("\n");
  154.       if ( -1 == lMenuID ) {
  155.          // This is a Submenu, so show the submenu
  156.          if ( (lSubMenu = GetSubMenu(pMenu,lOrd)) )
  157.             ShowMenu(in+1,lSubMenu);
  158.       }
  159.    }
  160. }
  161.  
  162. ShowClass(in,pHwnd)
  163. {
  164.    lClassName = GetClassName(pHwnd);
  165.    inprintf(in,"CLASS: \"%s\"\n",lClassName);
  166.    if ( !stricmp(lClassName,"Button") ) ShowButtonClass(in+1,pHwnd);
  167.    if ( !stricmp(lClassName,"ComboBox") ) ShowComboBoxClass(in+1,pHwnd);
  168.    if ( !stricmp(lClassName,"ListBox") ) ShowListBoxClass(in+1,pHwnd);
  169. }
  170.  
  171. ShowButtonClass(in,pHwnd)
  172. {
  173.    inprintf(in,"%s, ",SendMessage(pHwnd,BM_GETCHECK,0,0) ? "CHECKED" : "UNCHECKED" );
  174.    printf("%s\n",SendMessage(pHwnd,BM_GETSTATE,0,0) ? "HILITED" : "PLAIN" );
  175. }
  176.  
  177. ShowComboBoxClass(in,pHwnd)
  178. {
  179.    inprintf(in,"Count: %d",SendMessage(pHwnd,CB_GETCOUNT,0,0));
  180.    lCurSel = SendMessage(pHwnd,CB_GETCURSEL,0,0);
  181.    if ( CB_ERR == lCurSel )
  182.       printf(", None selected");
  183.    else {
  184.       printf(", selected: %d",lCurSel);
  185.       lTextLen = SendMessage(pHwnd,CB_GETLBTEXTLEN,lCurSel,0);
  186.       lText[lTextLen+10] = '\0';
  187.       SendMessage(pHwnd,CB_GETLBTEXT,lCurSel,lText);
  188.       lText[lTextLen] = 0;
  189.       printf(", Text: \"%s\"",lText);
  190.    }
  191.    printf("\n");
  192. }
  193.  
  194. ShowListBoxClass(in,pHwnd)
  195. {
  196.    lStyle = GetWindowLong(pHwnd,GWL_STYLE);
  197.    inprintf(in,"Count: %d",SendMessage(pHwnd,LB_GETCOUNT,0,0));
  198.    // determine if this is a multiple selection listbox
  199.    if ( LBS_MULTIPLESEL & lStyle ) {
  200.       // multiple selections
  201.       lCount = SendMessage(pHwnd,LB_GETSELCOUNT,0,0);
  202.       printf(", %d selected",lCount);
  203.    } else {
  204.       lCurSel = SendMessage(pHwnd,LB_GETCURSEL,0,0);
  205.       if ( LB_ERR == lCurSel )
  206.          printf(", None selected");
  207.       else {
  208.          printf(", selected: %d",lCurSel);
  209.          lTextLen = SendMessage(pHwnd,LB_GETTEXTLEN,lCurSel,0);
  210.          lText[lTextLen+10] = '\0';
  211.          SendMessage(pHwnd,LB_GETTEXT,lCurSel,lText);
  212.          lText[lTextLen] = 0;
  213.          printf(", Text: \"%s\"",lText);
  214.       }
  215.    }
  216.    printf("\n");
  217. }
  218.  
  219. /************ Useful functions ********/
  220. KeyPressed(pKey)  // return boolen TRUE if keypressed now, else FALSE
  221. {
  222.  return( 0x80 & DynamicLink("USER","GETKEYSTATE",SWORD16,PASCAL,pKey) );
  223. }
  224.  
  225. GetFocus()
  226. {
  227.    return DynamicLink("USER","GETFOCUS",UWORD16,PASCAL);
  228. }
  229.  
  230. inprintf(IndentLevel,FormatString/*,arg,arg,arg*/)
  231. {  // like printf, but indent IndentLevel characers
  232.    for ( lIn = 0; lIn < IndentLevel; lIn++ )
  233.       printf("  ");
  234.    va_start(va_list,FormatString);
  235.    vprintf(FormatString,va_list);
  236.    va_end(va_list);
  237. }
  238.  
  239. GetClassName(pHwnd)
  240. {
  241.    lClassName[400] = '\0';
  242.    lClassName[DynamicLink("USER","GETCLASSNAME",SWORD16,PASCAL,pHwnd,lClassName,399)] = 0;
  243.    return lClassName;
  244. }
  245.  
  246. GetWindowText(pHwnd) // NULL if none
  247. {
  248.    lText[0] = lText[500] = '\0';
  249.    if ( (lTextLen = SendMessage(pHwnd,WM_GETTEXT,499,lText)) < 0 )
  250.       return NULL;
  251.    lText[lTextLen] = 0;
  252.    return lText;
  253. }
  254.  
  255.