	if(::strlen(++ptr)>12)return FALSE;


template <class T>
void QuickSort<T>::sortItems(PureVector<T> &vectorItems,SortOptions::SortOrder sortOrder)
{
	if(!vectorItems.size())return;
//	mlpItemList=(T*)vectorItems;
	if(SortOptions::Ascending==sortOrder)quickSort(0,vectorItems.size()-1);
	else quickSortDescending(0,vectorItems.size()-1);
}



WORD Process::createProcess(String moduleNameString,String cmdLineString,CreationFlags creationFlags,WORD showWindow)
{
	PathFind pathFind;
  Profile profile;
	String pureFileName;
	String pathFileNameString;
	String commandLineString;
	String startupDirString(".");
	String blankString(" ");

  if(isOkay())terminateProcess();
	if(moduleNameString.isNull())return FALSE;
  pureFileName=moduleNameString;
//  profile.makeFileName(pureFileName);
	if(pathFind.findFile(pureFileName,pathFileNameString))
	{
    moduleNameString=pathFileNameString;
		startupDirString=pathFileNameString;
    commandLineString=pathFileNameString;
		profile.makeDirectoryName(startupDirString);
		commandLineString+=blankString;
	}
	else
	{
		commandLineString=moduleNameString;
		commandLineString+=blankString;
	}
	commandLineString+=cmdLineString;
	if(SW_SHOWNORMAL!=showWindow){mStartupInfo.dwFlags=STARTF_USESHOWWINDOW;mStartupInfo.wShowWindow=showWindow;}
	mIsOkay=(WORD)::CreateProcess(moduleNameString,commandLineString,0,0,0,(DWORD)creationFlags,0,startupDirString,&mStartupInfo,(PROCESS_INFORMATION*)((PureProcess*)this));
	return mIsOkay;
}


WORD Process::createProcess(String moduleNameString,String cmdLineString,const CreationFlags &creationFlags,WORD showWindow)
{
	PathFind pathFind;
	Profile profile;
	String pureFileName;
	String pathFileNameString;
	String commandLineString;
	String startupDirString(".");
	String blankString(" ");

	if(isOkay())terminateProcess();
	if(moduleNameString.isNull())return FALSE;
	pureFileName=moduleNameString;
	if(pathFind.findFile(pureFileName,pathFileNameString))
	{
		moduleNameString=pathFileNameString;
//		startupDirString=pathFileNameString;
    commandLineString=pathFileNameString;
//		profile.makeDirectoryName(startupDirString);
		commandLineString+=blankString;
	}
	else
	{
		commandLineString=moduleNameString;
		commandLineString+=blankString;
	}
	commandLineString+=cmdLineString;
	if(SW_SHOWNORMAL!=showWindow){mStartupInfo.dwFlags=STARTF_USESHOWWINDOW;mStartupInfo.wShowWindow=showWindow;}
//	mIsOkay=(WORD)::CreateProcess(moduleNameString,commandLineString,0,0,0,(DWORD)creationFlags,0,startupDirString,&mStartupInfo,(PROCESS_INFORMATION*)((PureProcess*)this));
	mIsOkay=(WORD)::CreateProcess(moduleNameString,commandLineString,0,0,0,(DWORD)creationFlags,0,0,&mStartupInfo,(PROCESS_INFORMATION*)((PureProcess*)this));
	return mIsOkay;
}



#if 0
WORD MemFile::write(DWORD value)
{
	WORD wordValue;

  if(!isOkay())return FALSE;
	if(BigEndian==mByteOrder)
	{
		WORD hiWord(HIWORD(value));
		WORD loWord(LOWORD(value));

		wordValue=mIntelData.intelData(loWord);
		value=((DWORD)wordValue)<<16;
		wordValue=mIntelData.intelData(hiWord);
    value|=wordValue;
	}
  wordValue=(WORD)(value&0xFFFF);
	write(wordValue);
	wordValue=(WORD)(value>>16);
  write(wordValue);
  return TRUE;
}
#endif

		if(!mMIDIOutDevice.midiEvent(mMIDIEventVector[mPlayIndex]))return closeDevice();
		if(++mPlayIndex>=mMIDIEventVector.size())return closeDevice();





#if 0
WORD OptionsReg::isInTime(const SystemTime &systemTime)const
{
  if(daily())
	{
	  if(systemTime.hour()>=hour()&&
		   systemTime.minute()>=minute()&&
			 systemTime.second()>=second())return TRUE;
		return FALSE;
	}
  if(systemTime.month()>=month()&&
	   systemTime.day()>=day()&&
		 systemTime.year()>=year()&&
		 systemTime.hour()>=hour()&&
		 systemTime.minute()>=minute()&&
		 systemTime.second()>=second())return TRUE;
	return FALSE;
}
#endif


#if 0
// systemTime:12:58:01
// optionsReg:11:57:22

//19970101 11 57 22

WORD OptionsReg::isGreater(const SystemTime &systemTime)
{
  DWORD sysTime(0);
	DWORD optTime(0);
	DWORD sysDate(0);
	DWORD optDate(0);

  sysTime=((DWORD)systemTime.hour())<<16;
	sysTime|=((DWORD)systemTime.minute())<<8;
	sysTime|=(DWORD)sysTime.second();
	sysDate=((DWORD)systemTime.year())<<16;
	sysDate|=((DWORD)systemTime.month())<<8;
	sysDate|=(DWORD)sysTime.day();
	optDate=((DWORD)year())<<16;
	optDate|=((DWORD)month())<<8;
	optDate|=(DWORD)day();
  optTime=((DWORD)hour())<<16;
	optTime|=((DWORD)minute())<<8;
	optTime|=(DWORD)second();
	if(daily()
	{
	  if(sysTime>optTime)return TRUE;
		return FALSE;
  }
	else
	{
	  if(sysDate>optDate)return TRUE;
		else if(sysDate==optDate&&sysTime>=optTime)return TRUE;
	}
	return FALSE;
}


    case IFS_IFSFNDISCONNECT :
		  handleBox(IFS_IFSFNDISCONNECT);
		  break;
    case IFS_IFSFNCONNECT :
		  handleBox(IFS_IFSFNCONNECT);
		  break;
    case IFS_IFSFNFINDCLOSE :
		  handleBox(IFS_IFSFNFINDCLOSE);
		  break;
    case IFS_IFSFNDIR	:
		  handleBox(IFS_IFSFNDIR);
		  break;
    case IFS_IFSFNFILETIMES :
		  handleBox(IFS_IFSFNFILETIMES);
		  break;
    case IFS_IFSFNFILELOCKS :
		  handleBox(IFS_IFSFNFILELOCKS);
		  break;
    case IFS_IFSFNCOMMIT :
		  handleBox(IFS_IFSFNCOMMIT);
		  break;
    case IFS_IFSFNCLOSE :
		  handleBox(IFS_IFSFNCLOSE);
		  break;
    case IFS_IFSFNSEEK :
		  handleBox(IFS_IFSFNSEEK);
		  break;
    case IFS_IFSFNFINDNEXT :
		  handleBox(IFS_IFSFNFINDNEXT);
		  break;
    case IFS_IFSFNWRITE :
		  handleBox(IFS_IFSFNWRITE);
		  break;
    case IFS_IFSFNREAD :
		  handleBox(IFS_IFSFNREAD);
		  break;



void OwnerDrawList::drawEntire(const DrawItem &drawItem)
{
	PureDevice pureDevice(drawItem.deviceContext());
	PureDevice memDevice;
	String stringData;
	TEXTMETRIC textMetric;
	Rect drawRect;

	if(!isOkay())return;
  stringData.reserve(256);
	drawRect=drawItem.rectItem();
	memDevice.compatibleDevice(pureDevice);
	PureBitmap &pureBitmap=(((UINT)drawItem.itemState())&ODS_SELECTED?mPureBitmaps[BmSel]:mPureBitmaps[BmUnSel]);
	memDevice.select(pureBitmap,TRUE);
	pureDevice.bitBlt(drawRect,memDevice,Point(0,0));
	::SendMessage(drawItem.hwndItem(),LB_GETTEXT,drawItem.itemID(),(LPARAM)(LPSTR)stringData);
  if(stringData.isNull())::MessageBeep(0);
	::GetTextMetrics(drawItem.deviceContext(),&textMetric);

	if(drawItem.itemState()&ODS_DISABLED)
	  ::GrayString(drawItem.deviceContext(),(HBRUSH)0,(GRAYSTRINGPROC)0,
		(LPARAM)(LPSTR)stringData,stringData.length(),pureBitmap.width()+6,(drawRect.bottom()+drawRect.top()-textMetric.tmHeight)/2,0,0);
	else 
	  ::TextOut(drawItem.deviceContext(),pureBitmap.width()+6,(drawRect.bottom()+drawRect.top()-textMetric.tmHeight)/2,(LPSTR)stringData,stringData.length());

  if((((UINT)drawItem.itemState())&ODS_FOCUS))
	{
		Rect bmpRect(drawRect);
		bmpRect.right(bmpRect.left()+pureBitmap.width());
		bmpRect.bottom(bmpRect.top()+pureBitmap.height());
		::DrawFocusRect(drawItem.deviceContext(),(RECT*)&bmpRect);
	}
	memDevice.select(pureBitmap,FALSE);
}


DWORD DirTree::getDirList(const String &pathDir,Block<DirEntry> &dirEntries)
{
  String entryName;
  Block<String> dirList;
  PathFind pathFind;
	FindData findData;

  dirEntries.remove();
	if(pathDir.isNull())return FALSE;
	pathFind.dirList(pathDir,dirList);
	if(dirList.size()<=2)return FALSE;
	if(!makeFileName(dirList[0],entryName))return FALSE;
	if(entryName!=mCurrDir)return FALSE;
	if(!makeFileName(dirList[1],entryName))return FALSE;
	if(entryName!=String(mUpDir))return FALSE;
	for(int itemIndex=2;itemIndex<dirList.size();itemIndex++)
	{
		if(!findData.findFirst(dirList[itemIndex]))continue;
		if(!(findData.attributes()&FindData::FileDirectory))continue;
	  if(!makeFileName(dirList[itemIndex],entryName))continue;
		if(entryName==mCurrDir)break;
		dirEntries.insert(&DirEntry(dirList[itemIndex],entryName));
	}
	return dirEntries.size();
}



WORD PathFind::canTranscend(String &pathEntry)
{
  FindData findData;
	char *lpStr0;

	if(!findData.findFirst(pathEntry)||findData.attributes()&FindData::FileDirectory)
	{
		String tempString(pathEntry);
		if(*((char*)tempString+tempString.length())!=BackSlash&&*((char*)tempString+tempString.length())!=ForwardSlash)tempString+=mBackSlashString;
		tempString+=mStarDotStarString;
		if(!mFileBlock.findFirst(tempString,_A_SUBDIR))
		{
			if(isDirectory(mFileBlock))return TRUE;
			while(!mFileBlock.findNext())if(isDirectory(mFileBlock))return TRUE;
		}
		return FALSE;
	}
	lpStr=::strchr(pathEntry,Dot);

//	if(0==(lpStr=::strchr(pathEntry,Dot)))
//	{
//		String tempString(pathEntry);
//		if(*((char*)tempString+tempString.length())!=BackSlash&&*((char*)tempString+tempString.length())!=ForwardSlash)tempString+=mBackSlashString;
//		tempString+=mStarDotStarString;
//		if(!mFileBlock.findFirst(tempString,_A_SUBDIR))
//		{
//			if(isDirectory(mFileBlock))return TRUE;
//			while(!mFileBlock.findNext())if(isDirectory(mFileBlock))return TRUE;
//		}
//		return FALSE;
//	}
	*lpStr=BackSlash;
	return FALSE;
}


#if 0
WORD PathFind::canTranscend(String &pathEntry)
{
	char *lpStr;

	if(0==(lpStr=::strchr(pathEntry,Dot)))
	{
		String tempString(pathEntry);
		if(*((char*)tempString+tempString.length())!=BackSlash&&*((char*)tempString+tempString.length())!=ForwardSlash)tempString+=mBackSlashString;
		tempString+=mStarDotStarString;
		if(!mFileBlock.findFirst(tempString,_A_SUBDIR))
		{
			if(isDirectory(mFileBlock))return TRUE;
			while(!mFileBlock.findNext())if(isDirectory(mFileBlock))return TRUE;
		}
		return FALSE;
	}
	if(lpStr)*lpStr=BackSlash;
	return FALSE;
}
#endif



#if 0
WORD PathFind::canTranscend(String &pathEntry)
{
	char *lpStr;

	if(0==(lpStr=::strchr(pathEntry,Dot)))
	{
		String tempString(pathEntry);
		if(*((char*)tempString+tempString.length())!=BackSlash&&*((char*)tempString+tempString.length())!=ForwardSlash)tempString+=mBackSlashString;
		tempString+=mStarDotStarString;
		if(!mFileBlock.findFirst(tempString,FileBlock::SubDirectory))
		{
			if(isDirectory(mFileBlock))return TRUE;
			while(!mFileBlock.findNext())if(isDirectory(mFileBlock))return TRUE;
		}
		return FALSE;
	}
	if(lpStr)*lpStr=BackSlash;
	return FALSE;
}
#endif



void SystemTime::daysAdd360(short dayCount)
{
  SystemTime toDateTime;
  long totalDays;
	WORD isThirtyFirst;

  toDateTime=*this;
	if(!year()&&!day()&&!month()||!dayCount)return *this;
	isThirtyFirst=LongestDaysInMonth==day();
	if(isThirtyFirst)day(LongestDaysInMonth-1);
	totalDays=360*(long)year()+30*(long)month()+(long)day()+dayCount-391;
	toDateTime.day((short)(totalDays%30)+1);
	toDateTime.month(Month((short)(totalDays/30)%12+1));
	toDateTime.year((short)(totalDays/360)+1);
	if(!(dayCount%30)&&isThirtyFirst)
	switch(toDateTime.month())
	{
	  case January : 
		case March :
		case May :
		case July :
		case August :
		case October :
		case December :
		  toDateTime.day(toDateTime.day()+1);
			break;
	}
	*this=toDateTime;
}




#ifndef _COMMON_PUREPALETTE_HPP_
#define _COMMON_PUREPALETTE_HPP_
#include <string.h>
#ifndef _COMMON_WINDOWS_HPP_
#include <common/windows.hpp>
#endif
#ifndef _COMMON_PUREBITMAP_HPP_
#include <common/purebmp.hpp>
#endif
#ifndef _COMMON_PUREDEVICE_HPP_
#include <common/purehdc.hpp>
#endif
#ifndef _COMMON_RGBCOLOR_HPP_
#include <common/rgbcolor.hpp>
#endif
#ifndef _COMMON_PUREVECTOR_HPP_
#include <common/pvector.hpp>
#endif
#ifndef _COMMON_PVECTOR_TPP_
#include <common/pvector.tpp>
#endif
#ifndef _COMMON_PALETTEENTRY_HPP_
#include <common/palentry.hpp>
#endif

class PurePalette
{
public:
	enum {MaxColors=256};
	enum InitPal{InitSys,InitNone};
	typedef int PaletteIndex;
//  PurePalette(void);
  PurePalette(InitPal initPal=InitNone);
	PurePalette(HPALETTE hPalette);
	PurePalette(const PurePalette &somePurePalette);
	~PurePalette();
	PurePalette &operator=(const PurePalette &somePurePalette);
	PurePalette &operator=(HPALETTE hPalette);
	PaletteEntry &operator[](PaletteIndex paletteIndex);
	WORD operator==(const PurePalette &somePurePalette)const;
	WORD identityPalette(void);
  WORD systemPalette(void);
	WORD isIdentityPalette(void)const;
	void cyclePalette(void);
	PaletteIndex paletteIndex(const RGBColor &someRGBColor)const;
	void getPaletteColors(PureVector<RGBColor> &someRGBColors)const;
	void setPaletteColors(PureVector<RGBColor> &someRGBColors,PaletteEntry::PaletteFlags paletteFlag=PaletteEntry::NullFlag);
	WORD setPaletteColor(short paletteIndex,RGBColor &someRGBColor,PaletteEntry::PaletteFlags paletteFlag=PaletteEntry::NullFlag);
	WORD getPaletteColor(short paletteIndex,RGBColor &someRGBColor)const;
	void clearPalette(void);
	void usePalette(const PureDevice &somePureDevice,short usage);
	WORD paletteEntry(PaletteIndex paletteIndex,RGBColor &someRGBColor)const;
	RGBColor paletteEntry(PaletteIndex paletteIndex)const;
	WORD paletteEntries(void)const;
	WORD isInUse(void)const;
	operator HPALETTE(void)const;
private:
  enum {SystemStaticColors=20};
	WORD createPalette(void);
	void clearPaletteEntries(void);
	void setPaletteColors(void)const;
	void destroyPalette(void);

	HPALETTE mhPalette;
	HPALETTE mhOldPalette;
  PaletteEntry mPaletteData[MaxColors];
	WORD mIsInUse;
};

//inline
//PurePalette::PurePalette(void)
//: mhPalette(0), mhOldPalette(0), mIsInUse(FALSE)
//{
//	clearPaletteEntries();
//	createPalette();
//	return;
//}

inline
PurePalette::PurePalette(InitPal initPal)
: mhPalette(0), mhOldPalette(0), mIsInUse(FALSE)
{
  if(InitSys==initPal)systemPalette();
	else {clearPaletteEntries(),createPalette();}  
	return;
}

inline
PurePalette::~PurePalette()
{
  destroyPalette();
	return;
}

inline
WORD PurePalette::paletteEntries(void)const
{
	return MaxColors;
}

inline
PurePalette::operator HPALETTE(void)const
{
	return mhPalette;
}

inline
void PurePalette::clearPaletteEntries(void)
{
	::memset((void*)&mPaletteData,0,sizeof(mPaletteData));
}

inline
void PurePalette::setPaletteColors(void)const
{
	::SetPaletteEntries(mhPalette,0,MaxColors,(PALETTEENTRY FAR*)&mPaletteData);
}

inline
WORD PurePalette::isInUse(void)const
{
	return mIsInUse;
}

inline
PurePalette::PaletteIndex PurePalette::paletteIndex(const RGBColor &someRGBColor)const
{
	return ::GetNearestPaletteIndex(mhPalette,(COLORREF)someRGBColor);
}

inline
PaletteEntry &PurePalette::operator[](PaletteIndex paletteIndex)
{
	assert(paletteIndex<MaxColors);
  return mPaletteData[paletteIndex];
}
#endif



#include <common/purepal.hpp>
#include <bsptree/rgbtree.hpp>

PurePalette::PurePalette(const PurePalette &somePurePalette)
: mhPalette(0), mhOldPalette(), mIsInUse(FALSE)
{
	::GetPaletteEntries(somePurePalette,0,MaxColors,(PALETTEENTRY FAR *)&mPaletteData);
	createPalette();
}

PurePalette::PurePalette(HPALETTE hPalette)
: mhPalette(0), mhOldPalette(0), mIsInUse(FALSE)
{
	::GetPaletteEntries(hPalette,0,MaxColors,(PALETTEENTRY FAR *)&mPaletteData);
	createPalette();
}

PurePalette &PurePalette::operator=(const PurePalette &somePurePalette)
{
  destroyPalette();
	::GetPaletteEntries(somePurePalette,0,MaxColors,(PALETTEENTRY FAR*)&mPaletteData);
	createPalette();
	return *this;
}

PurePalette &PurePalette::operator=(HPALETTE hPalette)
{
	destroyPalette();
	::GetPaletteEntries(hPalette,0,MaxColors,(PALETTEENTRY FAR*)&mPaletteData);
	createPalette();
  return *this;
}

WORD PurePalette::operator==(const PurePalette &somePurePalette)const
{
	for(short paletteIndex=0;paletteIndex<MaxColors;paletteIndex++)
		if(!(mPaletteData[paletteIndex]==somePurePalette.mPaletteData[paletteIndex]))return FALSE;
	return TRUE;
}

void PurePalette::destroyPalette(void)
{
	if(mhPalette){::DeleteObject(mhPalette);mhPalette=0;}
	mhOldPalette=0;
  mIsInUse=0;
	clearPaletteEntries();
  return;
}

void PurePalette::cyclePalette(void)
{
  PaletteEntry paletteEntryOne(mPaletteData[0]);
	::memcpy(&mPaletteData[0],&mPaletteData[1],sizeof(mPaletteData)-sizeof(PaletteEntry));
	mPaletteData[MaxColors-1]=paletteEntryOne;
	setPaletteColors();
}

WORD PurePalette::paletteEntry(PaletteIndex paletteIndex,RGBColor &someRGBColor)const
{
	if(paletteIndex>=paletteEntries())return FALSE;
  someRGBColor=(RGBColor)mPaletteData[paletteIndex];
	return TRUE;
}

RGBColor PurePalette::paletteEntry(PaletteIndex paletteIndex)const
{
	RGBColor tempColor(0,0,0);

	paletteEntry(paletteIndex,tempColor);
	return tempColor;
}

WORD PurePalette::createPalette()
{
  PaletteEntry FAR *lpPaletteEntry;
	LOGPALETTE FAR *lpLogPalette;
	HGLOBAL hGlobalPalette;

	if(mhPalette){::DeleteObject(mhPalette);mhPalette=0;}
	hGlobalPalette=::GlobalAlloc(GMEM_ZEROINIT|GMEM_MOVEABLE,sizeof(LOGPALETTE)+(MaxColors*sizeof(PALETTEENTRY)));
	lpLogPalette=(LOGPALETTE FAR *)::GlobalLock(hGlobalPalette);
	lpLogPalette->palNumEntries=MaxColors;
	lpLogPalette->palVersion=0x300;
	for(short paletteIndex=0;paletteIndex<MaxColors;paletteIndex++)
  {
		lpPaletteEntry=(PaletteEntry FAR *)&lpLogPalette->palPalEntry[paletteIndex];
    *lpPaletteEntry=mPaletteData[paletteIndex];
  }
	mhPalette=::CreatePalette((LOGPALETTE FAR *)lpLogPalette);
	::GlobalUnlock(hGlobalPalette);
	::GlobalFree(hGlobalPalette);
	return (mhPalette?TRUE:FALSE);
}

void PurePalette::usePalette(const PureDevice &somePureDevice,short usage)
{
	if(usage)
	{
		mhOldPalette=::SelectPalette(somePureDevice,mhPalette,FALSE);
		::RealizePalette(somePureDevice);
		mIsInUse=TRUE;
	}
	else
	{
		::SelectPalette(somePureDevice,mhOldPalette,FALSE);
		::RealizePalette(somePureDevice);
		mIsInUse=FALSE;
	}
}

void PurePalette::getPaletteColors(PureVector<RGBColor> &someRGBColors)const
{
	size_t paletteColors((size_t)someRGBColors.size(paletteEntries()));
	for(short paletteIndex=0;paletteIndex<paletteColors;paletteIndex++)
	  someRGBColors[paletteIndex]=(RGBColor)mPaletteData[paletteIndex];
}

WORD PurePalette::getPaletteColor(short paletteIndex,RGBColor &someRGBColor)const
{
	if(paletteIndex>=paletteEntries())return FALSE;
	someRGBColor=(RGBColor)mPaletteData[paletteIndex];
  return TRUE;
}

void PurePalette::setPaletteColors(PureVector<RGBColor> &someRGBColors,PaletteEntry::PaletteFlags paletteFlag)
{
	size_t paletteColors((size_t)someRGBColors.size());

	for(short paletteIndex=0;paletteIndex<paletteColors;paletteIndex++)
		setPaletteColor(paletteIndex,someRGBColors[paletteIndex],paletteFlag);
}

WORD PurePalette::setPaletteColor(short paletteIndex,RGBColor &someRGBColor,PaletteEntry::PaletteFlags paletteFlag)
{
	if(paletteIndex>=paletteEntries())return FALSE;
  mPaletteData[paletteIndex]=someRGBColor;
	mPaletteData[paletteIndex].flags(paletteFlag);
	::SetPaletteEntries(mhPalette,paletteIndex,1,(PALETTEENTRY FAR*)&mPaletteData[paletteIndex]);
	return TRUE;
}

void PurePalette::clearPalette(void)
{
	short paletteColors(paletteEntries());
	RGBColor nullColor;

	for(short paletteIndex=0;paletteIndex<paletteColors;paletteColors++)
		setPaletteColor(paletteIndex,nullColor);
}

WORD PurePalette::systemPalette(void)
{
	PureDevice screenDevice;
  WORD systemPaletteEntries;

	destroyPalette();
  screenDevice.screenDevice();
	systemPaletteEntries=::GetSystemPaletteEntries(screenDevice,0,MaxColors,(PALETTEENTRY FAR*)&mPaletteData);
	createPalette();
  return systemPaletteEntries;
}

WORD PurePalette::identityPalette(void)
{
  PaletteEntry paletteData[MaxColors];
	RGBTree paletteTree;
	RGBTree systemTree;
  RGBColor systemColor;
	PureDevice pureDevice;
	WORD staticColors;
  WORD useableIndex(0);
	RGBColor rgbColor;

	pureDevice.screenDevice();
	if(SYSPAL_NOSTATIC==::GetSystemPaletteUse(pureDevice))
	{
    PureVector<RGBColor> paletteColors;
		getPaletteColors(paletteColors);
		setPaletteColors(paletteColors,PaletteEntry::NoCollapse);
		setPaletteColor(PurePalette::MaxColors-1,RGBColor(255,255,255));
		setPaletteColor(0,RGBColor(0,0,0));
		createPalette();
		return TRUE;
	}
	if(SystemStaticColors!=(staticColors=::GetDeviceCaps(pureDevice,NUMCOLORS)))return FALSE;
	staticColors/=2;
	if(MaxColors!=::GetSystemPaletteEntries(pureDevice,0,MaxColors,(PALETTEENTRY FAR *)&paletteData))return FALSE;
	for(short paletteIndex=0;paletteIndex<staticColors;paletteIndex++)
		systemTree.insertItem(paletteData[paletteIndex]);
	for(paletteIndex=MaxColors-staticColors;paletteIndex<MaxColors;paletteIndex++)
    systemTree.insertItem(paletteData[paletteIndex]);
	for(short index=0;index<staticColors;index++)paletteData[index].flags(PaletteEntry::NullFlag);
	while(index<MaxColors-staticColors&&useableIndex<MaxColors)
	{
		getPaletteColor(useableIndex,rgbColor);
		if(!systemTree.searchItem(rgbColor))
		{
			if(!paletteTree.searchItem(rgbColor))
			{
				paletteTree.insertItem(rgbColor);
				paletteData[index]=rgbColor;
				paletteData[index].flags(PaletteEntry::NullFlag);
				index++;
			}
		}
		useableIndex++;
	}
	for(;index<MaxColors-staticColors;index++)paletteData[index].flags(PaletteEntry::NullFlag);  // NoCollapse 
	for(index=MaxColors-staticColors;index<MaxColors;index++)paletteData[index].flags(PaletteEntry::NullFlag);
  ::memcpy(mPaletteData,paletteData,sizeof(paletteData));
	createPalette();
  return TRUE;
}

WORD PurePalette::isIdentityPalette(void)const
{
  PaletteEntry paletteData[MaxColors];
	PureDevice pureDevice;
	WORD staticColors;

	pureDevice.screenDevice();
	if(SYSPAL_NOSTATIC==::GetSystemPaletteUse(pureDevice))
	{
		if(!(RGBColor(255,255,255)==mPaletteData[PurePalette::MaxColors-1]))return FALSE;
		if(!(RGBColor(0,0,0)==mPaletteData[0]))return FALSE;
    return TRUE;
	}
	if(SystemStaticColors!=(staticColors=::GetDeviceCaps(pureDevice,NUMCOLORS)))return FALSE;
	staticColors/=2;
	if(MaxColors!=::GetSystemPaletteEntries(pureDevice,0,MaxColors,(PALETTEENTRY FAR *)&paletteData))return FALSE;
	for(short paletteIndex=0;paletteIndex<staticColors;paletteIndex++)
		if(!(RGBColor(mPaletteData[paletteIndex])==RGBColor(paletteData[paletteIndex])))return FALSE;
	for(paletteIndex=MaxColors-staticColors;paletteIndex<MaxColors;paletteIndex++)
		if(!(RGBColor(mPaletteData[paletteIndex])==RGBColor(paletteData[paletteIndex])))return FALSE;
	return TRUE;
}



//inline
//DIBitmap &DIBitmap::operator=(const PurePalette &somePurePalette)
//{
//	(BitmapInfo&)*this=somePurePalette;
//  mBitmapPalette=somePurePalette;
//	createBitmap(mBitmapDevice);
//	return *this;
//}



//	DIBitmap &operator=(const PurePalette &somePurePalette);


WORD Process::createProcess(String moduleNameString,String cmdLineString,BOOL modNameIsFirstArg=TRUE,const CreationFlags &creationFlags,WORD showWindow)
{
	PathFind pathFind;
	Profile profile;
	String pureFileName;
	String pathFileNameString;
	String commandLineString;
	String startupDirString(".");
	String blankString(" ");

	if(isOkay())terminateProcess();
	if(moduleNameString.isNull())return FALSE;
	pureFileName=moduleNameString;
	if(pathFind.findFile(pureFileName,pathFileNameString))
	{
		moduleNameString=pathFileNameString;
		if(modNameIsFirstArg)commandLineString+=pathFileNameString+blankString;
//		commandLineString=pathFileNameString;
//		commandLineString+=blankString;
	}
	else if(modNameIsFirstArg)commandLineString=moduleNameString+blankString;
//	{
//  
//		commandLineString=moduleNameString;
//		commandLineString+=blankString;
//	}
	commandLineString+=cmdLineString;
	if(SW_SHOWNORMAL!=showWindow){mStartupInfo.dwFlags=STARTF_USESHOWWINDOW;mStartupInfo.wShowWindow=showWindow;}
	mIsOkay=(WORD)::CreateProcess(moduleNameString,commandLineString,0,0,0,(DWORD)creationFlags,0,0,&mStartupInfo,(PROCESS_INFORMATION*)((PureProcess*)this));
	if(!mIsOkay)return FALSE;
	mDisposition=FreeHandle;
	return mIsOkay;
}




#ifndef _COMMON_SMARTPOINTER_HPP_
#define _COMMON_SMARTPOINTER_HPP_
#ifndef _COMMON_WINDOWS_HPP_
#include <common/windows.hpp>
#endif

class PointerDisposition
{
public:
  enum Diposition{Assume,Delete};
};

template <class T>
class SmartPointer
{
public:
//	enum Disposition{Assume,Delete};
	SmartPointer(void);
	SmartPointer(T FAR *lpSmartPointer,Disposition disposition=Assume);
	SmartPointer(const SmartPointer<T> &someSmartPointer);
	virtual ~SmartPointer();
	T FAR *operator->(void);
	operator T FAR *(void);
	operator LPARAM(void);
	SmartPointer<T> &operator=(const SmartPointer<T> &someSmartPointer);
	SmartPointer<T> &operator=(T FAR *lpSmartPointer);
	WORD operator==(const SmartPointer<T> &someSmartPointer)const;
	void disposition(PointerDisposition::Disposition disposition);
	PointerDisposition::Disposition disposition(void)const;
//	void disposition(Disposition disposition);
//  Disposition disposition(void)const;
	WORD isOkay(void)const;
private:
  void destroy(void);
	T FAR *mlpSmartPointer;
	PointerDisposition::Disposition mDisposition;
//	Disposition mDisposition;
};
#if defined(_MSC_VER)
#include <common/pointer.tpp>
#endif
#endif




#ifndef _COMMON_SMARTPOINTER_TPP_
#define _COMMON_SMARTPOINTER_TPP_

template <class T>
SmartPointer<T>::SmartPointer(void)
: mlpSmartPointer(0), mDisposition(Assume)
{
}

template <class T>
SmartPointer<T>::SmartPointer(T FAR *lpSmartPointer,Disposition disposition)
: mlpSmartPointer(lpSmartPointer), mDisposition(disposition)
{
}

template <class T>
SmartPointer<T>::SmartPointer(const SmartPointer<T> &someSmartPointer)
: mlpSmartPointer(0), mDisposition(Assume)
{
	*this=someSmartPointer;
}

template <class T>
SmartPointer<T>::~SmartPointer()
{
	destroy();
}

template <class T>
SmartPointer<T>::operator T FAR *(void)
{
	return mlpSmartPointer;
}

template <class T>
SmartPointer<T>::operator LPARAM(void)
{
	return (LPARAM)mlpSmartPointer;
}

template <class T>
T FAR *SmartPointer<T>::operator->(void)
{
	return mlpSmartPointer;
}

template <class T>
SmartPointer<T> &SmartPointer<T>::operator=(const SmartPointer<T> &someSmartPointer)
{
	destroy();
	mlpSmartPointer=someSmartPointer.mlpSmartPointer;
	mDisposition=Assume;
	return *this;
}

template <class T>
SmartPointer<T> &SmartPointer<T>::operator=(T FAR *lpSmartPointer)
{
	destroy();
	mlpSmartPointer=lpSmartPointer;
	mDisposition=Assume;
	return *this;
}

template <class T>
WORD SmartPointer<T>::operator==(const SmartPointer<T> &someSmartPointer)const
{
	return *mlpSmartPointer==*someSmartPointer.mlpSmartPointer;
}

template <class T>
void SmartPointer<T>::destroy(void)
{
	if(!mlpSmartPointer)return;
	if(Assume==mDisposition)mlpSmartPointer=0;
	else {delete mlpSmartPointer;mlpSmartPointer=0;}
}

template <class T>
void SmartPointer<T>::disposition(PointerDisposition::Disposition disposition)
{
  mDisposition=disposition;
}

template <class T>
PointerDisposition::Disposition SmartPointer<T>::disposition(void)const
{
	return mDisposition;
}

//template <class T>
//void SmartPointer<T>::disposition(Disposition disposition)
//{
//	mDisposition=disposition;
//}
//
//template <class T>
//SmartPointer<T>::Disposition SmartPointer<T>::disposition(void)const
//{
//	return mDisposition;
//}

template <class T>
WORD SmartPointer<T>::isOkay(void)const
{
  return (mlpSmartPointer?TRUE:FALSE);
}
#endif

#if 0
inline
void String::operator+=(char someChar)
{
	String tempString(someChar);
	(*this)+=tempString;
}
#endif



void Progress::createWindow(void)
{
	::CreateWindow(szClassName,mCaptionString,
		WS_OVERLAPPED|WS_CAPTION|WS_CLIPCHILDREN|0x04L|WS_THICKFRAME,
		mInitialPoint.x(),mInitialPoint.y(),PWcx,PWcy,
		mhParentWindow,NULL,mhProcessInstance,(LPSTR)this);
}



class DlgHookProc : public WinHookProc
{
public:
  DlgHookProc();
	virtual ~DlgHookProc();
protected:
  virtual DWORD winID(void)const;
private:
};

DlgHookProc::DlgHookProc()
{
}

DlgHookProc::~DlgHookProc()
{
}

DWORD DlgHookProc::winID(void)const
{
  return DWL_DLGPROC;
}


//#ifndef _COMMON_OPENFILE_HPP_
//#include <common/openfile.hpp>
//#endif


removed from block.hpp
//#ifndef _COMMON_STDLIB_HPP_
//#include <common/stdlib.hpp>
//#endif




//#ifndef _COMMON_WINDEF_HPP_
//#include <common/windef.hpp>
//#endif
//#ifndef _COMMON_WINDOWS_HPP_
//#include <common/windows.hpp>
//#endif


#if 0
  FileHandle decodeFile;
	String strLine;
  BYTE charByte;

  strLines.remove();
	decodeFile.open(pathFileName);
	if(!decodeFile.isOkay())return FALSE;
	FileMap decodeMap(decodeFile);
	PureViewOfFile decodeView(decodeMap);
  while(decodeView.getLine(strLine))strLines.insert(&strLine);
  return (strLines.size()?TRUE:FALSE);
#endif


BOOL OwnerDrawList::setTabStops(Block<PureDWORD> &tabStops)
{
  if(!isOkay())return FALSE;
	mTabStopArray.size(tabStops.size());
	if(!mTabStopArray.size())return FALSE;
	int *pIntArray=(int*)mTabStopArray;
	for(int itemIndex=0;itemIndex<tabStops.size();itemIndex++)pIntArray[itemIndex]=tabStops[itemIndex];
  return sendMessage(LB_SETTABSTOPS,mTabStopArray.size(),(LPARAM)pIntArray);
//  BOOL retCode(FALSE);
//	int *pIntArray=new int[tabStops.size()];
//	for(int itemIndex=0;itemIndex<tabStops.size();itemIndex++)pIntArray[itemIndex]=tabStops[itemIndex];
//  retCode=sendMessage(LB_SETTABSTOPS,tabStops.size(),(LPARAM)pIntArray);
//	delete pIntArray;
//	return retCode;
}



CallbackData::ReturnType VectorHandler::callHandler(Block<CallbackPointer> &someCallbackVector,CallbackData &someCallbackData)
{
	size_t size((size_t)someCallbackVector.size());
	CallbackData::ReturnType returnCode(0);
	CallbackData::ReturnType callReturn;

	for(int vectorIndex=0;vectorIndex<size;vectorIndex++)
  {
	  callReturn=someCallbackVector[vectorIndex].callback(someCallbackData);
		if(callReturn)returnCode=callReturn;
//		returnCode=someCallbackVector[vectorIndex].callback(someCallbackData);
		size=(size_t)someCallbackVector.size();
	}
	return returnCode;
}


{
	Vector3D vector3D(Point3D(-33,32,-10),Point3D(32,32,-10),Point3D(32,-33,-10),Point3D(-33,-33,-10));
	Vector2D vector2D;
	mDevice3D->translatePoint(vector3D,vector2D);
//  ::clearBitmap((DWORD)mDIBitmap->ptrData(),mDIBitmap->imageExtent());
	::lineWINGBlt((DWORD)mDIBitmap->ptrData(),&vector2D[0],&vector2D[1],mDIBitmap->width(),mDIBitmap->height(),255);
	::lineWINGBlt((DWORD)mDIBitmap->ptrData(),&vector2D[1],&vector2D[2],mDIBitmap->width(),mDIBitmap->height(),255);
	::lineWINGBlt((DWORD)mDIBitmap->ptrData(),&vector2D[2],&vector2D[3],mDIBitmap->width(),mDIBitmap->height(),255);
	::lineWINGBlt((DWORD)mDIBitmap->ptrData(),&vector2D[3],&vector2D[0],mDIBitmap->width(),mDIBitmap->height(),255);
}




class EIPCursor : PureBitmap
{
public:
  EIPCursor(const String &strBitmap);
	virtual EIPCursor();
	WORD currentLine(void)const;
	void currentLine(WORD currentLine);
	WORD isVisible(void)const;
	void isVisible(WORD isVisible);
	DWORD eip(void)const;
	void eip(DWORD eip);
	const Rect &bmRect(void)const;
	void bmRect(const Rect &bmRect);
private:
  WORD mCurrentLine;
	WORD mIsVisible;
	DWORD mCurrentEIP;
	Rect mEIPRect;
};



// *********************************************************

Process::Process(HANDLE hProcess)
: mIsOkay(FALSE), mDisposition(AssumeHandle)
{
  *this=hProcess;
//	::GetStartupInfo(&mStartupInfo);
//	if(!hProcess)return;
//	setProcess(hProcess);
//	mIsOkay=TRUE;
}



FileMap::FileMap(const FileHandle &someFileHandle)
:	mMaxExtentHigh(0L), mMaxExtentLow(0), mhFileHandle(0)
{
  create(someFileHandle);
//	if(FileHandle::Read==someFileHandle.access())mPaging=ReadOnly;
//	else if(FileHandle::Write==someFileHandle.access())mPaging=WriteCopy;
//	else if(FileHandle::ReadWrite==someFileHandle.access())mPaging=ReadWrite;
//	else mPaging=ReadOnly;
//	mProtection=Commit;
//	create(String(""),0L,someFileHandle.size(),mPaging,mProtection,(HANDLE)someFileHandle);
}

String String::betweenString(char beginToken,char endToken)const
{
  char nullString[MaxString]={0};
	short stringLength;
	char *lpBegin;
	char *lpEnd;

	if(!mnpStr)return nullString;
	stringLength=length();
	if(1>=stringLength)return nullString;
	if(beginToken)
	{
		if(0==(lpBegin=::strchr(mnpStr,beginToken)))return nullString;
		if(++lpBegin-mnpStr>=stringLength)return nullString;
	}
	else lpBegin=mnpStr;
	if(0==(lpEnd=::strchr(lpBegin,endToken)))return *this;
	if(lpBegin==lpEnd)return nullString;
	assert(sizeof(nullString)>(lpEnd-lpBegin)+1);
	::memcpy(nullString,lpBegin,lpEnd-lpBegin);
	*(nullString+(lpEnd-lpBegin))=0;
	return nullString;
}


void PurePalette::readPalette(const String &strPathFileName)
{
  FileHandle palFile(strPathFileName);
	FileMap palMap(palFile);
	PureViewOfFile palView(palMap);
	PaletteEntry paletteEntry;
	String strLine;
	int palEntries;
	char *pLine;
	char strTokens[]={' ','\0'};

	if(!palFile.isOkay())return;
	palView.getLine(strLine);
	if(!(strLine==String("JASC-PAL")))return;
	palView.getLine(strLine);
	if(!(strLine==String("0100")))return;
	palView.getLine(strLine);
	palEntries=::atoi(strLine);
	if(palEntries!=MaxColors)return;
	for(int palEntry=0;palEntry<palEntries;palEntry++)
	{
	  palView.getLine(strLine);
		pLine=(char*)strLine;
		pLine=::strtok(pLine,strTokens);
		if(!pLine)continue;
    paletteEntry.red(::atoi(pLine));
		pLine=::strtok(0,strTokens);
		if(!pLine)continue;
		paletteEntry.green(::atoi(pLine));
		pLine=::strtok(0,strTokens);
		if(!pLine)continue;
		paletteEntry.blue(::atoi(pLine));
//		paletteEntry.red(::atoi(strLine.betweenString(0,' ')));
// 		paletteEntry.green(::atoi(strLine.betweenString(' ',' ')));
//		paletteEntry.blue(::atoi(strLine.betweenString(' ',0).betweenString(' ',0)));
		paletteEntry.flags(PaletteEntry::NoCollapse);
		mPaletteData[palEntry]=paletteEntry;
	}
	createPalette();
}


#if 0
String String::betweenString(char beginToken,char endToken)const
{
	String nullString;
	short stringLength;
	char *lpBegin;
	char *lpEnd;

	if(!mnpStr)return nullString;
	stringLength=length();
	if(1>=stringLength)return nullString;
	if(beginToken)
	{
		if(0==(lpBegin=::strchr(mnpStr,beginToken)))return nullString;
		if(++lpBegin-mnpStr>=stringLength)return nullString;
	}
	else lpBegin=mnpStr;
	if(0==(lpEnd=::strchr(lpBegin,endToken)))return *this;
	if(lpBegin==lpEnd)return nullString;
	nullString.reserve((lpEnd-lpBegin)+1,FALSE);
	::memcpy(nullString,lpBegin,lpEnd-lpBegin);
	*((char*)nullString+(lpEnd-lpBegin))=0;
	return nullString;
}
#endif


void ProfileDebug::handleErrorBreak(const ExceptionRecord &exceptionRecord)
{
  CallbackData cbData(0,(LPARAM)&(ExceptionRecord&)exceptionRecord);
	mHandlers[ErrorBreakHandler].callback(cbData);
//	context(debugInfo().process(),debugInfo().thread());
//	showCode(debugInfo().process(),(DWORD)exceptionRecord.exceptionAddress(),60);
//	violation(String("ExceptionDebugEvent:")+exceptionRecord.exceptionCodeString());
}

(mhDC&&::IsWindow(mhParent)?TRUE:FALSE);




//	filterString=filterPatternString.betweenString('(',')');
//  filterString=fileTitleString.betweenString('.',0);
//	filterString.insert(".");
//	filter(filterString);
//	filterPattern(filterPatternString);


void DIBitmap::fillRect(Vector2D &vector2D,int paletteIndex)
{
  float xDeltaLeft(vector2D[3].x()-vector2D[0].x());
	float xDeltaRight(vector2D[2].x()-vector2D[1].x());
	float yDeltaLeft(vector2D[3].y()-vector2D[1].y());
	float yDeltaRight(vector2D[2].y()-vector2D[1].y());
	float xLeft(vector2D[0].x());
	float yLeft(vector2D[0].y());
	float xRight(vector2D[1].x());
	float yRight(vector2D[1].y());
	float xLeftIncr;
	float xRightIncr;
	float dydxLeft;
	float dydxRight;
	int iterations;
	
	iterations=(vector2D[0].x()-vector2D[3].x());
	if(!iterations)iterations=vector2D[0].y()-vector2D[3].y();
  if(iterations<0)iterations=-iterations;
	if(vector2D[3].x()>vector2D[0].x())xLeftIncr=1.00;
	else if(vector2D[3].x()<vector2D[0].x())xLeftIncr=-1.00;
	else xLeftIncr=0.00;
	if(vector2D[2].x()>vector2D[1].x())xRightIncr=1.00;
	else if(vector2D[2].x()<vector2D[1].x())xRightIncr=-1.00;
	else xRightIncr=0.00;
	if(0.00!=xDeltaLeft)dydxLeft=yDeltaLeft/xDeltaLeft;
	else dydxLeft=1.00;
	if(0.00!=xDeltaRight)dydxRight=yDeltaRight/xDeltaRight;
	else dydxRight=1.00;
  if(dydxLeft<0.00)dydxLeft=-dydxLeft;
	if(dydxRight<0.00)dydxRight=-dydxRight;
	for(int iterator=0;iterator<iterations;iterator++)
	{
	  line(Point(xLeft,yLeft),Point(xRight,yRight),paletteIndex);
		xLeft+=xLeftIncr;
		yLeft+=dydxLeft;
		xRight+=xRightIncr;
		yRight+=dydxRight;
	}
}


//#ifndef _COMMON_SHELLAPI_HPP_
//#include <common/shellapi.hpp>
//#endif
//#ifndef _COMMON_STRING_HPP_
//#include <common/string.hpp>
//#endif


//#include <common/version.hpp>
//	VersionInfo versionInfo;
//  if(versionInfo.isWinNT())
//	{
//	  MultiByteToWideChar(CP_ACP,MB_PRECOMPOSED,(LPSTR)(String&)ansiString,ansiLength,(WORD*)*this,size());
//	}
//	else
//	{
//	}


//	resData(::LockResource(::LoadResource(hResModule,mhResHandle)));


void OwnerDrawListAltColor::drawEntire(const DrawItem &drawItem)
{
	String stringData;

	if(!isOkay())return;
	sendMessage(drawItem.hwndItem(),LB_GETTEXT,drawItem.itemID(),(LPARAM)(LPSTR)stringData);
	PureDevice controlDevice(drawItem.deviceContext());
  if((((UINT)drawItem.itemState())&ODS_SELECTED))
	{
	  controlDevice.setBkColor(mBkGndSelColor);
		controlDevice.fillRect(drawItem.rectItem(),mBkGndSelBrush);
//	  ::SetBkColor(drawItem.deviceContext(),mBkGndSelColor);
//    ::FillRect(drawItem.deviceContext(),drawItem.rectItem(),(HBRUSH)(GDIObj)mBkGndSelBrush);
	}
	else 
	{
	  if(drawItem.itemID()%2)
		{
		  controlDevice.setBkColor(mAltColor);
			controlDevice.fillRect(drawItem.rectItem(),mAltBrush);
//		  ::SetBkColor(drawItem.deviceContext(),mAltColor);
//      ::FillRect(drawItem.deviceContext(),drawItem.rectItem(),(HBRUSH)(GDIObj)mAltBrush);
		}
		else 
		{
		  controlDevice.setBkColor(mPrimColor);
			controlDevice.fillRect(drawItem.rectItem(),mPrimBrush);
//		  ::SetBkColor(drawItem.deviceContext(),mPrimColor);
//      ::FillRect(drawItem.deviceContext(),drawItem.rectItem(),(HBRUSH)(GDIObj)mPrimBrush);
		}
	}
//	stringData.length(128);
//  ::FillRect(drawItem.deviceContext(),drawItem.rectItem(),(HBRUSH)(GDIObj)bkGndBrush);
	textOut(drawItem,stringData);
  return;
}


void OwnerDrawListAltColor::handleResize(WORD /*width*/,WORD /*height*/)
{
//  width(getParent().width()-yIndent());
}


#include <common/fileio.hpp>
FileIO &operator>>(FileIO &stream,WaveForm &waveForm)
{
  initWaveForm();
//	if(!wavePathFileName.strstr(mExtensionString))wavePathFileName+=mExtensionString;
//	mWavePathFileName=wavePathFileName;
//  FileHandle waveFile(wavePathFileName,FileHandle::Read,FileHandle::ShareReadWrite);
  if(!stream.isOkay())return stream;
	stream.read((BYTE*)&mHeaderString,sizeof(mHeaderString));
	stream.read((BYTE*)&mLengthData,sizeof(mLengthData));
	stream.read((BYTE*)&mSubHeaderString,sizeof(mSubHeaderString));


	waveFile.read((BYTE*)&mHeaderString,sizeof(mHeaderString));
	waveFile.read((BYTE*)&mLengthData,sizeof(mLengthData));
	waveFile.read((BYTE*)&mSubHeaderString,sizeof(mSubHeaderString));
	mFormatChunk<<waveFile;
	while(TRUE)
	{
		ChunkID chunkID;
		chunkID<<waveFile;
		waveFile.seek(-chunkID.size(),FileHandle::SeekCurrent);
		if(chunkID==String("data")){mDataChunk<<waveFile;break;}
		mGenericChunks.insert(&GenericChunk());
    mGenericChunks[mGenericChunks.size()-1]<<waveFile;
  }
	mSampleData.numSamples(mDataChunk.length());
	mSampleData<<waveFile;
	waveFile.close();
}


#if 0
WORD PathFind::getPathBlock(void)
{
	char *lpPath;
	char *lpTemp;

	if(0==(lpPath=::getenv((LPSTR)mPathString)))return FALSE;
	if(0==(lpTemp=::strtok(lpPath,mSemicolonString)))return FALSE;
	mPathEntry.remove();
	while(TRUE)
	{
		mPathEntry.insert(&String(lpTemp));
		if(0==(lpTemp=::strtok(0,mSemicolonString)))break;
	}
	return (mIsOkay=TRUE);
}
#endif



DWORD FileHandle::getLine(String &lineString)
{
	String lineBuffer;
	BYTE charByte;
  DWORD bytesRead(0);

	while(TRUE)
	{
		if(!read(charByte))break;
    bytesRead++;
		if(CarriageReturn==charByte)
		{
			if(!read(charByte))break;
      bytesRead++;
			if(LineFeed==charByte)
			{
				lineString=lineBuffer;
				return bytesRead;
			}
		}
		else if(NullChar==charByte)
		{
			lineString=lineBuffer;
      return bytesRead;
    }
		else lineBuffer+=charByte;
	}
	lineString=lineBuffer;
	return bytesRead;
}



DWORD PureViewOfFile::getLine(String &lineString)
{
	String lineBuffer;
	BYTE charByte;
  DWORD bytesRead(0);

	while(TRUE)
	{
		if(!read(charByte))break;
    bytesRead++;
		if(CarriageReturn==charByte)
		{
			if(!read(charByte))break;
      bytesRead++;
			if(LineFeed==charByte)
			{
				lineString=lineBuffer;
				return TRUE;
			}
		}
		else if(LineFeed==charByte)
		{
		  lineString=lineBuffer;
			return TRUE;
		}
		else if(NullChar==charByte)
		{
			lineString=lineBuffer;
      return TRUE;
    }
		else lineBuffer+=charByte;
	}
	lineString=lineBuffer;
	return bytesRead;
}







	WORD seek(LONG offset,SeekFrom seekFrom);
	FileIO &operator++(void);
	FileIO &operator--(void);  



//	operator T HUGE *(void)const;
	WORD operator==(const GlobalData<T> &someGlobalData)const;
	GlobalData<T> &operator=(const GlobalData<T> &someGlobalData);
	WORD isOkay(void)const;
private:
	void destroyGlobalData(void);
	WORD createGlobalData(void);
	T HUGE *mlpGlobalData;
  HGLOBAL mhGlobalData;
	UINT mGlobalFlags;
	DWORD mSizeData;
};

template <class T>
inline
GlobalData<T>::GlobalData(void)
: mlpGlobalData(0), mGlobalFlags(GMEM_FIXED), mSizeData(0), mhGlobalData(0)
{
}

template <class T>
inline
GlobalData<T>::GlobalData(const GlobalData<T> &someGlobalData)
: mlpGlobalData(0), mGlobalFlags(GMEM_FIXED), mSizeData(0), mhGlobalData(0)
{
  *this=someGlobalData;
}

template <class T>
inline
GlobalData<T>::GlobalData(DWORD sizeData,UINT globalFlags)
: mlpGlobalData(0), mGlobalFlags(globalFlags), mSizeData(sizeData), mhGlobalData(0)
{
  createGlobalData();
}

template <class T>
inline
GlobalData<T>::~GlobalData()
{
	destroyGlobalData();
}

template <class T>
inline
DWORD GlobalData<T>::size(void)const
{
	return mSizeData;
}

template <class T>
inline
WORD GlobalData<T>::size(DWORD sizeData,UINT globalFlags)
{
  mGlobalFlags=globalFlags;
	mSizeData=sizeData;
  return createGlobalData();
}

template <class T>
inline
UINT GlobalData<T>::globalFlags(void)const
{
	return mGlobalFlags;
}

template <class T>
inline
void GlobalData<T>::globalFlags(UINT globalFlags)
{
	mGlobalFlags=globalFlags;
}

//template <class T>
//inline
//GlobalData<T>::operator T HUGE *(void)const
//{
//	assert(0!=mlpGlobalData);
//	return mlpGlobalData;
//}

template <class T>
inline
T &GlobalData<T>::operator[](DWORD itemIndex)
{
	assert(itemIndex<mSizeData);
  return *(mlpGlobalData+itemIndex);
}

template <class T>
inline
WORD GlobalData<T>::createGlobalData(void)
{
	destroyGlobalData();
	if(!mSizeData)return FALSE;
	mhGlobalData=::GlobalAlloc(mGlobalFlags,mSizeData*sizeof(T));
  if(!mhGlobalData)return FALSE;
	mlpGlobalData=(T HUGE*)::GlobalLock(mhGlobalData);
  return TRUE;
}

template <class T>
inline
void GlobalData<T>::destroyGlobalData(void)
{
  if(!mlpGlobalData)return;
	::GlobalUnlock(mhGlobalData);
	::GlobalFree(mhGlobalData);
	mhGlobalData=0;
	mlpGlobalData=0;
}

template <class T>
inline
WORD GlobalData<T>::isOkay(void)const
{
	return (mlpGlobalData?TRUE:FALSE);
}
#if defined(_MSC_VER)
#include <common/gdata.tpp>
#endif
#endif








_getPECodeSectionCount proc near                                          ; int getPECodeSectionCount(char *strPathFileName)
  push ebp                                                                ; save previous stack frame
	mov  ebp,esp																														; create new stack frame
	pushad																																	; save all general purpose regs
	xor eax,eax
	mov smCodeSections,0000h
	mov smPESignature,0000h
	mov smFileHandle,INVALID_HANDLE
  CREATEFILE [ebp+08h],GENERIC_READ,FILE_SHARE_READ,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL ;  or GENERIC_WRITE
	mov smFileHandle,eax                                                    ; move file handle into variable
	cmp smFileHandle,INVALID_HANDLE                                         ; examine file handle
	je @@Fail                                                               ; if the handle is invalid, exit
	READFILE smFileHandle,offset smImageDosHeader,size smImageDosHeader     ; read IMAGEDOSHEADER
	cmp smImageDosHeader.DOSHEADER@@e_magic,IMAGE_DOS_SIGNATURE             ; examine the magic number
	jne @@Fail                                                              ; if it's not equal then end
	SEEK smFileHandle,smImageDosHeader.DOSHEADER@@e_lfanew,SEEK_BEGIN       ; seek to new header
  READFILE smFileHandle,offset smPESignature,size smPESignature           ; read in the signature
	cmp smPESignature,IMAGE_PE_SIGNATURE                                    ; make sure this is a PE file
	jne @@Fail                                                              ; if not then we're done here
	READFILE smFileHandle,offset smImageFileHeader,size IMAGEFILEHEADER     ; read in the file header
	READFILE smFileHandle,offset smImageOptionalHeader,size IMAGEOPTIONALHEADER ; read in the optional header
  xor eax,eax                                                             ; clear out eax register
	mov ax,smImageFileHeader.FILEHEADER@@NumberOfSections                   ; move number of sections into ax
	mov bx,size IMAGESECTIONHEADER                                          ; move sizeof(IMAGESECTIONHEADER) to bx        
	mul bx                                                                  ; get byte count for all sections
	mov smLocalSectionHeaderLength,eax                                      ; store size of all sections
	sub esp,smLocalSectionHeaderLength                                      ; make space for sections on stack
	mov smpLocalSectionHeaders,esp                                          ; store starting address
	READFILE smFileHandle,smpLocalSectionHeaders,smLocalSectionHeaderLength ; read sections onto stack
  mov smCodeSections,0000h
	xor ecx,ecx                                                             ; clear ecx
sectionLoop:																															; sectionLoop sync address
  cmp cx,smImageFileHeader.FILEHEADER@@NumberOfSections                   ; did we read all the sections?
	jge sectionLoopEnd                                                       ; is yes, then we're done here
	GETSECTION ecx                                                          ; get section indexed by ecx
	ISCODE smpImageSection
	sectionIsCode smpImageSectionHeader
	jz @@NotCode
	inc smCodeSections
@@NotCode:
  inc cx                                                                  ; advance ecx
	jmp sectionLoop                    																			; keep reading sections
sectionLoopEnd:                                                           ; section loop end sync address
	add esp,smLocalSectionHeaderLength                                      ; restore sections from stack
	jmp @@End
@@Fail:                                                                   ; failure sync address  
  CLOSEHANDLE smFileHandle                                                ; close the file 
	mov smFileHandle,INVALID_HANDLE
	jmp @@Done                                                              ; jump to exit code
@@End:                                                                    ; end sync address
  CLOSEHANDLE smFileHandle                                                ; close the file
	mov smFileHandle,INVALID_HANDLE
@@Done:                                                                   ; we're all done here
  popad                                                                   ; restore all general purpose regs
	mov eax,smCodeSections
  pop ebp                                                                 ; restore previous stack frame
  retn                                                                    ; return near to caller
_getPECodeSectionCount endp



void PureBitmap::upsideDown(WORD width,WORD height,GlobalData<BYTE> &bitmapBits)const
{
  HGLOBAL hGlobalTemp=::GlobalAlloc(GMEM_FIXED,width*height);
	BYTE *lpDst;
	BYTE *lpSrc;

	lpDst=(BYTE*)::GlobalLock(hGlobalTemp);
	lpSrc=(BYTE*)&bitmapBits[0];
	for(LONG rowIndex=0;rowIndex<height;rowIndex++)
	  ::memcpy(lpDst+(rowIndex*width),(lpSrc+(height-rowIndex)*width)-width,width);
	::memcpy(lpSrc,lpDst,width*height);
	::GlobalUnlock(hGlobalTemp);
	::GlobalFree(hGlobalTemp);
}


DWORD PureBitmap::bitmapBits(WORD &scanWidth,WORD &scanHeight,GlobalData<BYTE> &bitmapBytes,BOOL bottomUp)const
{
	PurePalette systemPalette;
  PureDevice pureDevice;
	BitmapInfo bmInfo;
  DWORD scanLines(0);
	DWORD scanLineWidth;

  if(!isOkay())return scanLines;
	scanLineWidth=width();
	if(scanLineWidth%2L)scanLineWidth++;
	scanWidth=scanLineWidth;
  scanHeight=height();
	bitmapBytes.size(scanLineWidth*(DWORD)height()*(mBitmap.bmBitsPixel/8));
	systemPalette.systemPalette();
	bmInfo.width(width());
	bmInfo.height(height());
	bmInfo.bitCount(bitsPerPixel());
	bmInfo=systemPalette;
	pureDevice.displayDevice();
  scanLines=::GetDIBits(pureDevice,*this,0,bottomUp?height():int(height())*-1,(BYTE*)&bitmapBytes[0],(BITMAPINFO*)bmInfo,DIB_RGB_COLORS);  // bottomUp?int(height())*-1:height()
  return scanLines;
}


//  DWORD bitmapBits(WORD &scanWidth,WORD &scanHeight,GlobalData<BYTE> &bitmapBytes,BOOL bottomUp=FALSE)const;



#if 0
void OwnerDrawListCheck::drawEntire(const DrawItem &drawItem)
{
	PureDevice pureDevice(drawItem.deviceContext());
	PureDevice memDevice;
	String stringData;
	TEXTMETRIC textMetric;
	Rect drawRect;

	if(!isOkay())return;
  stringData.reserve(256);
	drawRect=drawItem.rectItem();
	memDevice.compatibleDevice(pureDevice);
	PureBitmap &pureBitmap=(((UINT)drawItem.itemState())&ODS_SELECTED?mPureBitmaps[BmSel]:mPureBitmaps[BmUnSel]);
	sendMessage(drawItem.hwndItem(),LB_GETTEXT,drawItem.itemID(),(LPARAM)(LPSTR)stringData);
  if(stringData.isNull())::MessageBeep(0);
	::GetTextMetrics(drawItem.deviceContext(),&textMetric);
	if(drawItem.itemState()&ODS_DISABLED)
	{
	  ::GrayString(drawItem.deviceContext(),(HBRUSH)(GDIObj)mDisabledBrush,(GRAYSTRINGPROC)0,(LPARAM)(LPSTR)stringData,stringData.length(),pureBitmap.width()+6,(drawRect.bottom()+drawRect.top()-textMetric.tmHeight)/2,0,0);
//	  ::GrayString(drawItem.deviceContext(),(HBRUSH)(GDIObj)mGrayBrush,(GRAYSTRINGPROC)0,(LPARAM)(LPSTR)stringData,stringData.length(),pureBitmap.width()+6,(drawRect.bottom()+drawRect.top()-textMetric.tmHeight)/2,0,0);
	  memDevice.select(pureBitmap,TRUE);
	  pureDevice.bitBlt(drawRect,memDevice,Point(0,0),PureDevice::MergeCopy);
		memDevice.select(pureBitmap,FALSE);
	}
	else 
	{
	  ::TextOut(drawItem.deviceContext(),pureBitmap.width()+6,(drawRect.bottom()+drawRect.top()-textMetric.tmHeight)/2,(LPSTR)stringData,stringData.length());
	  memDevice.select(pureBitmap,TRUE);
	  pureDevice.bitBlt(drawRect,memDevice,Point(0,0));
	  memDevice.select(pureBitmap,FALSE);
	}
  if((((UINT)drawItem.itemState())&ODS_FOCUS))
	{
		Rect bmpRect(drawRect);
		bmpRect.right(bmpRect.left()+pureBitmap.width());
		bmpRect.bottom(bmpRect.top()+pureBitmap.height());
		::DrawFocusRect(drawItem.deviceContext(),(RECT*)&bmpRect);
	}
}
#endif



#if 0
int RichEditControl::getCaretPosition(void)const
{
  int charPos;
	int row;
	int col;

  if(!isValid())return 0;
	charPos=HIWORD(sendMessage(EM_GETSEL,0,0L));
	row=sendMessage(EM_LINEFROMCHAR,(WPARAM)charPos,0L)+1;
	col=(charPos-lineIndex())+1;
	return MAKELPARAM(row,col);
}
#endif





	if(!versionInfo.isWinNT())
	{
    for(long index=0;index<ansiLength;index++)operator[](index)=((char*)((String&)ansiString))[index];
    operator[](index)=0;
	}
	else MultiByteToWideChar(CP_ACP,MB_PRECOMPOSED,(LPSTR)(String&)ansiString,ansiLength,(LPWSTR)&operator[](0),size());



void WideString::ansiToWideString(const String &ansiString)
{
  VersionInfo versionInfo;

  if(ansiString.isNull())return;
	WORD ansiLength(ansiString.length());
	size(ansiLength+1);

	if(!versionInfo.isWinNT())
	{
    for(long index=0;index<ansiLength;index++)operator[](index)=((char*)((String&)ansiString))[index];
    operator[](index)=0;
	}
	else MultiByteToWideChar(CP_ACP,MB_PRECOMPOSED,(LPSTR)(String&)ansiString,ansiLength,(LPWSTR)&operator[](0),size());
}




//	operator PureDevice &(void);
//  operator PurePalette &(void);


//inline
//DIBitmap::operator PureDevice &(void)
//{
//	return mBitmapDevice;
//}

//inline
//DIBitmap::operator PurePalette &(void)
//{
//  return mBitmapPalette;
//}


void BitmapInfo::rgbColors(DWORD rgbColors)
{
	BitmapInfo bitmapInfo(*this);

	createInfo(rgbColors);
	planes(bitmapInfo.planes());
	width(bitmapInfo.width());
	height(bitmapInfo.height());
	bitCount(bitmapInfo.bitCount());
	compression(bitmapInfo.compression());
	sizeImage(bitmapInfo.sizeImage());
	xPelsPerMeter(bitmapInfo.xPelsPerMeter());
	yPelsPerMeter(bitmapInfo.yPelsPerMeter());
	colorUsed(rgbColors);
	colorImportant(rgbColors);
//	colorUsed(bitmapInfo.colorUsed());
//  colorImportant(bitmapInfo.colorImportant());
}



	DWORD read(char *lpBuffer,WORD lengthData);
  DWORD read(BYTE *lpBuffer,WORD lengthData);
DWORD File::read(char *lpBuffer,WORD lengthData)
{
  return read((void*)lpBuffer,lengthData);
}

DWORD File::read(BYTE *lpBuffer,WORD lengthData)
{
  return read((void*)lpBuffer,lengthData);
}




#ifndef _COMMON_WINDOWS_HPP_
#define _COMMON_WINDOWS_HPP_
#define WIN32_LEAN_AND_MEAN
#define NOSERVICE
#define NOKANJI
#define NOCRYPT
#define NOMCX
#define NOLSTRING
#define NODBCS
#define NOMETAFILE
#define NOPROFILER
#define NOLANGUAGE
#define NOLOGERROR
#define NOMCX
#define NOIME
#define NOCOMM

//#ifndef _COMMON_USENLS_
//#define NONLS
//#endif

#include <windows.h>
typedef unsigned short USHORT;
#ifndef DS_3DLOOK
#define DS_3DLOOK 0x0004L
#endif
#ifndef PFD_GENERIC_ACCELERATED
#define PFD_GENERIC_ACCELERATED     0x00001000
#endif
#ifndef PFD_SWAP_LAYER_BUFFERS
#define PFD_SWAP_LAYER_BUFFERS      0x00000800
#endif
#ifndef PFD_DEPTH_DONTCARE
#define PFD_DEPTH_DONTCARE          0x20000000
#endif
#ifndef EN_MSGFILTER
#define EN_MSGFILTER 0x0700
#endif
#ifndef EN_REQUESTRESIZE
#define EN_REQUESTRESIZE 0x0701
#endif
#ifndef EN_SELCHANGE
#define EN_SELCHANGE 0x0702
#endif
#ifndef EN_DROPFILES
#define EN_DROPFILES 0x0703
#endif
#ifndef EN_PROTECTED
#define EN_PROTECTED 0x0704
#endif
#endif
#ifndef IMAGE_DIRECTORY_ENTRY_COPYRIGHT
#define IMAGE_DIRECTORY_ENTRY_COPYRIGHT IMAGE_DIRECTORY_ENTRY_ARCHITECTURE
#endif




#if 0
inline
String::operator int(void)const
{
	if(!mnpStr)return 0;
  return ::atoi(mnpStr);
}

inline
String::operator short(void)const
{
	if(!mnpStr)return 0;
  return ::atoi(mnpStr);
}

inline
String::operator float(void)const
{
	if(!mnpStr)return 0.00;
  return ::atof(mnpStr);
}

inline
String::operator long(void)const
{
	if(!mnpStr)return 0L;
	return ::atol(mnpStr);
}
#endif


//	operator int(void)const;
//	operator short(void)const;
//	operator float(void)const;
//	operator long(void)const;



//inline
//FileTime::operator FILETIME &(void)
//{
//	return *this;
//}


	operator SYSTEMTIME &(void);
	operator String(void);



inline
SystemTime::operator SYSTEMTIME &(void)
{
	return *this;
}


SystemTime::operator String(void)
{
  return toString();
}




WORD Bitmap::saveBitmap(void)
{
	BITMAPFILEHEADER bitmapFileHeader;
	OFSTRUCT ofStruct;

	if(!isOkay())return FALSE;
	if((HFILE_ERROR==mhFile)&&(HFILE_ERROR==(mhFile=::OpenFile(mFileName,&ofStruct,OF_WRITE|OF_CREATE))))return FALSE;
	::memset(&bitmapFileHeader,0,sizeof(BITMAPFILEHEADER));
	bitmapFileHeader.bfType=Signature;
//	bitmapFileHeader.bfSize=sizeof(BITMAPFILEHEADER)+sizeof(BITMAPINFOHEADER)+(sizeof(RGBQUAD)*mMaxColors)+mImageExtent;
//	bitmapFileHeader.bfOffBits=sizeof(BITMAPFILEHEADER)+sizeof(BITMAPINFOHEADER)+(sizeof(RGBQUAD)*mMaxColors);
//	::_lwrite(mhFile,(char*)&bitmapFileHeader,sizeof(BITMAPFILEHEADER));
//	::_lwrite(mhFile,(char*)getInfoPtr(),sizeof(BITMAPINFOHEADER)+(sizeof(RGBQUAD)*mMaxColors));
//	::_hwrite(mhFile,(char*)getDataPtr(),mImageExtent);
	bitmapFileHeader.bfSize=sizeof(BITMAPFILEHEADER)+sizeof(BITMAPINFOHEADER)+sizeof(RGBQUAD)+(sizeof(RGBQUAD)*(mMaxColors-1))+mImageExtent;
	bitmapFileHeader.bfOffBits=sizeof(BITMAPFILEHEADER)+sizeof(BITMAPINFOHEADER)+sizeof(RGBQUAD)+(sizeof(RGBQUAD)*(mMaxColors-1));
	::_lwrite(mhFile,(char*)&bitmapFileHeader,sizeof(BITMAPFILEHEADER));
	::_lwrite(mhFile,(char*)getInfoPtr(),sizeof(BITMAPINFOHEADER)+sizeof(RGBQUAD)+(sizeof(RGBQUAD)*(mMaxColors-1)));
	::_hwrite(mhFile,(char*)getDataPtr(),mImageExtent);


	closeFile();
	return FALSE;
}



WORD RegKey::setValue(const String &valueName,const String &stringData)
{
	DWORD resData(0);
  long keyReturn;

//  if(!isOkay()||stringData.isNull()||valueName.isNull())return FALSE;
//	keyReturn=::RegSetValueEx((HKEY)*this,valueName.isNull()?0:(LPSTR)valueName,resData,REG_SZ,(const unsigned char*)(LPSTR)stringData,stringData.length()+1);
  if(!isOkay()||valueName.isNull())return FALSE;
	if(stringData.isNull())keyReturn=::RegSetValueEx((HKEY)*this,valueName.isNull()?0:(LPSTR)valueName,resData,REG_SZ,0,0);
	else keyReturn=::RegSetValueEx((HKEY)*this,valueName.isNull()?0:(LPSTR)valueName,resData,REG_SZ,(const unsigned char*)(LPSTR)stringData,stringData.length()+1);
	return ERROR_SUCCESS==keyReturn;
}


/*
DWORD MemFile::read(char *lpBuffer,WORD lengthData)
{
	BYTE byteValue;

	if(!isOkay())return FALSE;
	for(WORD index=0;index<lengthData;index++)
	{
		if(!read(byteValue))return FALSE;
    *(lpBuffer++)=byteValue;
	}
  return TRUE;
}
*/



/*
WORD MemFile::read(char *lpBuffer,DWORD lengthData,int stopChar)
{
	BYTE tempChar;
	int bytesRead;

  bytesRead=0;
	for(;bytesRead<lengthData-1;bytesRead++)
	{
		if(!read(tempChar))return FALSE;
		if(tempChar==stopChar)break;
		*(lpBuffer++)=tempChar;
	}
  *(lpBuffer)=0;
  if(!bytesRead)return FALSE;
	return TRUE;
}
*/



  bool createBitmap(BitmapInfo &bmInfo);





bool Bitmap::createBitmap(BitmapInfo &bmInfo)
{
	mMaxColors=0;
	mCurrentMode=Write;
	mImageExtent=0;
	mWidth=0;
	mHeight=0;
	UHUGE *lpPtr;
	WORD bmWidth;
	WORD bmHeight;

  closeFile();
  bmWidth=bmInfo.width();
	bmHeight=bmInfo.height();
	getRequiredWidth(bmWidth,bmHeight);
	bmInfo.width(bmWidth);
	bmInfo.height(bmHeight);
	mFileName="";
  reserveInfo(0,bmInfo.rgbColors());
  copyBits((UHUGE*)getInfoPtr(),(UHUGE*)(BITMAPINFOHEADER*)((BitmapInfo&)bmInfo),sizeof(BITMAPINFOHEADER));
	if(!(mMaxColors=(WORD)getInfoPtr()->bmiHeader.biClrUsed))mMaxColors=1<<getInfoPtr()->bmiHeader.biBitCount;
	for(int itemIndex=0;itemIndex<bmInfo.rgbColors();itemIndex++)
	{
    getInfoPtr()->bmiColors[itemIndex]=bmInfo[itemIndex].getRGBQUAD();
	}
  mImageExtent=imageExtent();
	lpPtr=reserveData(mImageExtent);
	setBits(lpPtr,0,mImageExtent);
	mWidth=getInfoPtr()->bmiHeader.biWidth;
	mHeight=getInfoPtr()->bmiHeader.biHeight;
	setPalette();
	return true;
}



int GUIWindow::messageLoop(void)const
{
	bool isDialogMessage;
  MSG msg;

	while(::GetMessage(&msg,NULL,0,0))
	{
	  isDialogMessage=false;
	  for(int mindex=0;mindex<mModelessDialogs.size()&&!isDialogMessage;mindex++)
		if(::IsDialogMessage(*((((GUIWindow&)*this).mModelessDialogs)[mindex]),&msg))isDialogMessage=true;
		if(isDialogMessage)continue;


//	  if(!TranslateMDISysAccel(msg.hwnd,&msg)&&(mAccelerator.isOkay()&&!mAccelerator.translate(*this,msg)))								
//		{
      ::TranslateMessage(&msg);
      ::DispatchMessage(&msg);
//		}
//		else
//		{
//      ::TranslateMessage(&msg);
//      ::DispatchMessage(&msg);
//		}
	}
	return msg.wParam;
}




/*
void FrameWindow::yieldTask(void)const
{
}

int FrameWindow::messageLoop(void)const
{
}




MSG msg;
BOOL bRet;

while ((bRet = GetMessage(&msg, (HWND) NULL, 0, 0)) != 0)
{
    if (bRet == -1)
    {
        // handle the error and possibly exit
    }
    else 
    { 
        if (!TranslateMDISysAccel(hwndMDIClient, &msg) && 
                !TranslateAccelerator(hwndFrame, hAccel, &msg))
        { 
            TranslateMessage(&msg); 
            DispatchMessage(&msg); 
        } 
    } 
}




*/


/*		if(!mAccelerator.isOkay()||(mAccelerator.isOkay()&&!mAccelerator.translate(*this,msg)))
		{
      ::TranslateMessage(&msg);
      ::DispatchMessage(&msg);
		}
		else 
		{
		  ::DispatchMessage(&msg);
		} */



bool Profile::removeExtension(String &strPathFileName)const
{
	char *ptr;

  if(strPathFileName.isNull())return false;
	ptr=strPathFileName.str()+(strPathFileName.length()-1);
	while(*ptr!='.'&&ptr>=strPathFileName.str())ptr--;
	if(*ptr=='.')*ptr=0;
	return true;
}







#include <common/mdifrm.hpp>
#include <common/mdiwin.hpp>
#include <common/instance.hpp>
#include <common/dde.hpp>
#include <common/mmsystem.hpp>
#include <common/string.hpp>
#include <common/rect.hpp>

FrameWindow::FrameWindow(void)
//: mFirstNextIndex(0)
{
  mDestroyHandler.setCallback(this,&FrameWindow::destroyHandler);
	mMDIActivateHandler.setCallback(this,&FrameWindow::mdiActivateHandler);
	mCommandHandler.setCallback(this,&FrameWindow::commandHandler);
	insertHandler(VectorHandler::MDIActivateHandler,&mMDIActivateHandler);
	insertHandler(VectorHandler::CommandHandler,&mCommandHandler);
}

FrameWindow::FrameWindow(const FrameWindow &frameWindow)
//: mFirstNextIndex(0)
{ // private implementation
  *this=frameWindow;
	mDestroyHandler.setCallback(this,&FrameWindow::destroyHandler);
	mMDIActivateHandler.setCallback(this,&FrameWindow::mdiActivateHandler);
	mCommandHandler.setCallback(this,&FrameWindow::commandHandler);
	insertHandler(VectorHandler::MDIActivateHandler,&mMDIActivateHandler);
	insertHandler(VectorHandler::CommandHandler,&mCommandHandler);
}

FrameWindow::~FrameWindow()
{
  removeHandler(VectorHandler::MDIActivateHandler,&mMDIActivateHandler);
	removeHandler(VectorHandler::CommandHandler,&mCommandHandler);
}

FrameWindow &FrameWindow::operator=(const FrameWindow &/*frameWindow*/)
{ // private implentation
  return *this;
}

void FrameWindow::createWindow(const String &className,const String &windowName,const String &menuName,const String &iconName)
{
  HINSTANCE hInstance(processInstance());
	mFrameMenu=menuName;
  registerClass(hInstance,className,iconName);
	GUIWindow::createWindow(className,windowName,WS_OVERLAPPEDWINDOW|WS_CLIPCHILDREN,Rect(CW_USEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT),0,mFrameMenu,hInstance,(LPSTR)this);
	show(SW_SHOW);
	update();
}

void FrameWindow::registerClass(HINSTANCE hInstance,const String &className,const String &iconName)
{
  WNDCLASS wndClass;

  if(::GetClassInfo(hInstance,(char*)(String&)className,&wndClass))return;
  wndClass.style         =CS_HREDRAW|CS_VREDRAW;
  wndClass.lpfnWndProc   =(WNDPROC)FrameWindow::FrameProc;
  wndClass.cbClsExtra    =0;
  wndClass.cbWndExtra    =sizeof(FrameWindow*);
  wndClass.hInstance     =hInstance;
  wndClass.hIcon         =::LoadIcon(hInstance,iconName);
  wndClass.hCursor       =::LoadCursor(NULL,IDC_ARROW);
  wndClass.hbrBackground =(HBRUSH)(COLOR_WINDOWFRAME);
  wndClass.lpszMenuName  =0;
  wndClass.lpszClassName =(char*)(String&)className;
	preRegister(wndClass);
  ::RegisterClass(&wndClass);
}

void FrameWindow::createMDIClientWindow(void)
{
  CLIENTCREATESTRUCT clientCreate;
	PureMenu subMenu;

  clientCreate.hWindowMenu=(HMENU)subMenu;
  clientCreate.idFirstChild=IDFirstMDIChild;
	mClientWnd.createWindow("MDICLIENT",String(),WS_CHILD|WS_CLIPCHILDREN|WS_VISIBLE|MDIS_ALLCHILDSTYLES,Rect(0,0,0,0),*this,(HMENU)0,processInstance(),(CLIENTCREATESTRUCT *)&clientCreate);
}

void FrameWindow::insert(MDIWindow &mdiWindow)
{
  mDocuments.insert(&SmartPointer<MDIWindow>(&mdiWindow));
	mDocuments[mDocuments.size()-1].disposition(PointerDisposition::Delete);
	mDocuments[mDocuments.size()-1]->insertHandler(VectorHandler::DestroyHandler,&mDestroyHandler);
}

MDIWindow &FrameWindow::operator[](int itemIndex)
{
  return *(mDocuments[itemIndex]);
}

int FrameWindow::size(void)const
{
  return mDocuments.size();
}

int FrameWindow::windowProcedure(HWND hWnd,WORD message,WPARAM wParam,LPARAM lParam)
{
  watchDocumentWindows();
  if(message>=WM_USER&&message<=0x7FFF)
	{
    if(!installedHandlers(VectorHandler::UserHandler))return ::DefWindowProc(hWnd,message,wParam,lParam);
		return callHandlers(VectorHandler::UserHandler,CallbackData(message,lParam,hWnd));
	}
	switch(message)
	{
    case WM_CLOSE :
			if(!installedHandlers(VectorHandler::CloseHandler))return ::DefFrameProc(hWnd,mClientWnd,message,wParam,lParam);
			return callHandlers(VectorHandler::CloseHandler,CallbackData(wParam,lParam,hWnd));
		case WM_NCCREATE :
			if(!installedHandlers(VectorHandler::NCCreateHandler))return ::DefFrameProc(hWnd,mClientWnd,message,wParam,lParam);
			return callHandlers(VectorHandler::NCCreateHandler,CallbackData(wParam,lParam,hWnd));
		case WM_CHANGECBCHAIN :
			if(!installedHandlers(VectorHandler::ChangeCBChainHandler))return ::DefFrameProc(hWnd,mClientWnd,message,wParam,lParam);
			return callHandlers(VectorHandler::ChangeCBChainHandler,CallbackData(wParam,lParam,hWnd));
		case WM_DRAWCLIPBOARD :
			if(!installedHandlers(VectorHandler::DrawClipboardHandler))return ::DefFrameProc(hWnd,mClientWnd,message,wParam,lParam);
			return callHandlers(VectorHandler::DrawClipboardHandler,CallbackData(wParam,lParam,hWnd));
		case WM_CREATE :
		  createMDIClientWindow();
			if(!installedHandlers(VectorHandler::CreateHandler))return ::DefFrameProc(hWnd,mClientWnd,message,wParam,lParam);
			return callHandlers(VectorHandler::CreateHandler,CallbackData(wParam,lParam,hWnd));
		case WM_PAINT :
			if(!installedHandlers(VectorHandler::PaintHandler))return ::DefFrameProc(hWnd,mClientWnd,message,wParam,lParam);
			return handlePaintMessage(hWnd,message,wParam,lParam);
		case WM_ERASEBKGND :
		  if(!installedHandlers(VectorHandler::EraseBackgroundHandler))return ::DefFrameProc(hWnd,mClientWnd,message,wParam,lParam);
			return callHandlers(VectorHandler::EraseBackgroundHandler,CallbackData(wParam,lParam,hWnd));
		case WM_PALETTECHANGED :
		  if(!installedHandlers(VectorHandler::PaletteChangedHandler))return ::DefFrameProc(hWnd,mClientWnd,message,wParam,lParam);
			return callHandlers(VectorHandler::PaletteChangedHandler,CallbackData(wParam,lParam,hWnd));
		case WM_DRAWITEM :
			if(!installedHandlers(VectorHandler::DrawItemHandler))return ::DefFrameProc(hWnd,mClientWnd,message,wParam,lParam);
			return callHandlers(VectorHandler::DrawItemHandler,CallbackData(wParam,lParam,hWnd));
		case WM_TIMER :
			if(!installedHandlers(VectorHandler::TimerHandler))return ::DefFrameProc(hWnd,mClientWnd,message,wParam,lParam);
			return callHandlers(VectorHandler::TimerHandler,CallbackData(wParam,lParam,hWnd));
		case WM_CHAR :
			if(!installedHandlers(VectorHandler::CharHandler))return ::DefFrameProc(hWnd,mClientWnd,message,wParam,lParam);
			return callHandlers(VectorHandler::CharHandler,CallbackData(wParam,lParam,hWnd));
		case WM_COMMAND :
			if(!installedHandlers(VectorHandler::CommandHandler))return ::DefFrameProc(hWnd,mClientWnd,message,wParam,lParam);
			callHandlers(VectorHandler::CommandHandler,CallbackData(wParam,lParam,hWnd));
			return ::DefFrameProc(hWnd,mClientWnd,message,wParam,lParam);
		case WM_COMPACTING :
			if(!installedHandlers(VectorHandler::CompactingHandler))return ::DefFrameProc(hWnd,mClientWnd,message,wParam,lParam);
			return callHandlers(VectorHandler::CompactingHandler,CallbackData(wParam,lParam,hWnd));
		case WM_WININICHANGE :
			if(!installedHandlers(VectorHandler::WinIniChangeHandler))return ::DefFrameProc(hWnd,mClientWnd,message,wParam,lParam);
			return callHandlers(VectorHandler::WinIniChangeHandler,CallbackData(wParam,lParam,hWnd));
		case WM_SYSCOLORCHANGE :
			if(!installedHandlers(VectorHandler::SysColorChangeHandler))return ::DefFrameProc(hWnd,mClientWnd,message,wParam,lParam);
			return callHandlers(VectorHandler::SysColorChangeHandler,CallbackData(wParam,lParam,hWnd));
		case WM_CTLCOLOR :
			if(!installedHandlers(VectorHandler::ControlColorHandler))return ::DefFrameProc(hWnd,mClientWnd,message,wParam,lParam);
			return callHandlers(VectorHandler::ControlColorHandler,CallbackData(wParam,lParam,hWnd));
		case WM_CTLCOLORMSGBOX :
			if(!installedHandlers(VectorHandler::ControlColorHandler))return ::DefFrameProc(hWnd,mClientWnd,message,wParam,lParam);
			return callHandlers(VectorHandler::ControlColorHandler,CallbackData(wParam,lParam,hWnd));
		case WM_CTLCOLOREDIT :
			if(!installedHandlers(VectorHandler::ControlColorHandler))return ::DefFrameProc(hWnd,mClientWnd,message,wParam,lParam);
			return callHandlers(VectorHandler::ControlColorHandler,CallbackData(wParam,lParam,hWnd));
		case WM_CTLCOLORLISTBOX :
			if(!installedHandlers(VectorHandler::ControlColorHandler))return ::DefFrameProc(hWnd,mClientWnd,message,wParam,lParam);
			return callHandlers(VectorHandler::ControlColorHandler,CallbackData(wParam,lParam,hWnd));
		case WM_CTLCOLORBTN :
			if(!installedHandlers(VectorHandler::ControlColorHandler))return ::DefFrameProc(hWnd,mClientWnd,message,wParam,lParam);
			return callHandlers(VectorHandler::ControlColorHandler,CallbackData(wParam,lParam,hWnd));
		case WM_CTLCOLORDLG :
			if(!installedHandlers(VectorHandler::ControlColorHandler))return ::DefFrameProc(hWnd,mClientWnd,message,wParam,lParam);
			return callHandlers(VectorHandler::ControlColorHandler,CallbackData(wParam,lParam,hWnd));
		case WM_CTLCOLORSCROLLBAR :
			if(!installedHandlers(VectorHandler::ControlColorHandler))return ::DefFrameProc(hWnd,mClientWnd,message,wParam,lParam);
			return callHandlers(VectorHandler::ControlColorHandler,CallbackData(wParam,lParam,hWnd));
		case WM_CTLCOLORSTATIC :
			if(!installedHandlers(VectorHandler::ControlColorHandler))return ::DefFrameProc(hWnd,mClientWnd,message,wParam,lParam);
			return callHandlers(VectorHandler::ControlColorHandler,CallbackData(wParam,lParam,hWnd));
		case WM_DDE_INITIATE :
			if(!installedHandlers(VectorHandler::DDEInitiateHandler))return ::DefFrameProc(hWnd,mClientWnd,message,wParam,lParam);
			return callHandlers(VectorHandler::DDEInitiateHandler,CallbackData(wParam,lParam,hWnd));
		case WM_DDE_ACK :
			if(!installedHandlers(VectorHandler::DDEAckHandler))return ::DefFrameProc(hWnd,mClientWnd,message,wParam,lParam);
			return callHandlers(VectorHandler::DDEAckHandler,CallbackData(wParam,lParam,hWnd));
		case WM_DDE_REQUEST :
			if(!installedHandlers(VectorHandler::DDERequestHandler))return ::DefFrameProc(hWnd,mClientWnd,message,wParam,lParam);
			return callHandlers(VectorHandler::DDERequestHandler,CallbackData(wParam,lParam,hWnd));
		case WM_DDE_TERMINATE :
			if(!installedHandlers(VectorHandler::DDETerminateHandler))return ::DefFrameProc(hWnd,mClientWnd,message,wParam,lParam);
			return callHandlers(VectorHandler::DDETerminateHandler,CallbackData(wParam,lParam,hWnd));
		case WM_DDE_DATA :
			if(!installedHandlers(VectorHandler::DDEDataHandler))return ::DefFrameProc(hWnd,mClientWnd,message,wParam,lParam);
			return callHandlers(VectorHandler::DDEDataHandler,CallbackData(wParam,lParam,hWnd));
		case MM_WOM_OPEN :
			if(!installedHandlers(VectorHandler::MMOpenHandler))return ::DefFrameProc(hWnd,mClientWnd,message,wParam,lParam);
			return callHandlers(VectorHandler::MMOpenHandler,CallbackData(wParam,lParam,hWnd));
		case MM_WOM_CLOSE :
			if(!installedHandlers(VectorHandler::MMCloseHandler))return ::DefFrameProc(hWnd,mClientWnd,message,wParam,lParam);
			return callHandlers(VectorHandler::MMCloseHandler,CallbackData(wParam,lParam,hWnd));
		case MM_WOM_DONE :
			if(!installedHandlers(VectorHandler::MMDoneHandler))return ::DefFrameProc(hWnd,mClientWnd,message,wParam,lParam);
			return callHandlers(VectorHandler::MMDoneHandler,CallbackData(wParam,lParam,hWnd));
		case WM_LBUTTONDBLCLK :
			if(!installedHandlers(VectorHandler::LeftButtonDoubleHandler))return ::DefFrameProc(hWnd,mClientWnd,message,wParam,lParam);
			return callHandlers(VectorHandler::LeftButtonDoubleHandler,CallbackData(wParam,lParam,hWnd));
		case WM_LBUTTONDOWN :
			if(!installedHandlers(VectorHandler::LeftButtonDownHandler))return ::DefFrameProc(hWnd,mClientWnd,message,wParam,lParam);
			return callHandlers(VectorHandler::LeftButtonDownHandler,CallbackData(wParam,lParam,hWnd));
		case WM_LBUTTONUP :
			if(!installedHandlers(VectorHandler::LeftButtonUpHandler))return ::DefFrameProc(hWnd,mClientWnd,message,wParam,lParam);
			return callHandlers(VectorHandler::LeftButtonUpHandler,CallbackData(wParam,lParam,hWnd));
		case WM_RBUTTONDBLCLK :
			if(!installedHandlers(VectorHandler::RightButtonDoubleHandler))return ::DefFrameProc(hWnd,mClientWnd,message,wParam,lParam);
			return callHandlers(VectorHandler::RightButtonDoubleHandler,CallbackData(wParam,lParam,hWnd));
		case WM_RBUTTONDOWN :
			if(!installedHandlers(VectorHandler::RightButtonDownHandler))return ::DefFrameProc(hWnd,mClientWnd,message,wParam,lParam);
			return callHandlers(VectorHandler::RightButtonDownHandler,CallbackData(wParam,lParam,hWnd));
		case WM_RBUTTONUP :
			if(!installedHandlers(VectorHandler::RightButtonUpHandler))return ::DefFrameProc(hWnd,mClientWnd,message,wParam,lParam);
			return callHandlers(VectorHandler::RightButtonUpHandler,CallbackData(wParam,lParam,hWnd));
		case WM_NCLBUTTONUP :
			if(!installedHandlers(VectorHandler::NCLeftButtonUpHandler))return ::DefFrameProc(hWnd,mClientWnd,message,wParam,lParam);
			return callHandlers(VectorHandler::NCLeftButtonUpHandler,CallbackData(wParam,lParam,hWnd));
		case WM_NCLBUTTONDOWN :
			if(!installedHandlers(VectorHandler::NCLeftButtonDownHandler))return ::DefFrameProc(hWnd,mClientWnd,message,wParam,lParam);
			return callHandlers(VectorHandler::NCLeftButtonDownHandler,CallbackData(wParam,lParam,hWnd));
		case WM_NCRBUTTONUP :
			if(!installedHandlers(VectorHandler::NCRightButtonUpHandler))return ::DefFrameProc(hWnd,mClientWnd,message,wParam,lParam);
			return callHandlers(VectorHandler::NCRightButtonUpHandler,CallbackData(wParam,lParam,hWnd));
		case WM_NCRBUTTONDOWN :
			if(!installedHandlers(VectorHandler::NCRightButtonDownHandler))return ::DefFrameProc(hWnd,mClientWnd,message,wParam,lParam);
			return callHandlers(VectorHandler::NCRightButtonDownHandler,CallbackData(wParam,lParam,hWnd));
		case WM_MOUSEMOVE :
			if(!installedHandlers(VectorHandler::MouseMoveHandler))return ::DefFrameProc(hWnd,mClientWnd,message,wParam,lParam);
			return callHandlers(VectorHandler::MouseMoveHandler,CallbackData(wParam,lParam,hWnd));
		case WM_SETFOCUS :
			if(!installedHandlers(VectorHandler::SetFocusHandler))return ::DefFrameProc(hWnd,mClientWnd,message,wParam,lParam);
			return callHandlers(VectorHandler::SetFocusHandler,CallbackData(wParam,lParam,hWnd));
		case WM_SETFONT :
			if(!installedHandlers(VectorHandler::SetFontHandler))return ::DefFrameProc(hWnd,mClientWnd,message,wParam,lParam);
			return callHandlers(VectorHandler::SetFontHandler,CallbackData(wParam,lParam,hWnd));
		case WM_KILLFOCUS :
			if(!installedHandlers(VectorHandler::KillFocusHandler))return ::DefFrameProc(hWnd,mClientWnd,message,wParam,lParam);
			return callHandlers(VectorHandler::KillFocusHandler,CallbackData(wParam,lParam,hWnd));
		case WM_KEYUP :
			if(!installedHandlers(VectorHandler::KeyUpHandler))return ::DefFrameProc(hWnd,mClientWnd,message,wParam,lParam);
			return callHandlers(VectorHandler::KeyUpHandler,CallbackData(wParam,lParam,hWnd));
		case WM_KEYDOWN :
			if(!installedHandlers(VectorHandler::KeyDownHandler))return ::DefFrameProc(hWnd,mClientWnd,message,wParam,lParam);
			return callHandlers(VectorHandler::KeyDownHandler,CallbackData(wParam,lParam,hWnd));
		case WM_GETMINMAXINFO :
			if(!installedHandlers(VectorHandler::MinMaxHandler))return ::DefFrameProc(hWnd,mClientWnd,message,wParam,lParam);
			return callHandlers(VectorHandler::MinMaxHandler,CallbackData(wParam,lParam,hWnd));
		case WM_ENTERIDLE :
			if(!installedHandlers(VectorHandler::EnterIdleHandler))return ::DefFrameProc(hWnd,mClientWnd,message,wParam,lParam);
			return callHandlers(VectorHandler::EnterIdleHandler,CallbackData(wParam,lParam,hWnd));
		case WM_MENUSELECT :
			if(!installedHandlers(VectorHandler::MenuSelectHandler))return ::DefFrameProc(hWnd,mClientWnd,message,wParam,lParam);
			return callHandlers(VectorHandler::MenuSelectHandler,CallbackData(wParam,lParam,hWnd));
		case WM_GETDLGCODE :
			if(!installedHandlers(VectorHandler::DialogCodeHandler))return ::DefFrameProc(hWnd,mClientWnd,message,wParam,lParam);
			return callHandlers(VectorHandler::DialogCodeHandler,CallbackData(wParam,lParam,hWnd));
		case WM_MEASUREITEM :
			if(!installedHandlers(VectorHandler::MeasureItemHandler))return ::DefFrameProc(hWnd,mClientWnd,message,wParam,lParam);
			return callHandlers(VectorHandler::MeasureItemHandler,CallbackData(wParam,lParam,hWnd));
		case WM_VSCROLL :
		  if(!installedHandlers(VectorHandler::VerticalScrollHandler))return ::DefFrameProc(hWnd,mClientWnd,message,wParam,lParam);
			return callHandlers(VectorHandler::VerticalScrollHandler,CallbackData(wParam,lParam,hWnd));
		case WM_HSCROLL :
		  if(!installedHandlers(VectorHandler::HorizontalScrollHandler))return ::DefFrameProc(hWnd,mClientWnd,message,wParam,lParam);
			return callHandlers(VectorHandler::HorizontalScrollHandler,CallbackData(wParam,lParam,hWnd));
#if defined(__FLAT__)
		case WM_NOTIFY :
			if(!installedHandlers(VectorHandler::NotifyHandler))return ::DefFrameProc(hWnd,mClientWnd,message,wParam,lParam);
			return callHandlers(VectorHandler::NotifyHandler,CallbackData(wParam,lParam,hWnd));
#endif
		case WM_SIZE :
			if(!installedHandlers(VectorHandler::SizeHandler))return ::DefFrameProc(hWnd,mClientWnd,message,wParam,lParam);
			return callHandlers(VectorHandler::SizeHandler,CallbackData(wParam,lParam,hWnd));
		case WM_DROPFILES :
		  if(!installedHandlers(VectorHandler::DropFilesHandler))return ::DefFrameProc(hWnd,mClientWnd,message,wParam,lParam);
			return callHandlers(VectorHandler::DropFilesHandler,CallbackData(wParam,lParam,hWnd));
		case WM_DESTROY :
		  if(!installedHandlers(VectorHandler::DestroyHandler))postQuitMessage();
			callHandlers(VectorHandler::DestroyHandler,CallbackData(wParam,lParam,hWnd));
			InstanceData::removeInstanceData(hWnd);
			setHandle(0);
			if(!installedHandlers(VectorHandler::SizeHandler))return ::DefFrameProc(hWnd,mClientWnd,message,wParam,lParam);
			return FALSE;
		case WM_MDIACTIVATE :
		  if(!installedHandlers(VectorHandler::MDIActivateHandler))return ::DefFrameProc(hWnd,mClientWnd,message,wParam,lParam);
			return callHandlers(VectorHandler::MDIActivateHandler,CallbackData(wParam,lParam,hWnd));
		case WM_ACTIVATEAPP :
		  if(!installedHandlers(VectorHandler::ActivateAppHandler))return ::DefFrameProc(hWnd,mClientWnd,message,wParam,lParam);
			return callHandlers(VectorHandler::ActivateAppHandler,CallbackData(wParam,lParam,hWnd));
		case WM_DISPLAYCHANGE :
		  if(!installedHandlers(VectorHandler::DisplayChangeHandler))return ::DefFrameProc(hWnd,mClientWnd,message,wParam,lParam);
			return callHandlers(VectorHandler::DisplayChangeHandler,CallbackData(wParam,lParam,hWnd));
		case WM_SHOWWINDOW :
		  if(!installedHandlers(VectorHandler::ShowWindowHandler))return ::DefFrameProc(hWnd,mClientWnd,message,wParam,lParam);
			return callHandlers(VectorHandler::ShowWindowHandler,CallbackData(wParam,lParam,hWnd));
		case WM_MDIDESTROY :
			return FALSE;
		case WM_NCDESTROY :
		default :
			return ::DefFrameProc(hWnd,mClientWnd,message,wParam,lParam);
	}
}

#if defined(_MSC_VER)
int FAR PASCAL FrameWindow::enumerateProcedure(HWND hWnd,LPARAM lParam)
#else
int FAR PASCAL _export FrameWindow::enumerateProcedure(HWND hWnd,LPARAM lParam)
#endif
{
	if(::GetWindow(hWnd,GW_OWNER))return 1;
	switch(LOWORD(lParam))
	{
	  case MDICloseAll :
      if(!::SendMessage(hWnd,WM_QUERYENDSESSION,0,0L))return 1;
			::SendMessage(::GetParent(hWnd),WM_MDIDESTROY,(WPARAM)hWnd,0L);
			break;
		case MDIRestoreAll :
		  if(::IsIconic(hWnd)||::IsZoomed(hWnd))
			  ::SendMessage(::GetParent(hWnd),WM_MDIRESTORE,(WPARAM)hWnd,0L);
			break;
		case MDIMinimizeAll :
			if(!::IsIconic(hWnd))::ShowWindow(hWnd,SW_SHOWMINNOACTIVE);
			break;
	}
  return 1;
}

void FrameWindow::watchDocumentWindows(void)
{
  WORD size(mDocuments.size());
  for(int itemIndex=0;itemIndex<size;itemIndex++)
	{
	  if(!mDocuments[itemIndex]->isValid())
		{
		  mDocuments.remove(itemIndex);
			size=mDocuments.size();
			itemIndex=-1;
		}
	}
}

bool FrameWindow::getActive(SmartPointer<MDIWindow> &mdiWindow)
{
  HWND hMDIChild(0);

  if(!mClientWnd.isValid())return false;
	if((HWND)0==(hMDIChild=(HWND)mClientWnd.sendMessage(WM_MDIGETACTIVE,0,0L)))return false;
	for(int itemIndex=0;itemIndex<mDocuments.size();itemIndex++)
	  if(hMDIChild==(HWND)*(mDocuments[itemIndex]))return mdiWindow=mDocuments[itemIndex],true;
	return false;
}

bool FrameWindow::getDocument(const String &strWindowName,SmartPointer<MDIWindow> &mdiWindow)
{
  HWND hMDIChild;

  if(!mClientWnd.isValid())return false;
	if((HWND)0==(hMDIChild=mClientWnd.findWindow(strWindowName)))return false;
	for(int itemIndex=0;itemIndex<mDocuments.size();itemIndex++)
	  if(hMDIChild==(HWND)*(mDocuments[itemIndex]))return mdiWindow=mDocuments[itemIndex],true;
  return false;
}

bool FrameWindow::getDocuments(Array<SmartPointer<MDIWindow> > &mdiWindows)
{
  mdiWindows.size(mDocuments.size());
	if(!mdiWindows.size())return false;
	for(int index=0;index<mdiWindows.size();index++)
	  mdiWindows[index]=mDocuments[index];
	return true;
}

bool FrameWindow::getDocumentClass(const String &strClassName,SmartPointer<MDIWindow> &mdiWindow)
{
  Array<SmartPointer<MDIWindow> > mdiWindows;
	if(!getDocuments(mdiWindows))return false;
	for(int index=0;index<mdiWindows.size();index++)
	{
	  if(mdiWindows[index]->className()==strClassName)
		{
		  mdiWindow=mdiWindows[index];
		  return true;
		}
	}
	return false;

//  if(getFirstDocument(mdiWindow))
//	{
//	  if(mdiWindow->className()==strClassName)return true;
//	  while(getNextDocument(mdiWindow))if(mdiWindow->className()==strClassName)return true;
//	}
//	return false;
}

/*
BOOL FrameWindow::getFirstDocument(SmartPointer<MDIWindow> &mdiWindow)
{
  if(!mDocuments.size())return FALSE;
	mdiWindow=mDocuments[mFirstNextIndex=0];
	return TRUE;
}

BOOL FrameWindow::getNextDocument(SmartPointer<MDIWindow> &mdiWindow)
{
  if(!mDocuments.size()||mFirstNextIndex+1>=mDocuments.size())return FALSE;
	mdiWindow=mDocuments[++mFirstNextIndex];
	return TRUE;
}
*/

/*
BOOL FrameWindow::getFirstDocument(SmartPointer<MDIWindow> &mdiWindow)
{
  if(!mDocuments.size())return FALSE;

	SmartPointer<PureDWORD> pFirstNextData;
	if(!mFirstNextStore.getThreadData(pFirstNextData))
	{
	  mFirstNextStore.addThreadData(PureDWORD(0));
    mFirstNextStore.getThreadData(pFirstNextData);
	}
	else pFirstNextData->setValue(0);
	if(pFirstNextData->getValue()>=mDocuments.size())
	{
	  mFirstNextStore.removeThreadData();
	  return false;
	}
	mdiWindow=mDocuments[pFirstNextData->getValue()];
//	mdiWindow=mDocuments[mFirstNextIndex=0];
	return TRUE;
}

BOOL FrameWindow::getNextDocument(SmartPointer<MDIWindow> &mdiWindow)
{
	SmartPointer<PureDWORD> pFirstNextData;

	if(!mFirstNextStore.getThreadData(pFirstNextData))return false;
	if(!mDocuments.size()||pFirstNextData->getValue()+1>=mDocuments.size())
	{
	  mFirstNextStore.removeThreadData();
		return false;
	}
	pFirstNextData->setValue(pFirstNextData->getValue()+1);
	mdiWindow=mDocuments[pFirstNextData->getValue()];
//  if(!mDocuments.size()||mFirstNextIndex+1>=mDocuments.size())return FALSE;
//	mdiWindow=mDocuments[++mFirstNextIndex];
	return TRUE;
}
*/

void FrameWindow::enableMenuItems(UINT menuIndex,UINT itemID,PureMenu::PositionFlags positionFlags,PureMenu::InsertFlags insertFlags)
{
  SmartPointer<MDIWindow> mdiWindow;
	Array<SmartPointer<MDIWindow> > mdiWindows;
  PureMenu subMenu;

	if(!getDocuments(mdiWindows))return;
	getFrameMenu().getSubMenu(menuIndex,subMenu);
  subMenu.enableMenuItem(itemID,positionFlags,insertFlags);
	drawMenuBar();
	for(int index=0;index<mdiWindows.size();index++)
	{
	  mdiWindow=mdiWindows[index];
		mdiWindow->getMenu().getSubMenu(menuIndex,subMenu);
    subMenu.enableMenuItem(itemID,positionFlags,insertFlags);
		mdiWindow->drawMenuBar();
	}

//	if(getFirstDocument(mdiWindow))
//	{
//		mdiWindow->getMenu().getSubMenu(menuIndex,subMenu);
//   subMenu.enableMenuItem(itemID,positionFlags,insertFlags);
//		mdiWindow->drawMenuBar();
//		while(getNextDocument(mdiWindow))
//		{
//	    mdiWindow->getMenu().getSubMenu(menuIndex,subMenu);
//     subMenu.enableMenuItem(itemID,positionFlags,insertFlags);
//		  mdiWindow->drawMenuBar();
//		}
//	}
}

CallbackData::ReturnType FrameWindow::destroyHandler(CallbackData &someCallbackData)
{
	for(int itemIndex=0;itemIndex<mDocuments.size();itemIndex++)
	  if(someCallbackData.hwndFrom()==(HWND)*(mDocuments[itemIndex]))mdiDestroy(*(mDocuments[itemIndex]));
	return (CallbackData::ReturnType)FALSE;
}

CallbackData::ReturnType FrameWindow::mdiActivateHandler(CallbackData &someCallbackData)
{
  MDIWindow *pMDIWndActivate=0;
	MDIWindow *pMDIWndDeactivate=0;

	for(int itemIndex=0;itemIndex<mDocuments.size();itemIndex++)
	{
	  if((HWND)someCallbackData.wParam()==(HWND)*(mDocuments[itemIndex]))pMDIWndDeactivate=(MDIWindow*)mDocuments[itemIndex];
	  if((HWND)someCallbackData.lParam()==(HWND)*(mDocuments[itemIndex]))pMDIWndActivate=(MDIWindow*)mDocuments[itemIndex];
	}
	if(pMDIWndDeactivate)mdiDeactivate(*pMDIWndDeactivate);
	if(pMDIWndActivate)mdiActivate(*pMDIWndActivate);
  return FALSE;
}

CallbackData::ReturnType FrameWindow::commandHandler(CallbackData &someCallbackData)
{
  PureMenu pureMenu(::GetMenu(someCallbackData.hwndFrom()));
	String strItem(pureMenu.menuItemString(someCallbackData.wParam(),PureMenu::ByCommand));
	if(!strItem.isNull()&&strItem==String("More Windows..."))return moreWindows(),FALSE;
  for(UINT chIndex=0,menuID=IDFirstMDIChild;chIndex<mDocuments.size();chIndex++,menuID++)
	  if(menuID==someCallbackData.wmCommandID())activate(chIndex);
  return FALSE;
}

BOOL FrameWindow::activate(UINT childIndex)
{
  if(childIndex>=mDocuments.size())return FALSE;
  mClientWnd.sendMessage(WM_MDIACTIVATE,(WPARAM)(HWND)*mDocuments[childIndex],0L);
	mDocuments[childIndex]->show(SW_SHOWNORMAL);
	return TRUE;
}

void FrameWindow::destroy(void)
{
  SmartPointer<MDIWindow> mdiWindow;
	Array<SmartPointer<MDIWindow> > mdiWindows;

	getDocuments(mdiWindows);
	for(int index=0;index<mdiWindows.size();index++)
	{
	  mdiWindow=mdiWindows[index];
		if(preDestroy(*mdiWindow))return;
	}

//	if(getFirstDocument(mdiWindow))
//	{
//	  if(preDestroy(*mdiWindow))return;
//	  while(getNextDocument(mdiWindow))
//		{
//		  if(preDestroy(*mdiWindow))return;
//		}
//	}
	closeAll();
  GUIWindow::destroy();
}

// *** virtuals

bool FrameWindow::preDestroy(MDIWindow &/*mdiWindow*/)
{
  return false;
}

void FrameWindow::moreWindows(void)
{
}

void FrameWindow::mdiDeactivate(MDIWindow &/*mdiWindow*/)
{
}

void FrameWindow::mdiActivate(MDIWindow &/*mdiWindow*/)
{
}

void FrameWindow::mdiDestroy(MDIWindow &/*mdiWindow*/)
{
}

void FrameWindow::preRegister(WNDCLASS &/*wndClass*/)
{
}


SDate::SDate(void)
{
  initArray();
	getTodaysDate();
//	CompatibleDate::Month=0;
//	CompatibleDate::Day=0;
//	CompatibleDate::Year=0;
}

// modified this 11/13/2002 after encountering first-chance exceptions encountered when parent
// window was the desktop window.  I'm thinking that there really is no reason why we should
// not use processInstance() in all cases.  Hopefully , this will not break any existing code.

HWND Control::createControl(const String &className,const String &windowName,DWORD dwStyle,const Rect &initRect,HWND hParentWnd,int controlID)
{
	dwStyle|=WS_CHILD;
	if(isValid())return *this;
	this->controlID(controlID);
//  createWindow(className,windowName,dwStyle,initRect,hParentWnd,(HMENU)controlID,(HINSTANCE)::GetWindowLong(hParentWnd,GWL_HINSTANCE),0);
  createWindow(className,windowName,dwStyle,initRect,hParentWnd,(HMENU)controlID,(HINSTANCE)processInstance(),0);
	disposition(GUIWindow::AssumeAndDestroy);
	return *this;
}

HWND Control::createControl(DWORD extendedStyle,const String &className,const String &windowName,DWORD dwStyle,const Rect &initRect,HWND hParentWnd,int controlID)
{
	dwStyle|=WS_CHILD;
	if(isValid())return *this;
	this->controlID(controlID);
//	createWindow(extendedStyle,className,windowName,dwStyle,initRect,hParentWnd,(HMENU)controlID,(HINSTANCE)::GetWindowLong(hParentWnd,GWL_HINSTANCE),0);
	createWindow(extendedStyle,className,windowName,dwStyle,initRect,hParentWnd,(HMENU)controlID,(HINSTANCE)processInstance(),0);
	disposition(GUIWindow::AssumeAndDestroy);
	return *this;
}

HWND Control::createControl(const String &className,const String &windowName,DWORD dwStyle,const Rect &initRect,Window &parentWindow,int controlID)
{
	dwStyle|=WS_CHILD;
	if(isValid())return *this;
	this->controlID(controlID);
//	createWindow(className,windowName,dwStyle,initRect,parentWindow,(HMENU)controlID,parentWindow.processInstance(),0);
	createWindow(className,windowName,dwStyle,initRect,parentWindow,(HMENU)controlID,processInstance(),0);
	disposition(GUIWindow::AssumeAndDestroy);
	return *this;
}

HWND Control::createControl(DWORD extendedStyle,const String &className,const String &windowName,DWORD dwStyle,const Rect &initRect,Window &parentWindow,int controlID)
{
	dwStyle|=WS_CHILD;
	if(isValid())return *this;
	this->controlID(controlID);
	createWindow(extendedStyle,className,windowName,dwStyle,initRect,parentWindow,(HMENU)controlID,processInstance(),0);
//	createWindow(extendedStyle,className,windowName,dwStyle,initRect,parentWindow,(HMENU)controlID,parentWindow.processInstance(),0);
	disposition(GUIWindow::AssumeAndDestroy);
	return *this;
}



class FileTime : private FILETIME
{
public:
	FileTime(void);
	FileTime(const FileTime &someFileTime);
	FileTime(const FILETIME &someFILETIME);
	FileTime(const SystemTime &someSystemTime);
	virtual ~FileTime();
	FileTime &operator=(const FileTime &someFileTime);
	FileTime &operator=(const SystemTime &someSystemTime);
