home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / cenvi23.zip / DLGCTRL.LIB < prev    next >
Text File  |  1995-04-12  |  8KB  |  206 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: ButtonClick(int ButtonWindowHandle)
  50. // WHERE: ButtonWindowHandle: handle for button window as from GetSubWindowHandle()
  51. // RETURN: No return value
  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. //**** ListBoxSelection(): Specify text selection for listbox
  71. // SYNTAX: bool ListBoxSelection(int LBHandle,string PartialText)
  72. // WHERE: LBHandle: Handle for a list-box window
  73. //        PartialText: Will match this partial text, case-insensitive
  74. // RETURN: False is cannot match selection, else True
  75. //
  76. //
  77.  
  78. #include <WinTools.lib>
  79. #include <WinMsg.lib>
  80. #include <GiveMem.lib>
  81.  
  82. GetSubWindowHandle(pWinSpec,pIdOrText,pIndexOrClass)
  83. {
  84.    // get handle of parent window
  85.    if ( !(lParentHwnd = pWinSpec ? GetWindowHandle(pWinSpec) : GetActiveWindow()) )
  86.       lRetHwnd = 0;
  87.    else {
  88.       // find window matching ID or Text
  89.       if ( !pIdOrText ) {
  90.          // no id or text, so return first child
  91.          lRetHwnd = WinQueryWindow(lParentHwnd,QW_TOP);
  92.       } else if ( 0 == DataDimension(pIdOrText) ) {
  93.          // get child window with this ID
  94.          lRetHwnd = GetDlgItem(lParentHwnd,pIdOrText);
  95.       } else {
  96.          lCompareLen = strlen(pIdOrText);
  97.          // window is title, and so must look through all children to match
  98.          for ( lRetHwnd = WinQueryWindow(lParentHwnd,QW_TOP); lRetHwnd;
  99.                lRetHwnd = WinQueryWindow(lRetHwnd,QW_NEXT) ) {
  100.             if ( (lWindowText = GetWindowTitle(lRetHwnd)) && lWindowText[0] ) {
  101.                // remove all '&' characters
  102.                lFindAmper = lWindowText;
  103.                while ( lFindAmper = strchr(lFindAmper,'&') )
  104.                   strcpy(lFindAmper,lFindAmper+1);
  105.                // compare new found string against our source
  106.                if ( !strnicmp(lWindowText,pIdOrText,lCompareLen) )
  107.                   break;
  108.             }
  109.          }
  110.       }
  111.    }
  112.  
  113.    if ( lRetHwnd  &&  2 < va_arg() ) {
  114.       if ( 0 == DataDimension(pIndexOrClass) ) {
  115.          // move this sibling direction
  116.          if ( (lIndex = pIndexOrClass) < 0 ) {
  117.             for ( ; lIndex && lRetHwnd; lIndex++ )
  118.                lRetHwnd = WinQueryWindow(lRetHwnd,QW_PREV);
  119.          } else {
  120.             for ( ; lIndex && lRetHwnd; lIndex-- )
  121.                lRetHwnd = WinQueryWindow(lRetHwnd,QW_NEXT);
  122.          }
  123.       } else {
  124.          // find first next window that is of class pIndexOrClass
  125.          while ( stricmp(pIndexOrClass,GetClassName(lRetHwnd))
  126.               && (lRetHwnd = WinQueryWindow(lRetHwnd,QW_NEXT)) ) ;
  127.       }
  128.    }
  129.  
  130.    return lRetHwnd;
  131. }
  132.  
  133. GetWindowText(pHwnd)
  134. {
  135.    return GetWindowTitle(pHwnd);
  136. }
  137.  
  138. SetWindowText(pHwnd,pText)
  139. {
  140.    return SetWindowTitle(pHwnd,pText);
  141. }
  142.  
  143. ButtonClick(pHwnd)
  144. {
  145.    #define BM_CLICK  0x0120
  146.    WinSendMsg(pHwnd,BM_CLICK,False,0);
  147.    WinSendMsg(pHwnd,BM_CLICK,True,0);
  148. }
  149.  
  150. ButtonGetCheck(pHwnd)
  151. {
  152.    #define BM_QUERYCHECK   0x0124
  153.    return WinSendMsg(pHwnd,BM_QUERYCHECK,0,0);
  154. }
  155.  
  156. ButtonSetCheck(pHwnd,pState)
  157. {
  158.    #define BM_SETCHECK  0x0125
  159.    WinSendMsg(pHwnd,BM_SETCHECK,pState,0);
  160. }
  161.  
  162. ListBoxSelection(pHwnd,pText)
  163. {
  164.    #define LM_SEARCHSTRING 0x016B
  165.    #define LSS_PREFIX      2
  166.    lMem = GiveMemoryToWindow(pHwnd);
  167.    poke(lMem,pText,1+strlen(pText));
  168.    lIdx = WinSendMsg(pHwnd,LM_SEARCHSTRING,LSS_PREFIX,lMem);
  169.    if ( lIdx < 0 )
  170.       // not found
  171.       return 0;
  172.    #define LM_SELECTITEM   0x0164
  173.    WinSendMsg(pHwnd,LM_SELECTITEM,lIdx,True);
  174.    return True;
  175. }
  176.  
  177. /************ Useful functions ********/
  178.  
  179. GetDlgItem(pHwnd,pCtrlID)
  180. {
  181.    lEnum = WinBeginEnumWindows(pHwnd);
  182.    while ( (lChild = WinGetNextWindow(lEnum))
  183.         && pCtrlID != GetDlgCtrlID(lChild) )
  184.       ;
  185.    WinEndEnumWindows(lEnum);
  186.    return lChild;
  187. }
  188.  
  189. GetDlgCtrlID(pHwnd)
  190. {
  191.    #define ORD_WIN32QUERYWINDOWUSHORT  844
  192.    #define QWS_ID (-1)
  193.    return 0xFFFF & PMDynamicLink("PMWIN",ORD_WIN32QUERYWINDOWUSHORT,BIT32,CDECL,
  194.                                  pHwnd,QWS_ID);
  195. }
  196.  
  197. GetClassName(pHwnd)
  198. {
  199.    #define ORD_WIN32QUERYCLASSNAME  805
  200.    lString[1000] = '\0';
  201.    lString[DynamicLink("PMWIN",ORD_WIN32QUERYCLASSNAME,BIT32,CDECL,pHwnd,999,lString)] = 0;
  202.    strcpy(lRet,lString);
  203.    return lRet;
  204. }
  205.  
  206.