ScrollBar::ScrollBar( int nId, Win* parent, bool _vertical, bool _autoHide, crect* rect )
		:  Win( Win::WT_CHILD, 0, parent, rect, nId ),
		   vertical( _vertical ),
		   si( 100, 10, 0 ),
		   len( 0 ),
		   bsize( 0 ),
		   bpos( 0 ),
		   trace( false ),
		   traceBPoint( 0 ),
		   autoHide( _autoHide ),
		   b1Pressed( false ),
		   b2Pressed( false ),
		   managedWin( 0 )
	{
		LSize ls;
		int l = SB_WIDTH * 2;// + 2;// + 5;
		int h = SB_WIDTH;// + 2;

		if ( vertical )
		{
			ls.Set( cpoint( h, l ) );
			ls.y.maximal = 16000;
		}
		else
		{
			ls.Set( cpoint( l, h ) );
			ls.x.maximal = 16000;
		}

		SetLSize( ls );
		SetScrollInfo( 0 );
//	crect r = ClientRect();
//	EventSize(&cevent_size(cpoint(r.Width(),r.Height())));
	}
Win::Win( WTYPE t, unsigned hints, Win *_parent, const crect *rect, int uiNId )
:	
	type(t),
	whint(hints),
	parent(_parent),
	captured(false),
	state(0),
	lastFocusChild(0),
	blockedBy(0),
	modal(0),

	upLayout(0), 
	layout(0)
{

	DWORD st = WS_CLIPSIBLINGS | WS_CLIPCHILDREN  ;
	switch (type) {
	case WT_CHILD: st |= WS_CHILD; break;
	case WT_POPUP: st |= WS_POPUP; break;
	case WT_MAIN:
	default:
		if ((hints & WH_MINBOX) !=0 ) st |= WS_MINIMIZEBOX;
		if ((hints & WH_MAXBOX) !=0 ) st |= WS_MAXIMIZEBOX;
		if ((hints & WH_SYSMENU) !=0 ) st |= WS_SYSMENU;
		if ((hints & WH_RESIZE) !=0 ) st |= WS_SIZEBOX ;
//		if ((hints & WH_OVERLAPPED) !=0 ) st |= WS_OVERLAPPED;
	}

	crect r;
	if (rect) r = *rect;
	else 
	{
		r.left = CW_USEDEFAULT;
		r.top = CW_USEDEFAULT;
		r.right = CW_USEDEFAULT;
		r.bottom = CW_USEDEFAULT;
	}

	{
		int X, Y, W, H;

		if (!rect || type==WT_MAIN && (hints & WH_USEDEFPOS) != 0)
		{
			X = CW_USEDEFAULT;
			Y = 0;
			W = CW_USEDEFAULT;
			H = 0;
		} else {
			X = rect->left;
			Y = rect->top;
			W = rect->Width();
			H = rect->Height();
		}
	
		handle = CreateWindow(wClass, "Hi", st,
			X, Y, W, H, 
			(parent && parent->handle)? parent->handle :0, NULL, appInstance, NULL);
		DWORD e= GetLastError();
	}

	if (!handle) {
		throw_syserr();
	}

	AddWinToHash(handle, this);

	if (parent)
	{
		parent->childList.append(this);
	}

	if (rect && !rect->IsEmpty()) 
	{
		LSize ls;
		ls.Set(*rect);
		SetLSize(ls);
	}
}