Professional UI Solutions
Site Map   /  Register
 
 

Forum

Please Log In to post a new message or reply to an existing one. If you are not registered, please register.

NOTE: Some forums may be read-only if you are not currently subscribed to our technical support services.

Forums » Prof-UIS Tech Support » CExtButtonwith menu question Collapse All
Subject Author Date
Offer Har Feb 21, 2007 - 4:11 PM

Dear Support,

I have a button I attached a menu to.
I would like the menu to have the exact same width as the button has, so it will look as an integral part of the button when the menu is opened.
How can this be done?

Thanks,
Ron.

Technical Support Feb 22, 2007 - 10:43 AM

There is no direct way to do this. But there is a workaround. First, create a CExtPopupMenuWnd-derived class and overridde the _CalcTrackSize method in it: call the mehod of the base class and then change the width in the returned CSize value as you want. Then create a CExtButton-derived class and override the _OnTrackPopup method. Leave the default method’s code but this line:

CExtPopupMenuWnd * pPopup = new CExtPopupMenuWnd;
In this line create your CExtPopupMenuWnd-derived class.


Offer Har Feb 22, 2007 - 11:00 AM

Dear Support,

Currently for creating a button with menu, all I do is:

    CMenu menu;
    menu.LoadMenu(IDR_MENU);
    m_btn.m_menu.Attach(menu.Detach());

Should I leave these 3 lines as-is?

Thanks,
Ron.

Technical Support Feb 22, 2007 - 11:08 AM

Yes, you don’t need to change these lines.

Offer Har Feb 22, 2007 - 11:15 AM

It works fine...
There is one problem - when in item is highlighted in the menu, the highlight does not go the whole way.
It seems that there is another place in the menu that tells the menu to highlight the item only up to the original width, and not the width that i specified in _CalcTrackSize.
How to solve this problem?
Thanks,
Ron.

Technical Support Feb 23, 2007 - 2:28 AM

Please place a call of CExtPopupMenuWnd::_SyncItems() before returning the execution control from the overridden _CalcTrackSize() method.

Offer Har Feb 23, 2007 - 8:39 AM

Does not work. Stil the highlight item does not go all the way.
This is the code:

virtual CSize _CalcTrackSize()
{
    CSize sz = CExtPopupMenuWnd::_CalcTrackSize();
    CRect rc;
    m_pParentButton->GetWindowRect(rc);
    sz.cx = rc.Width();
    CExtPopupMenuWnd::_SyncItems();
    return sz;
}

Technical Support Feb 24, 2007 - 12:18 PM

Here is a newer version of the popup menu class with the custom menu width adjustment:

class CMyPopup : public CExtPopupMenuWnd
{
      virtual CSize _CalcTrackSize()
      {
            CSize _sizeDefault = CExtPopupMenuWnd::_CalcTrackSize();
            CRect rc;
            m_pParentButton->GetWindowRect( &rc );
            CSize _sizeNew = _sizeDefault;
            _sizeNew.cx = rc.Width();
            m_sizeFullItems.cx += _sizeNew.cx - _sizeDefault.cx; 
            return _sizeNew;
      }
};
Additionally we would like to ask you to comment out the following assertion in the CExtPopupMenuWnd::_DoExpand() method in the ../Prof-UIS/Src/ExtPopupMenuWnd.cpp file:
//          ASSERT(
//                      m_sizeFullItems.cx >= m_sizeFullItems2.cx
//                &&    m_sizeFullItems.cy >= m_sizeFullItems2.cy
//                );

Offer Har Feb 25, 2007 - 8:58 AM

Thanks.
I didn’t comment the lines and it still works.
Are you sure i need to comment these lines out?

Technical Support Feb 25, 2007 - 10:38 AM

These lines should be commented out. Otherwise this would certainly produce the assertion failure when the Expand button is present at the bottom of the menu (relating to the rarely/frequently commands feature).