home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
HomeWare 14
/
HOMEWARE14.bin
/
os2
/
cenv2_19.arj
/
DLGCTRL.LIB
< prev
next >
Wrap
Text File
|
1994-03-08
|
8KB
|
214 lines
// DlgCtrl.lib - DIALOG CONTROL LIBRARY
// ver.1
//
// These are useful utilities for working with the values and settings
// of various windows within a window. These do not necessarily have
// to be dialog boxes, but this will frequently be the case.
//
//
//**** GetSubWindowHandle(): get window within window
// SYNTAX: int GetSubWindowHandle(WindowSpec,int ControlID | string SubWindowText
// [,int SiblingIndex | string ClassName])
// int GetSubWindowHandle(WindowSpec,SubWindowSpec[,int SiblingIndex])
// WHERE: WindowSpec: is a window handle or window title, as in GetWindowHandle() of
// WinTools.lib. If 0 or NULL then use current active window.
// ControlID: Numeric identifier of child window; if 0 then first child
// SubWindowText: Text associated with child window. Many sub windows have
// '&' in text for hotkeys, and so & will be ignored in match, so
// so you can specifiy "help" to match "&Help"
// SiblingIndex: If specified then will return handle of sibling window this
// index from ControlID or SubWindowText. e.g., +1 would get next
// sibling and -1 would get previous sibling; 0 = no change
// ClassName: If specified then will return handle of the next sibling
// that is of class ClassName
// RETURN: Returns handle of window found; 0 if not found
// EXAMPLES: The following methods could be use in the FONT dialog box of
// Paintbrush to return the handle of the "Font Style" combo box
// GetSubWindowHandle("Font","Font Style",1);
// GetSubWindowHandle(0,"Font Style",1); // active window
// GetSubWindowHandle("Font","Font Style","ComboBox");
// GetSubWindowHandle("Font",0x0471);
//
//
//**** GetWindowText(): Get text association with window
// SYNTAX: string GetWindowText(int WindowHandle)
// WHERE: WindowHandle: any window handle, such as returned from GetSubWindowHandle()
// RETURN: string for text, else NULL if error
// NOTE: Use this function to get edit text, listbox text, or combobox text
//
//
//**** SetWindowText(): Set text association with window
// SYNTAX: string SetWindowText(int WindowHandle,string Text)
// WHERE: WindowHandle: any window handle, such as returned from GetSubWindowHandle()
// Text: string value to set in edit field, combox, etc...
// RETURN: False if error, else TRUE
// NOTE: Use this function to set edit text, listbox text, or combobox text
//
//
//**** ButtonClick(): click a button window
// SYNTAX: int ButtonClick(int ButtonWindowHandle)
// WHERE: ButtonWindowHandle: handle for button window as from GetSubWindowHandle()
// RETURN: Returns result of sending BN_CLICKED message
//
//
//**** ButtonGetCheck(): Is button checked?
// SYNTAX: bool ButtonGetCheck(int ButtonWindowHandle)
// WHERE: ButtonWindowHandle: handle for button window as from GetSubWindowHandle()
// RETURN: Return boolean true if button is checked, else false
//
//
//**** ButtonSetCheck(): Set button check state on
// SYNTAX: void ButtonSetCheck(int ButtonWindowHandle,int State)
// WHERE: ButtonWindowHandle: handle for button window as from GetSubWindowHandle()
// State: For regular check buttons, this is TRUE or FALSE for checked or not,
// but three-state buttons would be one of the following
#define BTN_NO_CHECK 0
#define BTN_CHECK 1
#define BTN_GRAYED 2 // for three-state buttons
//
//
//**** ComboBoxList(): Return all of the possible selections in a combobox list
// SYNTAX: string[] ComboBoxList(int ComboBoxHandle[,ItemCount])
// WHERE: ComboBoxHandle: handle for ComboBox as from GetSubWindowHandle()
// ItemCount: Return number of item returned in list
// RETURN: NULL if not items, else return
// MODIFY: Set ItemCount (if supplied) to number of item in returned list
//
//
//**** ComboBoxSelectString(): Select first match for string
// SYNTAX: int ComboBoxSelectString(int ComboBoxHandle,string Text)
// WHERE: ComboBoxHandle: handle for ComboBox as from GetSubWindowHandle()
// Text: string value to set in edit field, combox, etc...
// RETURN: Return index of new selected item, else CB_ERR if no match
//
//
#include <WinTools.lib>
GetSubWindowHandle(pWinSpec,pIdOrText,pIndexOrClass)
{
// get handle of parent window
if ( !(lParentHwnd = pWinSpec ? GetWindowHandle(pWinSpec) : GetActiveWindow()) )
lRetHwnd = 0;
else {
printf("Found pWinSpec\n");
return 0;
// find window matching ID or Text
if ( !pIdOrText ) {
// no id or text, so return first child
lRetHwnd = GetWindow(lParentHwnd,GW_CHILD);
} else if ( 0 == DataDimension(pIdOrText) ) {
// get child window with this ID
lRetHwnd = GetDlgItem(lParentHwnd,pIdOrText);
} else {
lCompareLen = strlen(pIdOrText);
// window is title, and so must look through all children to match
for ( lRetHwnd = GetWindow(lParentHwnd,GW_CHILD); lRetHwnd;
lRetHwnd = GetWindow(lRetHwnd,GW_HWNDNEXT) ) {
if ( (lWindowText = GetWindowTitle(lRetHwnd)) && lWindowText[0] ) {
// remove all '&' characters
lFindAmper = lWindowText;
while ( lFindAmper = strchr(lFindAmper,'&') )
strcpy(lFindAmper,lFindAmper+1);
// compare new found string against our source
if ( !strnicmp(lWindowText,pIdOrText,lCompareLen) )
break;
}
}
}
}
if ( lRetHwnd && 2 < va_arg() ) {
if ( 0 == DataDimension(pIndexOrClass) ) {
// move this sibling direction
if ( (lIndex = pIndexOrClass) < 0 ) {
for ( ; lIndex && lRetHwnd; lIndex++ )
lRetHwnd = GetWindow(lRetHwnd,GW_HWNDPREV);
} else {
for ( ; lIndex && lRetHwnd; lIndex-- )
lRetHwnd = GetWindow(lRetHwnd,GW_HWNDNEXT);
}
} else {
// find first next window that is of class pIndexOrClass
while ( stricmp(pIndexOrClass,GetClassName(lRetHwnd))
&& (lRetHwnd = GetWindow(lRetHwnd,GW_HWNDNEXT)) ) ;
}
}
return lRetHwnd;
}
GetWindowText(pHwnd)
{
lText[0] = lText[500] = '\0';
if ( (lTextLen = SendMessage(pHwnd,WM_GETTEXT,499,lText)) < 0 )
return NULL;
lText[lTextLen] = 0;
return lText;
}
SetWindowText(pHwnd,pText)
{
return ( 0 <= SendMessage(pHwnd,WM_SETTEXT,0,pText) );
}
ButtonClick(pHwnd)
{
lParentHwnd = GetParent(pHwnd);
lCtrlID = GetDlgCtrlID(pHwnd);
return SendMessage(lParentHwnd,WM_COMMAND,lCtrlID,pHwnd,BN_CLICKED);
}
ButtonGetCheck(pHwnd)
{
return SendMessage(pHwnd,BM_GETCHECK,0,0);
}
ButtonSetCheck(pHwnd,pState)
{
SendMessage(pHwnd,BM_SETCHECK,pState,0);
}
ComboBoxList(pHwnd,pItemCount)
{
if ( lCount = SendMessage(pHwnd,CB_GETCOUNT,0,0) ) {
for ( lIdx = 0; lIdx < lCount; lIdx++ ) {
lText[0] = lText[500] = '\0';
lText[SendMessage(pHwnd,CB_GETLBTEXT,lIdx,lText)] = 0;
strcpy(lList[lIdx],lText);
}
}
if ( 1 < va_arg() ) pItemCount = lCount;
return lCount ? lList : NULL;
}
ComboBoxSelectString(pHwnd,pText)
{
return SendMessage(pHwnd,CB_SELECTSTRING,-1,pText);
}
/************ Useful functions ********/
GetDlgItem(pHwnd,pCtrlID)
{
return DynamicLink("USER","GETDLGITEM",UWORD16,PASCAL,pHwnd,pCtrlID);
}
GetDlgCtrlID(pHwnd)
{
return DynamicLink("USER","GETDLGCTRLID",UWORD16,PASCAL,pHwnd);
}
GetClassName(pHwnd)
{
lClassName[400] = '\0';
lClassName[DynamicLink("USER","GETCLASSNAME",SWORD16,PASCAL,pHwnd,lClassName,399)] = 0;
return lClassName;
}
GetParent(pHwnd)
{
return DynamicLink("USER","GETPARENT",UWORD16,PASCAL,pHwnd);
}