//	WindowMenu.c////	This file defines a "Window" menu#include "WindowMenu.h"// global variablesMenuHandle wmMenuHdl = 0;// build a menu from the Windows folder,// and initialize the OSA component needed to execute Windowsvoid BuildWindowMenu( const short menuID ){	// delete previous menu, if any	if (wmMenuHdl) {		DisposeMenu(wmMenuHdl);	}		// create a new menu	wmMenuHdl = NewMenu( menuID, "\pWindows" );		// build the list of Windows	UpdateWindowMenu();		// insert into the menu bar	InsertMenu( wmMenuHdl, 0 );}// add the windows, as needed, to the window menuvoid UpdateWindowMenu(){	short i;	WindowPeek windptr;	Str255 str;		// delete previous items	short cnt = CountMItems( wmMenuHdl );	for (i=1; i<=cnt; i++) {		DelMenuItem( wmMenuHdl, 1 );	}	// add new items	for (windptr = (WindowPeek)FrontWindow(); windptr; windptr = windptr->nextWindow ) {		GetWTitle( (WindowPtr)windptr, str );		AppendMenu( wmMenuHdl, str );		}}// enable the Windows menuvoid EnableWindowMenu(){	// we'd like to just say this:	//		EnableItem( wmMenuHdl, 0 );	// ...but some apps (like MacZoop) muck with the enable flags,	// and then this doesn't work.  So we'll do it the hard way:	short i;	short cnt = CountMItems( wmMenuHdl );	for (i=0; i<=cnt; i++) {		EnableItem( wmMenuHdl, i );	}}// disable the Windows menuvoid DisableWindowMenu(){	DisableItem( wmMenuHdl, 0 );}// handle a menu selectionvoid HandleWindowMenuSelection( const short num ){	// if the window menu is freshly built in layer order,	// then we can just find and select the "num"th window	short i;	WindowPeek windptr = (WindowPeek)FrontWindow();	for (i=1; i<num; i++) {		windptr = (windptr ? windptr->nextWindow : 0);	}		// now we should have a pointer to the proper window	if (windptr)		SelectWindow( (WindowPtr)windptr );}