home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Interactive Guide / c-cplusplus-interactive-guide.iso / c_ref / csource1 / cenvew / winutil.lib < prev   
Text File  |  1993-12-02  |  5KB  |  136 lines

  1. // WinUtil.lib - Cmm code wrapper for various useful Windows functions.
  2. //               This is by no means an exhaustive collection, but simply
  3. //               examples.  You may #include this file in your CMM source
  4. //               or you may simply copy the routines you like into your
  5. //               code.  The routines in this file are:
  6. // GetSystemMetrics() - Width and height of various display elements
  7. // GetWindowRect() - return structure containing window coordinates
  8. // MoveWindow() - Move a window to specified coordinates on the screen
  9. // GetWindowHandle() - get handle for a window based on it's matching title
  10. // GetWindowText() - Get title of a window
  11.  
  12. #define _WINUTIL_LIB 1
  13.  
  14.  
  15. GetSystemMetrics(Index)
  16.    // return this system metric
  17. {
  18.    #define SM_CXSCREEN         0    // screen width
  19.    #define SM_CYSCREEN         1    // screen height
  20.    #define SM_CXVSCROLL        2
  21.    #define SM_CYHSCROLL        3
  22.    #define SM_CYCAPTION        4
  23.    #define SM_CXBORDER         5
  24.    #define SM_CYBORDER         6
  25.    #define SM_CXDLGFRAME       7
  26.    #define SM_CYDLGFRAME       8
  27.    #define SM_CYVTHUMB         9
  28.    #define SM_CXHTHUMB         10
  29.    #define SM_CXICON           11
  30.    #define SM_CYICON           12
  31.    #define SM_CXCURSOR         13
  32.    #define SM_CYCURSOR         14
  33.    #define SM_CYMENU           15
  34.    #define SM_CXFULLSCREEN     16
  35.    #define SM_CYFULLSCREEN     17
  36.    #define SM_CYKANJIWINDOW    18
  37.    #define SM_MOUSEPRESENT     19
  38.    #define SM_CYVSCROLL        20
  39.    #define SM_CXHSCROLL        21
  40.    #define SM_DEBUG            22
  41.    #define SM_SWAPBUTTON       23
  42.    #define SM_RESERVED1        24
  43.    #define SM_RESERVED2        25
  44.    #define SM_RESERVED3        26
  45.    #define SM_RESERVED4        27
  46.    #define SM_CXMIN            28
  47.    #define SM_CYMIN            29
  48.    #define SM_CXSIZE           30
  49.    #define SM_CYSIZE           31
  50.    #define SM_CXFRAME          32
  51.    #define SM_CYFRAME          33
  52.    #define SM_CXMINTRACK       34
  53.    #define SM_CYMINTRACK       35
  54.    #define SM_CMETRICS         36
  55.    return( DynamicLink("USER","GETSYSTEMMETRICS",SWORD16,PASCAL,Index) );
  56. }
  57.  
  58.  
  59. GetWindowRect(WindowHandle)
  60.    // return window coordinates in a structure with the following members
  61.    //   .left
  62.    //   .top
  63.    //   .right
  64.    //   .bottom
  65. {
  66.    // set up blob to retrieve four integers
  67.    BLObSize(_rect,4 * 2/*integer size*/);
  68.    DynamicLink("USER","GETWINDOWRECT",SWORD16,PASCAL,WindowHandle,_rect);
  69.    _ret.left = BLObGet(_rect,0,SWORD16);
  70.    _ret.top = BLObGet(_rect,2,SWORD16);
  71.    _ret.right = BLObGet(_rect,4,SWORD16);
  72.    _ret.bottom = BLObGet(_rect,6,SWORD16);
  73.    return(_ret);
  74. }
  75.  
  76.  
  77. GetClientRect(WindowHandle)
  78.    // return window client-area coordinates in a structure with the following members
  79.    //   .left
  80.    //   .top
  81.    //   .right
  82.    //   .bottom
  83. {
  84.    // set up blob to retrieve four integers
  85.    BLObSize(_rect,4 * 2/*integer size*/);
  86.    DynamicLink("USER","GETCLIENTRECT",SWORD16,PASCAL,WindowHandle,_rect);
  87.    _ret.left = BLObGet(_rect,0,SWORD16);
  88.    _ret.top = BLObGet(_rect,2,SWORD16);
  89.    _ret.right = BLObGet(_rect,4,SWORD16);
  90.    _ret.bottom = BLObGet(_rect,6,SWORD16);
  91.    return(_ret);
  92. }
  93.  
  94.  
  95. MoveWindow(WindowHandle,x,y,width,height,Repaint)
  96.    // move the window to coordinates x,y on the screen, with size width,height.
  97.    // if Repaint is not-False then will repaint window
  98. {
  99.    DynamicLink("USER","MOVEWINDOW",SWORD16,PASCAL,
  100.                WindowHandle,x,y,width,height,Repaint);
  101. }
  102.  
  103.  
  104. GetWindowText(WindowHandle)
  105.    // return string containing text of this Window handle, or NULL if this window
  106.    // has no text
  107. {
  108.    BLObSize(_buf,200);
  109.    if ( 0 == DynamicLink("USER","GETWINDOWTEXT",SWORD16,PASCAL,
  110.                          WindowHandle,_buf,BLObSize(_buf)-1) ) {
  111.       return(NULL);
  112.    }
  113.    // copy to shorter string and return that
  114.    strcpy(_ret,_buf);
  115.    return(_ret);
  116. }
  117.  
  118.  
  119. GetWindowHandle(Title)
  120.    // Search for a window to match the string: Title or match title for at
  121.    // least the length of the string. Return the handle of the window as an
  122.    // integer, or return 0 if the window was not found.
  123. {
  124.    _len = strlen(Title);
  125.    if ( NULL == (_winList = WindowList()) ) return 0;
  126.    _count = 1 + GetArraySpan(_winList);
  127.    for ( i = 0; i < _count; i++ ) {
  128.       // compare the title for this window, if it has one
  129.       if ( NULL != (_title = GetWindowText(_winList[i]))
  130.         && 0 == strnicmp(Title,_title,_len) )
  131.          return(_winList[i]);
  132.    }
  133.    return(0);
  134. }
  135.  
  136.