home *** CD-ROM | disk | FTP | other *** search
/ The Pier Shareware 6 / The_Pier_Shareware_Number_6_(The_Pier_Exchange)_(1995).iso / 035 / cenvi29.zip / DLGCTRL.LIB < prev    next >
Text File  |  1994-03-08  |  8KB  |  214 lines

  1. // DlgCtrl.lib - DIALOG CONTROL LIBRARY
  2. // ver.1
  3. //
  4. // These are useful utilities for working with the values and settings
  5. // of various windows within a window.  These do not necessarily have
  6. // to be dialog boxes, but this will frequently be the case.
  7. //
  8. //
  9. //**** GetSubWindowHandle(): get window within window
  10. // SYNTAX: int GetSubWindowHandle(WindowSpec,int ControlID | string SubWindowText
  11. //                                [,int SiblingIndex | string ClassName])
  12. //         int GetSubWindowHandle(WindowSpec,SubWindowSpec[,int SiblingIndex])
  13. // WHERE: WindowSpec: is a window handle or window title, as in GetWindowHandle() of
  14. //                    WinTools.lib. If 0 or NULL then use current active window.
  15. //        ControlID: Numeric identifier of child window; if 0 then first child
  16. //        SubWindowText: Text associated with child window.  Many sub windows have
  17. //                       '&' in text for hotkeys, and so & will be ignored in match, so
  18. //                       so you can specifiy "help" to match "&Help"
  19. //        SiblingIndex: If specified then will return handle of sibling window this
  20. //                      index from ControlID or SubWindowText. e.g., +1 would get next
  21. //                      sibling and -1 would get previous sibling; 0 = no change
  22. //        ClassName: If specified then will return handle of the next sibling
  23. //                   that is of class ClassName
  24. // RETURN: Returns handle of window found; 0 if not found
  25. // EXAMPLES: The following methods could be use in the FONT dialog box of
  26. //           Paintbrush to return the handle of the "Font Style" combo box
  27. //              GetSubWindowHandle("Font","Font Style",1);
  28. //              GetSubWindowHandle(0,"Font Style",1); // active window
  29. //              GetSubWindowHandle("Font","Font Style","ComboBox");
  30. //              GetSubWindowHandle("Font",0x0471);
  31. //
  32. //
  33. //**** GetWindowText(): Get text association with window
  34. // SYNTAX: string GetWindowText(int WindowHandle)
  35. // WHERE: WindowHandle: any window handle, such as returned from GetSubWindowHandle()
  36. // RETURN: string for text, else NULL if error
  37. // NOTE: Use this function to get edit text, listbox text, or combobox text
  38. //
  39. //
  40. //**** SetWindowText(): Set text association with window
  41. // SYNTAX: string SetWindowText(int WindowHandle,string Text)
  42. // WHERE: WindowHandle: any window handle, such as returned from GetSubWindowHandle()
  43. //        Text: string value to set in edit field, combox, etc...
  44. // RETURN: False if error, else TRUE
  45. // NOTE: Use this function to set edit text, listbox text, or combobox text
  46. //
  47. //
  48. //**** ButtonClick(): click a button window
  49. // SYNTAX: int ButtonClick(int ButtonWindowHandle)
  50. // WHERE: ButtonWindowHandle: handle for button window as from GetSubWindowHandle()
  51. // RETURN: Returns result of sending BN_CLICKED message
  52. //
  53. //
  54. //**** ButtonGetCheck(): Is button checked?
  55. // SYNTAX: bool ButtonGetCheck(int ButtonWindowHandle)
  56. // WHERE: ButtonWindowHandle: handle for button window as from GetSubWindowHandle()
  57. // RETURN: Return boolean true if button is checked, else false
  58. //
  59. //
  60. //**** ButtonSetCheck(): Set button check state on
  61. // SYNTAX: void ButtonSetCheck(int ButtonWindowHandle,int State)
  62. // WHERE: ButtonWindowHandle: handle for button window as from GetSubWindowHandle()
  63. //        State: For regular check buttons, this is TRUE or FALSE for checked or not,
  64. //               but three-state buttons would be one of the following
  65.             #define BTN_NO_CHECK   0
  66.             #define BTN_CHECK      1
  67.             #define BTN_GRAYED     2   // for three-state buttons
  68. //
  69. //
  70. //**** ComboBoxList(): Return all of the possible selections in a combobox list
  71. // SYNTAX: string[] ComboBoxList(int ComboBoxHandle[,ItemCount])
  72. // WHERE: ComboBoxHandle: handle for ComboBox as from GetSubWindowHandle()
  73. //        ItemCount: Return number of item returned in list
  74. // RETURN: NULL if not items, else return
  75. // MODIFY: Set ItemCount (if supplied) to number of item in returned list
  76. //
  77. //
  78. //**** ComboBoxSelectString(): Select first match for string
  79. // SYNTAX: int ComboBoxSelectString(int ComboBoxHandle,string Text)
  80. // WHERE: ComboBoxHandle: handle for ComboBox as from GetSubWindowHandle()
  81. //        Text: string value to set in edit field, combox, etc...
  82. // RETURN: Return index of new selected item, else CB_ERR if no match
  83. //
  84. //
  85.  
  86. #include <WinTools.lib>
  87.  
  88. GetSubWindowHandle(pWinSpec,pIdOrText,pIndexOrClass)
  89. {
  90.    // get handle of parent window
  91.    if ( !(lParentHwnd = pWinSpec ? GetWindowHandle(pWinSpec) : GetActiveWindow()) )
  92.       lRetHwnd = 0;
  93.    else {
  94. printf("Found pWinSpec\n");
  95. return 0;
  96.       // find window matching ID or Text
  97.       if ( !pIdOrText ) {
  98.          // no id or text, so return first child
  99.          lRetHwnd = GetWindow(lParentHwnd,GW_CHILD);
  100.       } else if ( 0 == DataDimension(pIdOrText) ) {
  101.          // get child window with this ID
  102.          lRetHwnd = GetDlgItem(lParentHwnd,pIdOrText);
  103.       } else {
  104.          lCompareLen = strlen(pIdOrText);
  105.          // window is title, and so must look through all children to match
  106.          for ( lRetHwnd = GetWindow(lParentHwnd,GW_CHILD); lRetHwnd;
  107.                lRetHwnd = GetWindow(lRetHwnd,GW_HWNDNEXT) ) {
  108.             if ( (lWindowText = GetWindowTitle(lRetHwnd)) && lWindowText[0] ) {
  109.                // remove all '&' characters
  110.                lFindAmper = lWindowText;
  111.                while ( lFindAmper = strchr(lFindAmper,'&') )
  112.                   strcpy(lFindAmper,lFindAmper+1);
  113.                // compare new found string against our source
  114.                if ( !strnicmp(lWindowText,pIdOrText,lCompareLen) )
  115.                   break;
  116.             }
  117.          }
  118.       }
  119.    }
  120.  
  121.    if ( lRetHwnd  &&  2 < va_arg() ) {
  122.       if ( 0 == DataDimension(pIndexOrClass) ) {
  123.          // move this sibling direction
  124.          if ( (lIndex = pIndexOrClass) < 0 ) {
  125.             for ( ; lIndex && lRetHwnd; lIndex++ )
  126.                lRetHwnd = GetWindow(lRetHwnd,GW_HWNDPREV);
  127.          } else {
  128.             for ( ; lIndex && lRetHwnd; lIndex-- )
  129.                lRetHwnd = GetWindow(lRetHwnd,GW_HWNDNEXT);
  130.          }
  131.       } else {
  132.          // find first next window that is of class pIndexOrClass
  133.          while ( stricmp(pIndexOrClass,GetClassName(lRetHwnd))
  134.               && (lRetHwnd = GetWindow(lRetHwnd,GW_HWNDNEXT)) ) ;
  135.       }
  136.    }
  137.  
  138.    return lRetHwnd;
  139. }
  140.  
  141. GetWindowText(pHwnd)
  142. {
  143.    lText[0] = lText[500] = '\0';
  144.    if ( (lTextLen = SendMessage(pHwnd,WM_GETTEXT,499,lText)) < 0 )
  145.       return NULL;
  146.    lText[lTextLen] = 0;
  147.    return lText;
  148. }
  149.  
  150. SetWindowText(pHwnd,pText)
  151. {
  152.    return ( 0 <= SendMessage(pHwnd,WM_SETTEXT,0,pText) );
  153. }
  154.  
  155. ButtonClick(pHwnd)
  156. {
  157.    lParentHwnd = GetParent(pHwnd);
  158.    lCtrlID = GetDlgCtrlID(pHwnd);
  159.    return SendMessage(lParentHwnd,WM_COMMAND,lCtrlID,pHwnd,BN_CLICKED);
  160. }
  161.  
  162. ButtonGetCheck(pHwnd)
  163. {
  164.    return SendMessage(pHwnd,BM_GETCHECK,0,0);
  165. }
  166.  
  167. ButtonSetCheck(pHwnd,pState)
  168. {
  169.    SendMessage(pHwnd,BM_SETCHECK,pState,0);
  170. }
  171.  
  172. ComboBoxList(pHwnd,pItemCount)
  173. {
  174.    if ( lCount = SendMessage(pHwnd,CB_GETCOUNT,0,0) ) {
  175.       for ( lIdx = 0; lIdx < lCount; lIdx++ ) {
  176.          lText[0] = lText[500] = '\0';
  177.          lText[SendMessage(pHwnd,CB_GETLBTEXT,lIdx,lText)] = 0;
  178.          strcpy(lList[lIdx],lText);
  179.       }
  180.    }
  181.    if ( 1 < va_arg() ) pItemCount = lCount;
  182.    return lCount ? lList : NULL;
  183. }
  184.  
  185. ComboBoxSelectString(pHwnd,pText)
  186. {
  187.    return SendMessage(pHwnd,CB_SELECTSTRING,-1,pText);
  188. }
  189.  
  190. /************ Useful functions ********/
  191.  
  192. GetDlgItem(pHwnd,pCtrlID)
  193. {
  194.    return DynamicLink("USER","GETDLGITEM",UWORD16,PASCAL,pHwnd,pCtrlID);
  195. }
  196.  
  197. GetDlgCtrlID(pHwnd)
  198. {
  199.    return DynamicLink("USER","GETDLGCTRLID",UWORD16,PASCAL,pHwnd);
  200. }
  201.  
  202. GetClassName(pHwnd)
  203. {
  204.    lClassName[400] = '\0';
  205.    lClassName[DynamicLink("USER","GETCLASSNAME",SWORD16,PASCAL,pHwnd,lClassName,399)] = 0;
  206.    return lClassName;
  207. }
  208.  
  209. GetParent(pHwnd)
  210. {
  211.    return DynamicLink("USER","GETPARENT",UWORD16,PASCAL,pHwnd);
  212. }
  213.  
  214.