Geeks With Blogs
Prabhu Kumar a tech twaddler..
I received a comment on one of my previous posts, correcting me on what I had mentioned. The menu bar resource was defined as below:


IDR_MENU SHMENUBAR DISCARDABLE
BEGIN
    IDR_MENU,
    2,

    I_IMAGENONE, IDM_OK, TBSTATE_ENABLED, TBSTYLE_BUTTON | TBSTYLE_AUTOSIZE,
    IDS_OK, 0, NOMENU,
   
    I_IMAGENONE, IDM_HELP, TBSTATE_ENABLED, TBSTYLE_DROPDOWN | TBSTYLE_AUTOSIZE,
    IDS_HELP, 0, 0,
END

And I had said, "Everything in between BEGIN and END defines the menu bar. The first line under BEGIN should be the same as the menu bar identifier, IDR_MENU". Well, I was wrong there. The first line under BEGIN could be same as the menu bar identifier but it need not be. Thanks Binary for noticing that! The first line under BEGIN is the identifier of the popup menu that appears when the user clicks on one of the popup menus.  If both the softkeys in your menu bar are buttons then the popup menu identifier could be specified as zero. So the correct way of doing it would be to define the menu bar as:


IDR_MENU SHMENUBAR DISCARDABLE
BEGIN
    IDR_MENU_POPUP,
    2,

    I_IMAGENONE, IDM_OK, TBSTATE_ENABLED, TBSTYLE_BUTTON | TBSTYLE_AUTOSIZE,
    IDS_OK, 0, NOMENU,
   
    I_IMAGENONE, IDM_HELP, TBSTATE_ENABLED, TBSTYLE_DROPDOWN | TBSTYLE_AUTOSIZE,
    IDS_HELP, 0, 0,
END

and IDR_MENU_POPUP is defined as a popup menu,


IDR_MENU_POPUP MENU
BEGIN
    POPUP ""
    BEGIN
        MENUITEM "System Metric",               IDM_SYSTEM_METRIC
        MENUITEM "About",                              IDM_HELP_ABOUT
    END
END

In the above menu bar, the left softkey is an "OK" button and right softkey is a popup menu with "System Metric" and "About" as its menu items. Just remember that IDR_MENU is the identifier of the softkey bar which is created and IDR_MENU_POPUP is the identifier of the popup menu, which appears when the user clicks on the right softkey "Menu"

 

Binary also raised another interesting point. How do we get popup menus on both right softkey and left softkey? Of course, the first thing I did was to remove the NOMENU option from the part defining the left softkey. You can see the problem there can't you? Both left softkey and right softkey become popup menus, but both the popup menus show the same menu items because we specified a single popup menu identifier, IDR_MENU_POPUP, and that is why the same popup menu shows up for both the softkeys.





I was looking into how to get different popup menus for the 2 softkeys when Mr (or Ms) Binary replied again. Binary had figured out how.

 

You define the popup menu as usual but with two popup entries,


IDR_MENU_POPUP MENU
BEGIN
    POPUP "Menu L"
    BEGIN
        MENUITEM "Menu Item1",                        0
        MENUITEM "Menu Item2",                        0
    END

    POPUP "Menu R"
    BEGIN
        MENUITEM "System Metric",               IDM_SYSTEM_METRIC
        MENUITEM "About",                              IDM_HELP_ABOUT
    END
END
 

and while creating the menubar in WM_CREATE message, specify the following options,


        case WM_CREATE:
            SHMENUBARINFO mbi;

            memset(&mbi, 0, sizeof(SHMENUBARINFO));
            mbi.cbSize     = sizeof(SHMENUBARINFO);
            mbi.hwndParent = hWnd;
            mbi.nToolBarId = IDR_MENU_POPUP;
            mbi.hInstRes   = g_hInst;
            mbi.dwFlags = SHCMBF_HMENU;

            if (!SHCreateMenuBar(&mbi))
            {
                g_hWndMenuBar = NULL;
            }
            else
            {
                g_hWndMenuBar = mbi.hwndMB;
            }

The only difference is we specify the popup menu identifier for nToolBarId member instead of the menu bar identifier and we also set the SHCMBF_HMENU flag. When SHCMBF_HMENU flag is not specified then the nToolBarId value is treated as a toolbar identifer which creates our usual softkey bar with left and right softkeys. If the flag is set then nToolBarId is treated as a menu identifier. Just a regular menu bar with menus and submenus. So now when you run the application you get,




Be sure to specify the message value if you want to handle these menu clicks. I have specified zero above because I am not really interested in handling these items.

 

So now a question pops up (pun intended), what if I have several popup menus and submenus in the popup identifier. Will it take only the first two and display them or will it do something strange? See for yourself, I used the following popup menu just for the sake of it,


IDR_MENU_POPUP MENU
BEGIN

    POPUP "File"
    BEGIN
        MENUITEM "&Open",               0
        MENUITEM "&Save",                0
        MENUITEM "E&xit",                  0
    END

    POPUP "Edit"
    BEGIN
        MENUITEM "&Copy",               0
        MENUITEM "C&ut",                 0
        MENUITEM "&Paste",              0
    END

    POPUP "View"
    BEGIN
        MENUITEM "&Full Screen",       0
        MENUITEM "&Options",            0
    END

    POPUP "Help"
    BEGIN
        MENUITEM "Abou&t",              0
        MENUITEM "He&lp",                0
    END

END


here's what is does,






and,




I have never seen that on a ppc! I was surprised that it actually works and creates a full fledged menu bar with several menus. And notice the SIP button has moved to the right. The color of the menu bar has changed as well. A pretty interesting find, I would say.


Update:
You might also be interested in this post, Fun with menus - part II

Posted on Thursday, July 9, 2009 12:42 PM Applications | Back to top


Comments on this post: Fun with menus!

# re: Fun with menus!
Requesting Gravatar...
This post is great, the documentation to use this stuff is very poor at MSFT, but I have a problem man, my two menus are still detecting the first one, and I cant access the other one.

can you please post what u did in the resources files(.rc and rc2) or the example code?

currently Im working in a project using this.
thanks in advance
Left by Morin Marco on Feb 05, 2010 3:25 PM

# re: Fun with menus!
Requesting Gravatar...
Morin, glad the post was useful.

About the problem you are facing, I am guessing that you are trying to get different popup menu's on both left and right softkeys. The problem could be that you are not setting the nToolBarId member of SHMENUBARINFO struct to the popup_menu_identifier and you also need to set the dwFlags to SHCMBF_HMENU for it to work.

If I am wrong in assuming above, do explain your problem in detail and post some code, if you can.

Also note that having popup menus in both left and right softkey is not recommended. The general practice is to have the left softkey as a button and the right as a menu. You could check WinMob UI guidelines, a google/bing search should turn up good results.
Left by Prabhu on Feb 08, 2010 8:19 AM

# re: Fun with menus!
Requesting Gravatar...
Yes Prabhu,
Im trying to get two different, PopUp menus on Left and Right soft keys.
But Im doing exactly what u did, or well maybe im doing something wrong :S

This is my .rc2
memset(&mbi, 0, sizeof(SHMENUBARINFO));
mbi.cbSize = sizeof(SHMENUBARINFO);
mbi.hwndParent = hWindow;
mbi.dwFlags = SHCMBF_HMENU|SHCMBF_HIDESIPBUTTON;
mbi.nToolBarId = IDR_MENU_POPUP;
mbi.hInstRes = m_hInstance;
mbi.nBmpId = 0;
mbi.cBmpImages = 0;this is my RC file

IDR_MENU SHMENUBAR DISCARDABLE
BEGIN
IDR_MENU_POPUP,
1,

I_IMAGENONE, IDM_MENU, TBSTATE_ENABLED, TBSTYLE_DROPDOWN | TBSTYLE_AUTOSIZE ,
IDS_MENU, 0, 0,
END

This is my cpp:

memset(&mbi, 0, sizeof(SHMENUBARINFO));
mbi.cbSize = sizeof(SHMENUBARINFO);
mbi.hwndParent = hWindow;
mbi.dwFlags = SHCMBF_HMENU|SHCMBF_HIDESIPBUTTON;
mbi.nToolBarId = IDR_MENU_POPUP;
mbi.hInstRes = m_hInstance;
mbi.nBmpId = 0;
mbi.cBmpImages = 0;

And this is my .rc

IDR_MENU_POPUP MENU
BEGIN
POPUP "Menu"
BEGIN
POPUP "Color Properties"
.
.
END
POPUP "Settings"
BEGIN
POPUP "Color Properties"
.
END
END

What do you think? Did I miss something?
I think the problem is in the Rc2
Left by Morin Marco on Feb 08, 2010 8:53 AM

# re: Fun with menus!
Requesting Gravatar...
Well, your code looks fine from here, I don't see why it wouldn't work. The .rc2 file does not matter because the menu bar that we define there is not used anywhere. Only the popup menu defined in .rc file is used. Is your menubar getting created at all? Or is SHCreateMenuBar() returning any error code?

I have sent the sample application to your id, try it out with Visual Studio and compare the .rc file, code under WM_CREATE of WndProc and resourceppc.h (make sure that all the id's are unique) with your files.

If you get it working please leave a note on what the problem was.
Left by Prabhu on Feb 08, 2010 9:35 AM

# re: Fun with menus!
Requesting Gravatar...
Blog post on this problem:

Fun with menus! update on Part I
Left by Prabhu on Feb 24, 2010 11:08 PM

# re: Fun with menus!
Requesting Gravatar...
How to create popup menu on the list item press.
Left by raghavendra on May 26, 2010 3:38 AM

# re: Fun with menus!
Requesting Gravatar...
Raghvendra, Sorry but I didn't understand what you are trying to ask, could you elaborate?
Left by Prabhu on May 26, 2010 10:19 PM

# re: Fun with menus!
Requesting Gravatar...
Prabhu, thanks for the great post which helped me lots on understanding wm6.5 menus. I have yet another problem with menus though, and I would like to hear your opinion.
I have made a menubar with two menu items: the left one is a normal popup menu and the one on the right is a button. Here is the rc file:
IDR_MENU SHMENUBAR DISCARDABLE
BEGIN
IDR_MENU_WINDOW,
2,
I_IMAGENONE, ID_MENU, TBSTATE_ENABLED, TBSTYLE_DROPDOWN | TBSTYLE_AUTOSIZE,
IDS_CAP_MENU, 0, 0,
I_IMAGENONE, ID_ACTION, TBSTATE_ENABLED, TBSTYLE_BUTTON | TBSTYLE_AUTOSIZE,
IDS_DONE, 0, NOMENU,
END
I would like to dynamically change the text on the button. For example, it could be "Done" in some cases, but could be "Confirm" in some other cases. But I couldn't retrieve the handle to the 'button' menu item at all.
I tried this
HMENU menu = (HMENU)m_wndCmdBar.SendMessage(SHCMBM_GETSUBMENU, 0, ID_MENU);
HMENU menu_button = (HMENU)m_wndCmdBar.SendMessage(SHCMBM_GETSUBMENU, 0, ID_ACTION);
The first line returns the handle to the left menu fine, but the second one always gives NULL. Do you have any idea about when I have done wrong? Thanks in advance.
Left by Dan on Sep 11, 2010 9:20 AM

# re: Fun with menus!
Requesting Gravatar...
Dan, glad you found the post useful.

Look at the post below, I think this is what you are looking for?

Changing the text of a softkey menu
Left by Prabhu on Sep 13, 2010 10:29 AM

# re: Fun with menus!
Requesting Gravatar...
Prabhu, that solved my puzzle. I should have found that page before posting my question. Thanks for your help. Dan
Left by Dan on Sep 15, 2010 3:36 PM

# re: Fun with menus!
Requesting Gravatar...
Hi
I know that this article is a little old, but I hope that you still work with Windows Mobile and you can help me.
I work on Visual Studio 2008 and SDK Windows Mobile 6.5 Professional. I created project as MFC Smard Device Application
I need make something what will be mix menu and toolbar.
Tollbar will have 6 items
First is standard menu position with "label" without image.
Second is button with image without text which run some function
Next position is again menu (submenu) with image and without text after click on this button I want have one (second in my POPUP MENU) of submenu.
Next again button with image without text which run some function
Next position is again menu (submenu) with image and without text after click on this button I want have one of submenu.
Next again button with image without text which run some function

So in my .rc2 file I prepare this structure

IDR_TEST_2 SHMENUBAR DISCARDABLE
BEGIN
IDR_TEST_3,
6,

I_IMAGENONE, IDM_MENU, TBSTATE_ENABLED, TBSTYLE_DROPDOWN | TBSTYLE_AUTOSIZE,
IDS_MENU, 0, 0,

1, ID_TEST2_TEST21, TBSTATE_ENABLED, TBSTYLE_BUTTON | TBSTYLE_AUTOSIZE,
0, 0, NOMENU,

2, IDM_MENU, TBSTATE_ENABLED, TBSTYLE_DROPDOWN | TBSTYLE_AUTOSIZE,
0, 0, 1,

3, ID_TEST3_TEST31, TBSTATE_ENABLED, TBSTYLE_BUTTON | TBSTYLE_AUTOSIZE,
0, 0, NOMENU,

4, IDM_MENU, TBSTATE_ENABLED, TBSTYLE_DROPDOWN | TBSTYLE_AUTOSIZE,
0, 0, 2,

5, ID_BUTTON32784, TBSTATE_ENABLED, TBSTYLE_BUTTON | TBSTYLE_AUTOSIZE,
0, 0, NOMENU,

END

IDR_TEST_3 MENU
BEGIN
POPUP "Test1"
BEGIN
MENUITEM "Test11", ID_TEST1_TEST11
MENUITEM "Test12", ID_TEST1_TEST12
END
POPUP "Test2"
BEGIN
MENUITEM "Test21", ID_TEST2_TEST21
MENUITEM "Test22", ID_TEST2_TEST22
END
POPUP "Test3"
BEGIN
MENUITEM "Test31", ID_TEST3_TEST31
MENUITEM "Test32", ID_TEST3_TEST32
END
END

I found somewhere information that this last position in SHMENUBAR items (NOMENU or number) this is index in MENU POPUP, so in 1 items I put 0 - first POPUP "Test1"
in 3 items I put 1 (POPUP "Test2") and in 5 items I put 3(POPUP "Test3").


and in CMainFrame::OnCreate I removed
if (!m_wndCommandBar.Create(this) ||
!CreateSimpleCEMenuBar(IDR_MAINFRAME, SHCMBF_HMENU) ||
!m_wndCommandBar.LoadToolBar(IDR_MAINFRAME) ||
!m_wndCommandBar.AddAdornments(dwAdornmentFlags))
{ ///....


and put

SHMENUBARINFO mbi;
ZeroMemory(&mbi, sizeof mbi);
mbi.cbSize = sizeof mbi;
mbi.hwndParent = this->GetSafeHwnd(); //handle of the dialog window
mbi.nToolBarId = IDR_TEST_2;
mbi.hInstRes = AfxGetResourceHandle();
mbi.dwFlags = SHCMBF_HIDESIPBUTTON;
mbi.nBmpId = IDR_TEST_2;
mbi.cBmpImages = 4;

if(SHCreateMenuBar(&mbi))
{ // ....



On device menu looks corect exactly as I want only problem is that for all (1,3,5) items I got the same menu (POPUP "Test1"). Of Course I can't add flags SHCMBF_HMENU because in this case I lost image and every position will be with text.

Thanks for your help.

Piotr
Left by Piotr Komorowski on Mar 10, 2013 2:45 AM

Your comment:
 (will show your gravatar)


Copyright © TechTwaddle | Powered by: GeeksWithBlogs.net