home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
OS/2 Shareware BBS: 10 Tools
/
10-Tools.zip
/
cenvi23.zip
/
DLGCTRL.LIB
< prev
next >
Wrap
Text File
|
1995-04-12
|
8KB
|
206 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: ButtonClick(int ButtonWindowHandle)
// WHERE: ButtonWindowHandle: handle for button window as from GetSubWindowHandle()
// RETURN: No return value
//
//
//**** 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
//
//
//**** ListBoxSelection(): Specify text selection for listbox
// SYNTAX: bool ListBoxSelection(int LBHandle,string PartialText)
// WHERE: LBHandle: Handle for a list-box window
// PartialText: Will match this partial text, case-insensitive
// RETURN: False is cannot match selection, else True
//
//
#include <WinTools.lib>
#include <WinMsg.lib>
#include <GiveMem.lib>
GetSubWindowHandle(pWinSpec,pIdOrText,pIndexOrClass)
{
// get handle of parent window
if ( !(lParentHwnd = pWinSpec ? GetWindowHandle(pWinSpec) : GetActiveWindow()) )
lRetHwnd = 0;
else {
// find window matching ID or Text
if ( !pIdOrText ) {
// no id or text, so return first child
lRetHwnd = WinQueryWindow(lParentHwnd,QW_TOP);
} 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 = WinQueryWindow(lParentHwnd,QW_TOP); lRetHwnd;
lRetHwnd = WinQueryWindow(lRetHwnd,QW_NEXT) ) {
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 = WinQueryWindow(lRetHwnd,QW_PREV);
} else {
for ( ; lIndex && lRetHwnd; lIndex-- )
lRetHwnd = WinQueryWindow(lRetHwnd,QW_NEXT);
}
} else {
// find first next window that is of class pIndexOrClass
while ( stricmp(pIndexOrClass,GetClassName(lRetHwnd))
&& (lRetHwnd = WinQueryWindow(lRetHwnd,QW_NEXT)) ) ;
}
}
return lRetHwnd;
}
GetWindowText(pHwnd)
{
return GetWindowTitle(pHwnd);
}
SetWindowText(pHwnd,pText)
{
return SetWindowTitle(pHwnd,pText);
}
ButtonClick(pHwnd)
{
#define BM_CLICK 0x0120
WinSendMsg(pHwnd,BM_CLICK,False,0);
WinSendMsg(pHwnd,BM_CLICK,True,0);
}
ButtonGetCheck(pHwnd)
{
#define BM_QUERYCHECK 0x0124
return WinSendMsg(pHwnd,BM_QUERYCHECK,0,0);
}
ButtonSetCheck(pHwnd,pState)
{
#define BM_SETCHECK 0x0125
WinSendMsg(pHwnd,BM_SETCHECK,pState,0);
}
ListBoxSelection(pHwnd,pText)
{
#define LM_SEARCHSTRING 0x016B
#define LSS_PREFIX 2
lMem = GiveMemoryToWindow(pHwnd);
poke(lMem,pText,1+strlen(pText));
lIdx = WinSendMsg(pHwnd,LM_SEARCHSTRING,LSS_PREFIX,lMem);
if ( lIdx < 0 )
// not found
return 0;
#define LM_SELECTITEM 0x0164
WinSendMsg(pHwnd,LM_SELECTITEM,lIdx,True);
return True;
}
/************ Useful functions ********/
GetDlgItem(pHwnd,pCtrlID)
{
lEnum = WinBeginEnumWindows(pHwnd);
while ( (lChild = WinGetNextWindow(lEnum))
&& pCtrlID != GetDlgCtrlID(lChild) )
;
WinEndEnumWindows(lEnum);
return lChild;
}
GetDlgCtrlID(pHwnd)
{
#define ORD_WIN32QUERYWINDOWUSHORT 844
#define QWS_ID (-1)
return 0xFFFF & PMDynamicLink("PMWIN",ORD_WIN32QUERYWINDOWUSHORT,BIT32,CDECL,
pHwnd,QWS_ID);
}
GetClassName(pHwnd)
{
#define ORD_WIN32QUERYCLASSNAME 805
lString[1000] = '\0';
lString[DynamicLink("PMWIN",ORD_WIN32QUERYCLASSNAME,BIT32,CDECL,pHwnd,999,lString)] = 0;
strcpy(lRet,lString);
return lRet;
}