示例#1
0
static int ReadMenu(CurPos &cp, const char *MenuName) {
    unsigned char obj;
    unsigned short len;

    int menu = -1, item = -1;

    menu = NewMenu(MenuName);

    while ((obj = GetObj(cp, len)) != 0xFF) {
        switch (obj) {
        case CF_ITEM:
            {
                if (len == 0) {
                    item = NewItem(menu, 0);
                } else {
                    const char *s = GetCharStr(cp, len);
                    int Cmd;
                    if (s == 0) return -1;
                    item = NewItem(menu, s);
                    if ((obj = GetObj(cp, len)) != CF_MENUSUB) return -1;
                    if ((Cmd = ReadCommands(cp, 0)) == -1) return -1;
                    Menus[menu].Items[item].Cmd = Cmd + 65536;
                }
            }
            break;
        case CF_SUBMENU:
            {
                const char *s = GetCharStr(cp, len);
                const char *w;

                if ((obj = GetObj(cp, len)) != CF_STRING) return -1;
                if ((w = GetCharStr(cp, len)) == 0) return -1;
                item = NewSubMenu(menu, s, GetMenuId(w), SUBMENU_NORMAL);
            }
            break;

        case CF_SUBMENUCOND:
            {
                const char *s = GetCharStr(cp, len);
                const char *w;

                if ((obj = GetObj(cp, len)) != CF_STRING) return -1;
                if ((w = GetCharStr(cp, len)) == 0) return -1;
                item = NewSubMenu(menu, s, GetMenuId(w), SUBMENU_CONDITIONAL);
            }
            break;

        case CF_END:
            return 0;
        default:
            return -1;
        }
    }
    return -1;
}
示例#2
0
void CWinMenu::OnMouseMove(UINT nFlags, CPoint point) 
{
	LPMITEMINFO	item = GetMenuItem( &point );

	BOOL bRedraw = FALSE;

	// Redraw window if needed by toolbar
	if (	item != NULL && item->toolbar != NULL && 
			item->toolbar->OnMouseMove( nFlags, &point ) )
		bRedraw = TRUE;

	if ( ( nFlags & MK_LBUTTON ) == 0 )
	{	

		if ( item != m_itemover )
		{
			// Clear mouse over
			if ( m_itemover != NULL && m_itemover->toolbar != NULL )
				m_itemover->toolbar->ClearMouseOver();

			// Save new item
			m_itemover = item;

			// Popup sub menu if needed
			NewSubMenu( item );

			// Redraw our window
			bRedraw = TRUE;

		} // end if

	} // end if

	else
	{
		RECT c;
		GetWindowRect( &c );

		if ( !PtInRect( &c, point ) )
		{
			HWND last = m_hDropWnd;

			POINT pt;
			pt.x = point.x;
			pt.y = point.y;
			ClientToScreen( &pt );

			// Which window was choosen
			HWND hParent = ::WindowFromPoint( pt );
			if ( m_bAllowChildren )
			{
				if ( hParent != NULL )
				{
					// Check for child windows
					::ScreenToClient( hParent, &pt );
					HWND hChild = ::ChildWindowFromPoint( hParent, pt );
					
					// Which window to use
					if ( hChild != NULL ) m_hDropWnd = hChild;
					else m_hDropWnd = hParent;
						
				} // end if
			} // end if
			else
			{
				// Get topmost window
				while ( hParent != NULL )
				{
					m_hDropWnd = hParent;
					hParent = ::GetParent( hParent );
				} // end while

			} // end else

			// Border window
			if ( last != m_hDropWnd ) 
			{
				// Undo our mess
				RedrawLastWindow();

				if ( m_hDropWnd != GetSafeHwnd() && ::IsWindow( m_hDropWnd ) )
				{
					HDC hDC = ::GetWindowDC( m_hDropWnd );

					if ( hDC != NULL )
					{
						// Save last window we screwed up
						m_hLastWnd = m_hDropWnd;

						RECT rect;
						::GetWindowRect( m_hDropWnd, &rect );
						OffsetRect( &rect, -rect.left, -rect.top );

						HBRUSH oldbrush = (HBRUSH)SelectObject( hDC, GetStockObject( NULL_BRUSH ) );
						HPEN red = CreatePen( PS_DASH, 2, RGB( 255, 0, 0 ) );
						HPEN white = CreatePen( PS_DASH, 2, RGB( 80, 80, 80 ) );
						HPEN blue = CreatePen( PS_DASH, 2, RGB( 0, 0, 255 ) );
						HPEN oldpen = (HPEN)SelectObject( hDC, red );

						// Draw the rectangle
//						Rectangle( hDC, rect.left, rect.top, rect.right, rect.bottom );

						InflateRect( &rect, -2, -2 );
						SelectObject( hDC, red );
						Rectangle( hDC, rect.left, rect.top, rect.right, rect.bottom );

						InflateRect( &rect, -2, -2 );
						SelectObject( hDC, blue );
						Rectangle( hDC, rect.left, rect.top, rect.right, rect.bottom );

						// Restore the DC
						SelectObject( hDC, oldpen );
						SelectObject( hDC, oldbrush );
						DeleteObject( red );
						DeleteObject( white );
						DeleteObject( blue );
						::ReleaseDC( m_hDropWnd, hDC );
					} // end if
				} // end if
			} // end if

		} // end if

	} // end else if
	
	// Redraw window if needed
	if ( bRedraw ) RedrawWindow();

	CWnd::OnMouseMove(nFlags, point);
}