[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Insert popup menu in mainframe menu

Posted on 1998-04-20
11
Medium Priority
?
563 Views
Last Modified: 2013-11-20
Suppose that I have my main menu IDR_MAINFRAME and I would like to insert IDR_POPUP between 2nd and 3rd items of my main frame menu. How can I perform this?
IDR_MAINFRAME:
[File Edit Window Help]
          ^
     Insert here [Special]

IDR_POPUP:
[Special >][Item 1]
           [Item 2]
           [Item 3]
0
Comment
Question by:fmichaud061597
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 4
  • 2
11 Comments
 
LVL 23

Expert Comment

by:chensu
ID: 1300844
In the Resource Editor, there is a blank box next to Help.

                       ___
File Edit Window Help |   |
                       ---

Drag the box and drop it between Edit and Window. The right click the box and select Properties from the context menu.
0
 

Author Comment

by:fmichaud061597
ID: 1300845
It's not a design-time menu creation I wanted. It's a dynamic linkage between the main menu and an other popup menu. There are two menus: IDR_MAINFRAME and IDR_POPUP.
0
 
LVL 23

Expert Comment

by:chensu
ID: 1300846
Sorry, I misunderstood.

You can do so by using the following steps:

1. Call CWnd::GetMenu() on the frame window;
2. Call CMenu::LoadMenu() to load the IDR_POPUP menu;
3. Call CMenu::InsertMenu() to insert the menu to the frame window menu;
4. Call CWnd::DrawMenuBar() to redraws the menu bar.
0
Learn how to optimize MySQL for your business need

With the increasing importance of apps & networks in both business & personal interconnections, perfor. has become one of the key metrics of successful communication. This ebook is a hands-on business-case-driven guide to understanding MySQL query parameter tuning & database perf

 

Author Comment

by:fmichaud061597
ID: 1300847
I can't figure out what i'm doing wrong. This is my code:

int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
    CMenu* pMenu = GetMenu();
    CMenu popupMenu;
    popupMenu.LoadMenu(IDR_POPUP);
    CString strMenu;
    popupMenu.GetMenuString(0, strMenu, MF_BYPOSITION);
    pMenu->InsertMenu(2, MF_BYPOSITION | MF_POPUP, (UINT)&popupMenu, strMenu);

    return 0;
}
0
 
LVL 4

Expert Comment

by:piano_boxer
ID: 1300848
Ok here's the solution:

Move the menu modifying code to a separate message handler and make a small change to the InsertMenu() call and add the line DrawMenuBar():

LRESULT CMainFrame::OnApp10(WPARAM, LPARAM)
{
    CMenu* pMenu = GetMenu();
    CMenu popupMenu;
    popupMenu.LoadMenu(IDR_POPUP);
    CString strMenu;
    popupMenu.GetMenuString(0, strMenu, MF_BYPOSITION);

    pMenu->InsertMenu(1, MF_BYPOSITION | MF_POPUP, (UINT)popupMenu.GetSubMenu(0)->Detach(), strMenu);

      DrawMenuBar( );

      return 0;
}

in your WM_CREATE handler post a user message:

PostMessage(WM_APP+10);

Insert this line in the messagemap. (Just above END_MESSAGE_MAP()):

ON_MESSAGE(WM_APP+10, OnApp10)

Insert the declaration of the function int til the class header:

LRESULT OnApp10(WPARAM, LPARAM);

0
 

Author Comment

by:fmichaud061597
ID: 1300849
It's causes an error (Debug assertion failed) when I click on the new created menu in the menu bar.
0
 
LVL 4

Expert Comment

by:piano_boxer
ID: 1300850
Then, whats the location of the assert failed line?
0
 

Author Comment

by:fmichaud061597
ID: 1300851
     { ASSERT(::IsMenu(m_hMenu)); return CMenu::FromHandle(::GetSubMenu(m_hMenu, nPos)); }

0
 
LVL 23

Accepted Solution

by:
chensu earned 400 total points
ID: 1300852
Do not use popupMenu as a local variable. Declare it as a member variable of CMainFrame.
0
 

Author Comment

by:fmichaud061597
ID: 1300853
Thank you. I was eye blinded =) So, one little more thing... if I want to access my popup menu from a button, for example, I need to invoke TracPopupMenu. But how to get exact x and y position for the menu, because I want that the menu appears just below my button and an at exactly place.

ex:
[Button]
[Button]
[Menu popup-----]
[Menu popup-----]
[Menu popup-----]
[Menu popup-----]
[Menu popup-----]
0
 
LVL 23

Expert Comment

by:chensu
ID: 1300854
The x and y parameters of TrackPopupMenu are in screen coordinates. You should know where you have put your buttons in the window. Call CWnd::ClientToScreen to convert them to screen coordinates. That's it.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction: Hints for the grid button.  Nested classes, templated collections.  Squash that darned bug! Continuing from the sixth article about sudoku.   Open the project in visual studio. First we will finish with the SUD_SETVALUE messa…
Introduction: The undo support, implementing a stack. Continuing from the eigth article about sudoku.   We need a mechanism to keep track of the digits entered so as to implement an undo mechanism.  This should be a ‘Last In First Out’ collec…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
Suggested Courses

656 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question