home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Monster Media 1994 #1
/
monster.zip
/
monster
/
PROG_C
/
CENVIW9.ZIP
/
EXAMINEW.CMM
< prev
next >
Wrap
Text File
|
1994-03-08
|
9KB
|
255 lines
//************************************************************************
//*** ExamineW.cmm - CEnvi utility to examine properties of the active ***
//*** ver.1 window. This information is useful for calls ***
//*** to other window, dialog, and message functions. ***
//************************************************************************
#define CHECK_INTERVAL 1000 // approx. milliseconds between check for ctrl-shift
#include <WinTools.lib>
#include <Window.lib>
#include <MenuCtrl.lib>
printf("ExamineW - Examine properties of the active window. At any time\n"
" press and hold Ctrl-Shift to bring up this window to\n"
" describe great detail about the state of the currently\n"
" active window.\n");
for( ; ; ) {
// loop forever waiting for Ctrl-Shift
printf("\n***************************************************************************");
printf("\nWaiting for Ctrl-Shift...");
WaitForKeysHeld();
printf("\r \r");
DescribeCurrentWindow();
}
WaitForKeysHeld() // wait for keys to be held
{
#define VK_SHIFT 0x10
#define VK_CONTROL 0x11
// first wait for keys to not all be down before continuing
while ( KeyPressed(VK_SHIFT) && KeyPressed(VK_CONTROL) ) ;
do {
suspend( CHECK_INTERVAL );
} while ( !KeyPressed(VK_SHIFT) || !KeyPressed(VK_CONTROL) );
}
DescribeCurrentWindow()
{
// show title and handle for active window
if ( !(ActiveHwnd = GetActiveWindow()) ) {
printf("Active window handle unknown.\n");
return;
}
if ( !(ActiveTitle = GetWindowText(ActiveHwnd)) ) ActiveTitle = "<Unknown>";
printf("Active window \"%s\", handle = %04X\n",ActiveTitle,ActiveHwnd);
// show title and handle for focus window
if ( !(FocusHwnd = GetFocus()) ) {
printf("No focus window\n");
} else {
printf("Focus window");
if ( FocusTitle = GetWindowText(FocusHwnd) )
printf(" \"%s\"",FocusTitle);
printf(" handle = %04X\n",FocusHwnd);
}
ShowWindowDetails(ActiveHwnd,0);
if ( FocusHwnd && FocusHwnd != ActiveHwnd )
ShowWindowDetails(FocusHwnd,0);
}
ShowWindowDetails(hwnd,Level)
{
printf("%04X",hwnd);
if ( Title = GetWindowText(hwnd) )
printf(" \"%s\"", Title);
printf("\n");
in = Level + 1;
inprintf(in,"ID: %04X\n",GetWindowWord(hwnd,GWW_ID));
GetWindowRect(hwnd,lRect);
inprintf(in,"Coordinates: (L,T,R,B) %d, %d, %d, %d\n",
lRect.left,lRect.top,lRect.right,lRect.bottom);
ShowStyle(in,lStyle = GetWindowLong(hwnd,GWL_STYLE));
inprintf(in,"ExtendedStyle: %08X\n",GetWindowLong(hwnd,GWL_EXSTYLE));
ShowClass(in,hwnd);
if ( (lStyle & WS_SYSMENU) && 0 != (lMenu = GetSystemMenu(hwnd)) ) {
inprintf(in,"SYSTEM MENU:\n");
ShowMenu(in,lMenu);
}
if ( !(lStyle & WS_CHILD) && 0 != (lMenu = GetMenu(hwnd)) )
ShowMenu(in,lMenu);
// Do this same routine for each child window of this window
for ( ChildWindow = GetWindow(hwnd,GW_CHILD); ChildWindow;
ChildWindow = GetWindow(ChildWindow,GW_HWNDNEXT) ) {
printf("\n");
inprintf(Level," ");
ShowWindowDetails(ChildWindow,in);
}
}
ShowStyle(in,pStyle)
{
// show style, and decipher it
inprintf(in,"Style: %08X\n",pStyle);
lStr[0] = '\0';
if ( pStyle & WS_POPUP ) strcat(lStr,"POPUP|");
if ( pStyle & WS_CHILD ) strcat(lStr,"CHILD|");
if ( pStyle & WS_MINIMIZE ) strcat(lStr,"MINIMIZE|");
if ( pStyle & WS_VISIBLE ) strcat(lStr,"VISIBLE|");
if ( pStyle & WS_DISABLED ) strcat(lStr,"DISABLED|");
if ( pStyle & WS_CLIPSIBLINGS ) strcat(lStr,"CLIPSIBLINGS|");
if ( pStyle & WS_CLIPCHILDREN ) strcat(lStr,"CLIPCHILDREN|");
if ( pStyle & WS_MAXIMIZE ) strcat(lStr,"MAXIMIZE|");
if ( lStr[0] )
inprintf(in," %s\n",lStr);
lStr[0] = '\0';
if ( pStyle & WS_BORDER ) strcat(lStr,"BORDER|");
if ( pStyle & WS_DLGFRAME ) strcat(lStr,"DLGFRAME|");
if ( pStyle & WS_VSCROLL ) strcat(lStr,"VSCROLL|");
if ( pStyle & WS_HSCROLL ) strcat(lStr,"HSCROLL|");
if ( pStyle & WS_SYSMENU ) strcat(lStr,"SYSMENU|");
if ( pStyle & WS_THICKFRAME ) strcat(lStr,"THICKFRAME|");
if ( pStyle & WS_GROUP ) strcat(lStr,"GROUP|");
if ( pStyle & WS_TABSTOP ) strcat(lStr,"TABSTOP|");
inprintf(in," %s0x%04X\n",lStr,pStyle & 0xFFFF);
}
ShowMenu(in,pMenu)
{
if ( -1 == (lCount = GetMenuItemCount(pMenu)) )
return;
inprintf(in,"MENU\n");
for ( lOrd = 0; lOrd < lCount; lOrd++ ) {
lMenuString = GetMenuString(pMenu,lOrd,MF_BYPOSITION);
lMenuID = GetMenuItemID(pMenu,lOrd);
inprintf(in,"%3d ID: %04X TEXT: \"%s\" ",lOrd,lMenuID,lMenuString);
lState = GetMenuState(pMenu,lOrd,MF_BYPOSITION);
if ( lState & MF_BITMAP ) printf("|BITMAP");
if ( lState & MF_CHECKED ) printf("|CHECKED");
if ( lState & MF_DISABLED ) printf("|DISABLED");
if ( lState & MF_GRAYED ) printf("|GRAYED");
if ( lState & MF_POPUP ) printf("|POPUP");
if ( lState & MF_MENUBREAK ) printf("|MENUBREAK");
if ( lState & MF_MENUBARBREAK ) printf("|MENUBARBREAK");
if ( lState & MF_HILITE ) printf("|HILITE");
if ( lState & MF_SEPARATOR ) printf("|SEPARATOR");
printf("\n");
if ( -1 == lMenuID ) {
// This is a Submenu, so show the submenu
if ( (lSubMenu = GetSubMenu(pMenu,lOrd)) )
ShowMenu(in+1,lSubMenu);
}
}
}
ShowClass(in,pHwnd)
{
lClassName = GetClassName(pHwnd);
inprintf(in,"CLASS: \"%s\"\n",lClassName);
if ( !stricmp(lClassName,"Button") ) ShowButtonClass(in+1,pHwnd);
if ( !stricmp(lClassName,"ComboBox") ) ShowComboBoxClass(in+1,pHwnd);
if ( !stricmp(lClassName,"ListBox") ) ShowListBoxClass(in+1,pHwnd);
}
ShowButtonClass(in,pHwnd)
{
inprintf(in,"%s, ",SendMessage(pHwnd,BM_GETCHECK,0,0) ? "CHECKED" : "UNCHECKED" );
printf("%s\n",SendMessage(pHwnd,BM_GETSTATE,0,0) ? "HILITED" : "PLAIN" );
}
ShowComboBoxClass(in,pHwnd)
{
inprintf(in,"Count: %d",SendMessage(pHwnd,CB_GETCOUNT,0,0));
lCurSel = SendMessage(pHwnd,CB_GETCURSEL,0,0);
if ( CB_ERR == lCurSel )
printf(", None selected");
else {
printf(", selected: %d",lCurSel);
lTextLen = SendMessage(pHwnd,CB_GETLBTEXTLEN,lCurSel,0);
lText[lTextLen+10] = '\0';
SendMessage(pHwnd,CB_GETLBTEXT,lCurSel,lText);
lText[lTextLen] = 0;
printf(", Text: \"%s\"",lText);
}
printf("\n");
}
ShowListBoxClass(in,pHwnd)
{
lStyle = GetWindowLong(pHwnd,GWL_STYLE);
inprintf(in,"Count: %d",SendMessage(pHwnd,LB_GETCOUNT,0,0));
// determine if this is a multiple selection listbox
if ( LBS_MULTIPLESEL & lStyle ) {
// multiple selections
lCount = SendMessage(pHwnd,LB_GETSELCOUNT,0,0);
printf(", %d selected",lCount);
} else {
lCurSel = SendMessage(pHwnd,LB_GETCURSEL,0,0);
if ( LB_ERR == lCurSel )
printf(", None selected");
else {
printf(", selected: %d",lCurSel);
lTextLen = SendMessage(pHwnd,LB_GETTEXTLEN,lCurSel,0);
lText[lTextLen+10] = '\0';
SendMessage(pHwnd,LB_GETTEXT,lCurSel,lText);
lText[lTextLen] = 0;
printf(", Text: \"%s\"",lText);
}
}
printf("\n");
}
/************ Useful functions ********/
KeyPressed(pKey) // return boolen TRUE if keypressed now, else FALSE
{
return( 0x80 & DynamicLink("USER","GETKEYSTATE",SWORD16,PASCAL,pKey) );
}
GetFocus()
{
return DynamicLink("USER","GETFOCUS",UWORD16,PASCAL);
}
inprintf(IndentLevel,FormatString/*,arg,arg,arg*/)
{ // like printf, but indent IndentLevel characers
for ( lIn = 0; lIn < IndentLevel; lIn++ )
printf(" ");
va_start(va_list,FormatString);
vprintf(FormatString,va_list);
va_end(va_list);
}
GetClassName(pHwnd)
{
lClassName[400] = '\0';
lClassName[DynamicLink("USER","GETCLASSNAME",SWORD16,PASCAL,pHwnd,lClassName,399)] = 0;
return lClassName;
}
GetWindowText(pHwnd) // NULL if none
{
lText[0] = lText[500] = '\0';
if ( (lTextLen = SendMessage(pHwnd,WM_GETTEXT,499,lText)) < 0 )
return NULL;
lText[lTextLen] = 0;
return lText;
}