home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 10 / 10.iso / l / l430 / 1.ddi / CHAP6.ZIP / XCSTODS.C < prev   
Encoding:
C/C++ Source or Header  |  1992-06-10  |  2.2 KB  |  84 lines

  1. /*
  2.     XCSTODS.C -- Uses a better way than XCStoDS to get USER's DS
  3.  
  4.     From Chapter 6 of "Undocumented Windows" (Addison-Wesley 1992)
  5.     by Andrew Schulman, Dave Maxey and Matt Pietrek
  6.  
  7.     Build using: WINIOBC XCSTODS (for Borland C++ v3.00)
  8.                  WINIOMS XCSTODS (for Microsoft C/SDK)
  9. */
  10.  
  11. #include <windows.h> 
  12. #include <dos.h>
  13. #include <string.h>
  14. #include "winio.h" 
  15.  
  16. #ifndef __BORLANDC__
  17. #define MK_FP(a,b)  ((void far *)(((unsigned long)(a) << 16) | (b)))
  18. #endif
  19.  
  20. /* Undocumented structures */
  21. #include "userobj.h"
  22.  
  23. /* undocumented function that could be used in 3.0 */ 
  24. // extern WORD FAR PASCAL XCStoDS(void);
  25.  
  26. WORD selUserDS;
  27. char strIndent[30] = {0};
  28. char strText[128];
  29.  
  30. void printtree(WORD wndofs)
  31.     {
  32.     // We only need WND fields which coincide in 3.0 and 3.1
  33.     WND_3_0 far *hwnd;
  34.  
  35.     for (;;)
  36.         {
  37.         hwnd = MK_FP(selUserDS, wndofs);
  38.         GetWindowText((HWND) wndofs, (LPSTR) &strText, 128);
  39.         printf("%sWindow %04X is %s\n", strIndent, wndofs, strText);
  40.         if (hwnd->hwndChild != NULL)
  41.             {
  42.             int i = strlen(strIndent);
  43.             strcat(strIndent, "  ");
  44.             printtree(hwnd->hwndChild);
  45.             strIndent[i] = 0;
  46.             }
  47.         if ((wndofs = hwnd->hwndNext) == NULL)
  48.             break;
  49.         }
  50.     }
  51.     
  52.  
  53. int main()
  54.     {
  55.     winio_about("XCSTODS"
  56.         "\nShows how access to USER's default DS might be used"
  57.         "\n\nFrom Chapter 6 of"
  58.         "\n\"Undocumented Windows\" (Addison-Wesley, 1992)"
  59.         "\nby Andrew Schulman, David Maxey and Matt Pietrek"
  60.         );
  61.  
  62.     // The following line will only work in 3.0
  63. //  selUserDS = XCStoDS();
  64.     // whereas the following line will work in 3.0 and 3.1
  65.     selUserDS = GetWindowWord(GetDesktopWindow(), GWW_HINSTANCE);
  66.     
  67.     // Now we need to adjust the selector privilege level for 3.0
  68.     selUserDS &= 0xfffc; 
  69.     selUserDS |= 1; 
  70.     
  71.     // Build the list, then paint it
  72.     winio_setpaint(winio_current(), FALSE);
  73.     
  74.     printtree(GetDesktopWindow());
  75.     
  76.     puts("\n\nEnd **********");
  77.     
  78.     winio_setpaint(winio_current(), TRUE);
  79.     
  80.     winio_home(winio_current());
  81.     
  82.     return 0;
  83.     }
  84.