Popup Menu on AcPane

Popup Menu on AcPane

Kyudos
Advisor Advisor
1,148 Views
6 Replies
Message 1 of 7

Popup Menu on AcPane

Kyudos
Advisor
Advisor

I'm having problems displaying a popup menu from the OnRButtonDown handler of my AcPane derived class. The first problem is positioning the menu I'm using this:

 

//------------------------------------------------------------------------------
void MyPane::OnRButtonDown(UINT nFlags, CPoint pt)
//------------------------------------------------------------------------------
{
    CMenu Menu;
    AcApStatusBar* pStatus = acedGetApplicationStatusBar();
    if (pStatus != NULL)
    {
        HWND hwndStatusBar = NULL;
        HWND hwndStatusBarHost = ::GetDlgItem(adsw_acadMainWnd(), 0xE801);
        if (hwndStatusBarHost != NULL)
        {
            hwndStatusBar = GetWindow(hwndStatusBarHost, GW_CHILD);
        }

        ::ClientToScreen(hwndStatusBar, &pt);

This doesn't give the correct coordinates on my multi-monitor system. Does anyone know how to convert between the results of ClientToScreen and the virtual desktop?

 

The second problem is that all my popup menu items are disabled, despite being enabled in the resources. Even if I iterate through them and specifically enable them, they are still disabled. How can I fix that?

 

 

0 Likes
Accepted solutions (1)
1,149 Views
6 Replies
Replies (6)
Message 2 of 7

owenwengerd
Advisor
Advisor

Have you tried using AcPane::DisplayPopupPaneMenu() instead?

--
Owen Wengerd
ManuSoft
0 Likes
Message 3 of 7

Kyudos
Advisor
Advisor

Yeah  - I tried that first, but I can't get it to hit the handler. The docs seem to suggest it will only work for ACSB_POPUP panels, so I use SetStyle in my constructor, but it doesn't seem to work.

0 Likes
Message 4 of 7

Kyudos
Advisor
Advisor

Ok...progress of sorts. I'm trying to modify the menu before I display it. So I have this:

 

 

if (Menu.LoadMenu(IDR_DIALOGBAR))
{
    CMenu* pSubMenu = Menu.GetSubMenu(3);

    // Show all info on menu
    CString strInfoMode = _T("");
    CString strMenuItem = _T("");
    CString strNewMenu = _T("");
    UINT nID = 0;
    if (pSubMenu != NULL)
    {
        for (int i = 0; i < 7; i++)
        {
            pSubMenu->GetMenuString(i, strMenuItem, MF_BYPOSITION);
            strInfoMode = GetInfoModeString((AEI_InfoPane::eInfoMode)i);
            strNewMenu.Format(_T("%s\t(%s)"), strMenuItem, strInfoMode);
            nID = pSubMenu->GetMenuItemID(i);
            pSubMenu->ModifyMenu(i, MF_BYPOSITION | MF_STRING, nID, strNewMenu);
        }

        pSubMenu->CheckMenuRadioItem(0, 7, m_eInfoMode, MF_BYPOSITION);
        CWnd* pWnd = acedGetAcadFrame();
        UINT nMenuID = pSubMenu->TrackPopupMenu(TPM_LEFTALIGN | TPM_RIGHTBUTTON | TPM_RETURNCMD, pt.x, pt.y, pWnd);

        if (nMenuID != 0)
        {
            OnInfoMenu(nMenuID);
        }
    }
}

 

IDR_DIALOGBAR is a menu resource containing the definitions of multiple popup menus. The above code shows the menu with the modified strings, but in the wrong place with all items disabled.

 

If I change it to this:

 

if (Menu.LoadMenu(IDR_INFOMENU))
{
    // Show all info on menu
    CString strInfoMode = _T("");
    CString strMenuItem = _T("");
    CString strNewMenu = _T("");
    UINT nID = 0;

    for (int i = 0; i < 7; i++)
    {
        Menu.GetMenuString(i, strMenuItem, MF_BYPOSITION);
        strInfoMode = GetInfoModeString((AEI_InfoPane::eInfoMode)i);
        strNewMenu.Format(_T("%s\t(%s)"), strMenuItem, strInfoMode);
        nID = Menu.GetMenuItemID(i);
        Menu.ModifyMenu(i, MF_BYPOSITION | MF_STRING, nID, strNewMenu);
    }

    Menu.CheckMenuRadioItem(0, 7, m_eInfoMode, MF_BYPOSITION);
    UINT nMenuID = pStatus->DisplayPopupPaneMenu(this, Menu);

if (nMenuID != 0) { OnInfoMenu(nMenuID); } }

Now IDR_INFOMENU is a copy of the submenu from the first instance 'promoted' to a menu resource in it's own right. Here the menu modification fails, but the menu displays enabled in the correct place (and the menu works).

 

(Note my AcPane::DisplayPopupPaneMenu handler is still never called).

 

So it seems like AutoCAD is interfering with my menu, whether I like it or not...

 

Any ideas?

 

0 Likes
Message 5 of 7

Kyudos
Advisor
Advisor
Accepted solution

Some partial solutions...

 

In my first method it seems to be setting the TrackMenuPopup owner to acedGetAcadFrame that causes the menu to be disabled. However, setting it to something else causes other problems (i.e., the menu doesn't work). Of course, it's still in the wrong place too.

 

If I fix my second method to modify the strings in the sub-menu (d'oh!) it almost does the right thing. It is enabled, it works and appears in the correct place - but AutoCAD's theming hasn't implemented menu tabs correctly. The Windows standard is that putting a tab in the menu text aligns everything after the tab to the right, regardless of the length of the menu text - AutoCAD isn't doing that.

 

It should look like this:

 

Menu2.png

 

instead it looks like this:

 

Menu1.png

 

However, that's probably close enough for now.

0 Likes
Message 6 of 7

Anonymous
Not applicable

I also encountered the same problem,Did you find a solution?


Kyudos 

 

 

 

 


 

0 Likes
Message 7 of 7

Kyudos
Advisor
Advisor

Only in as far as I've described here - my menu displays in the correct place, with the correct strings but doesn't handled the tabs correctly. I suspect that is a failure in AutoCAD's theming routines. It's a pretty minor display problem so I didn't try to fix it myself (since it would be fairly involved).

0 Likes