void CExtDockBar::_ContextMenuTrack()
{
	// find any control bar
CControlBar * pBar = NULL;
	for( int nPos = 0; nPos < m_arrBars.GetSize(); nPos++ )
	{
		pBar = GetDockedControlBar(nPos);
		if( pBar != NULL )
		{
			ASSERT_VALID( pBar );
			break;
		}
	}
	if( pBar == NULL )
		return;

CFrameWnd * pFrame = _GetDockingFrameImpl();
CPoint point;
	VERIFY( ::GetCursorPos(&point) );
CExtPopupMenuWnd * pPopup =
		new CExtPopupMenuWnd;
	VERIFY( pPopup->CreatePopupMenu( pBar->GetOwner()->GetSafeHwnd() ) );
	_ContextMenuBuild(
		pFrame,
		pPopup
		);
	pPopup->TrackPopupMenu(
		0,
		point.x,point.y,
		pBar->GetOwner()->GetSafeHwnd() // pFrame->GetSafeHwnd()
		);
}
void CExtStatusControlBar::OnContextMenu(CWnd* pWnd, CPoint point) 
{
#if (!defined __EXT_MFC_NO_CUSTOMIZE)
CExtCustomizeSite * pSite =
		CExtCustomizeSite::GetCustomizeSite( m_hWnd );
	if(		pSite != NULL
		&&	pSite->IsCustomizeMode()
		)
		return;
#endif // (!defined __EXT_MFC_NO_CUSTOMIZE)

	if( CExtControlBar::FindHelpMode(this) )
		return;

CFrameWnd * pFrame = _GetDockingFrameImpl();
	if( pFrame == NULL )
	{
		CStatusBar::OnContextMenu( pWnd, point );
		return;
	}

	ASSERT_VALID( pFrame );
HWND hWndTrack = GetOwner()->GetSafeHwnd();
	ASSERT( hWndTrack != NULL && ::IsWindow(hWndTrack) );
CExtPopupMenuWnd * pPopup =
		new CExtPopupMenuWnd;
	VERIFY( pPopup->CreatePopupMenu(hWndTrack) );

	if(	! CExtDockBar::_ConstructDockSiteControlBarPopupMenu(
			pFrame,
			pPopup,
			CExtControlBar::POPUP_MENU_EVENT_DATA::__PMED_STATUSBAR_CTX,
			this,
			WM_CONTEXTMENU,
			NULL
			)
		)
	{
		delete pPopup;
		return;
	}
	if( pPopup->ItemGetCount() == 0 )
	{
		delete pPopup;
		return;
	}
	::SetFocus( hWndTrack );
	if( ! pPopup->TrackPopupMenu(
			TPMX_OWNERDRAW_FIXED,
			point.x,
			point.y
			)
		)
	{
		delete pPopup;
	}
}
void CJazzUpTellTaleButton::OnRButtonUp(UINT nFlags, CPoint point)
{
	// Mouse position
	POINT cursorPosition;
	GetCursorPos(&cursorPosition);

	CParametersDlg* ParamDlg = dynamic_cast<CParametersDlg*>(GetParent()->GetParent());
	if(!ParamDlg) return;

	int index = GetWindowLong(m_hWnd,GWL_ID);

	int type = ParamDlg->m_Stack.m_arrPanes[index]->type;

	if (type == EDITORPARAM_GLOBALVARIABLE)
		return;

	CExtPopupMenuWnd* popup =  new CExtPopupMenuWnd;
	popup->CreatePopupMenu(m_hWnd);
	popup->ItemInsertCommand(1,-1, "Use Expression",NULL,NULL);
	popup->ItemInsert(CExtPopupMenuWnd::TYPE_SEPARATOR);
	popup->ItemInsertCommand(2,-1, "Default",NULL,NULL);
	UINT Item = 0;
	if(!popup->TrackPopupMenu(TPMX_DO_MESSAGE_LOOP|TPMX_NO_WM_COMMAND|TPMX_NO_CMD_UI, cursorPosition.x, cursorPosition.y, NULL, NULL, NULL, &Item))
		return;

	if(ParamDlg && Item != 0 && Item != -1)
	{
		CString paraminfo = ParamDlg->m_Stack.m_arrPanes[index]->GetParameterString();
		ParamDlg->SetRedraw(false);
		ParamDlg->m_Stack.m_arrPanes[index]->content_window->DestroyWindow();

		int type = EDITORPARAM_USERPARAM;
		if(Item == 2)
			type = ParamDlg->m_pACEEntry->params.at(index).type;
		
		ParamDlg->CreateParameter(index,&ParamDlg->m_Stack,*ParamDlg->m_Stack.m_arrPanes[index], type, paraminfo);
			
		
		ParamDlg->m_Stack.RearrangeStack();
		ParamDlg->SetRedraw(true);
		ParamDlg->Invalidate();
	}
	else
	{
		CErrorDlg dlg;
		dlg.Error("Construct Error", "Error in JazzUpTellTaleButton - parent window could not be found");
	}


}
BOOL CExtResizableDialog::_TrackDialogSystemMenu(
	CPoint * pPoint,
	BOOL bSelectAny
	)
{
	if( (GetStyle() & WS_POPUP) == 0 )
		return FALSE;
	if(	CExtPopupMenuWnd::IsMenuTracking() )
		CExtPopupMenuWnd::CancelMenuTracking();
	m_bSysMenuTracking = FALSE;

CMenu * pSysMenu =
		GetSystemMenu( FALSE );
	if( pSysMenu == NULL )
		return FALSE;
	ASSERT( ::IsMenu(pSysMenu->GetSafeHmenu()) );
CExtPopupMenuWnd * pPopup = new CExtPopupMenuWnd;
	if( !pPopup->CreatePopupMenu( GetSafeHwnd() ) )
	{
		ASSERT( FALSE );
		return FALSE;
	}
	if( !pPopup->UpdateFromMenu(
			GetSafeHwnd(),
			pSysMenu,
			false
			)
		)
	{
		ASSERT( FALSE );
		return FALSE;
	}

CPoint point;
	if( pPoint != NULL)
		point = *pPoint;
	else
	{
		CRect rcWnd, rcClient, rcHelper;
		GetWindowRect( &rcWnd );
		GetClientRect( &rcClient );
		rcHelper = rcWnd;
		ScreenToClient( &rcHelper );
		ASSERT( rcHelper.top <= rcClient.top );
		int yDiff = rcClient.top - rcHelper.top;
		point = rcWnd.TopLeft();
		point.x += GetSystemMetrics(SM_CXFRAME);
		point.y += yDiff;
	}
	m_bSysMenuTracking =
		pPopup->TrackPopupMenu(
			TPMX_BOTTOMALIGN,
			point.x,point.y,
			GetSafeHwnd(),
			NULL,
			bSelectAny ? true : false
			) ? true : false;

	if( m_bSysMenuTracking )
		SetTimer( ID_TIMER_SYS_TRACKING, 20, NULL );
	return TRUE;
}
void CExtMiniDockFrameWnd::OnNcRButtonDown(UINT nHitTest, CPoint point)
{
	if( _ResizingIsInProgress() )
	{
		_ResizingEnd();
		return;
	}
	if( nHitTest == HTCAPTION )
	{
#if (!defined __EXT_MFC_NO_CUSTOMIZE)
		CExtCustomizeSite * pSite =
			CExtCustomizeSite::GetCustomizeSite( m_hWnd );
		if(		pSite != NULL
			&&	pSite->IsCustomizeMode()
			)
			return;
#endif // (!defined __EXT_MFC_NO_CUSTOMIZE)
		if( CExtControlBar::FindHelpMode(this) )
			return;
		CExtControlBar * pExtBar =
			GetControlBarExt();
		if( pExtBar != NULL )
		{
			ASSERT_VALID( pExtBar );
			
			CFrameWnd * pFrame = pExtBar->_GetDockingFrameImpl();
			ASSERT_VALID( pFrame );

			CPoint point;
			if( ! ::GetCursorPos(&point) )
				return;
			HWND hWndTrack = pFrame-> /*pExtBar->GetOwner()->*/ GetSafeHwnd();
			ASSERT( hWndTrack != NULL && ::IsWindow(hWndTrack) );
			CExtPopupMenuWnd * pPopup = new CExtPopupMenuWnd;
			VERIFY( pPopup->CreatePopupMenu(hWndTrack) );
			if(	! CExtDockBar::_ConstructDockSiteControlBarPopupMenu(
					pFrame,
					pPopup,
					CExtControlBar::POPUP_MENU_EVENT_DATA::__PMED_MINIFRAME_NC_CTX,
					pExtBar,
					WM_NCRBUTTONDOWN,
					NULL
					)
				)
			{
				delete pPopup;
				return;
			}
			if( pPopup->ItemGetCount() == 0 )
			{
				delete pPopup;
				return;
			}
			//::SetFocus( hWndTrack );
			if( ! pPopup->TrackPopupMenu(
					TPMX_OWNERDRAW_FIXED,
					point.x,
					point.y
					)
				)
			{
				delete pPopup;
			}
			return;
		} // if( pExtBar != NULL )
	} // if( nHitTest == HTCAPTION )
	CMiniDockFrameWnd::OnNcRButtonDown(nHitTest,point);
}