locked
WM_INITMENUPOPUP on Smartphone RRS feed

  • Question

  • Hi,

    I have a Windows Mobile 5 for PocketPC application which I am trying to port to Smartphone. Actually I am trying to have the PPC app run on Smartphone.

    The problem I am facing now is that I am populating the menus not at creation time, but only when the user opens them. My code works on PocketPC by intercepting the WM_INITMENUPOPUP message in the window's WindowProc function.

    On Smartphone 2005, however, my app never receives this message. According to the documentation and some websites, I think that WM_INITMENUPOPUP is supposed to be available on Smartphone, so this may be an issue with the application source.

    Has anybody an idea what the reason for my problem may be?

    Thanks in advance,

    Daniel

    P.S: This is an Visual Studio 2005 SP1 C++ application utilizing MFC.
    Sunday, June 10, 2007 6:18 PM

Answers

  • Hi again,

    I've now solved the problem by adding an OnInitMenuPopup function to my main frame derived class and if on smartphone, calling the corresponding function in the currently active window of my application.

    Code Snippet

    void CMainFrame::OnInitMenuPopup(CMenu* pMenu, UINT nIndex, BOOL bSysMenu) {
        CFrameWnd::OnInitMenuPopup(pMenu, nIndex, bSysMenu);

        if (isSmartPhone && !bSysMenu) {
            CMyDialog* currentDlg = m_wndView.GetCurrentDialog();
            currentDialog->OnInitMenuPopup(pMenu->m_hMenu, nIndex, bSysMenu);
        }
    }


    Daniel
    Wednesday, June 13, 2007 8:01 AM

All replies

  • Hi Daniel,

     

    WM_INITMENUPOPUP is surely available on Smartphone. For  MFC smart device dialog-based application, you can add handler for this message by the following steps:

    1. Open rc file editor and select dialog in designer;
    2. Right click the dialog and select property;
    3. In Properties window, turn to Messages page, you can find WM_INITMENUPOPUP message;
    4. Add handler called OnInitMenuPopup.

    For why this message cannot be received when porting Pocket PC to Smartphone. I may guess it is due to the Smart Phone style menu. (SHMENUBAR). So, try to create a clear Smartphone C++ project and execute the code that you use it to create the menu in your Pocket PC, and check if it can create the menu on Smartphone as expect.

     

    Thanks,

    Zero Dai - MSFT

    Wednesday, June 13, 2007 3:55 AM
  • I should have mentioned that even though I am using MFC, I am not using the CDialog class, i.e. I have my own CWnd derived "dialog" that I populate manually.

    That said, I did some more testing and on PocketPC, my application receives a WM_INITMENUPOPUP message. On SmartPhone, however, it does not but instead CFrameWnd:SurprisenInitMenuPopup is called (which doesn't seem to happen on PocketPC).

    I tried adding OnInitMenuPopup to my code (along with the ON_WM_INITMENUPOPUP() line in the message map), but as expected it did not work (as it would require the WM_INITMENUPOPUP message to be received in the first place - which it doesn't )


    As for the smartphone style menu, I am already using that. In my application the menu is created this way:

        SHMENUBARINFO mbi;
        memset(&mbi, 0, sizeof(SHMENUBARINFO));
        mbi.cbSize     = sizeof(SHMENUBARINFO);
        mbi.hwndParent = m_hWnd;
        mbi.nToolBarId = nMenuTemplateID;
        mbi.hInstRes   = ::AfxGetInstanceHandle();

        SHCreateMenuBar(&mbi);

    (nMenuTemplateID is one of three generic menus which I then modify corresponding to what I need in the window).

    Creating a clear smartphone C++ project and adding the OnInitMenuPopup message shows that it is working. However the default project code uses a CCommandBar and not SHMENUBAR, and I would actually prefer to not switch to CCommandBar for the menus.


    Daniel

    Wednesday, June 13, 2007 6:19 AM
  • Hi again,

    I've now solved the problem by adding an OnInitMenuPopup function to my main frame derived class and if on smartphone, calling the corresponding function in the currently active window of my application.

    Code Snippet

    void CMainFrame::OnInitMenuPopup(CMenu* pMenu, UINT nIndex, BOOL bSysMenu) {
        CFrameWnd::OnInitMenuPopup(pMenu, nIndex, bSysMenu);

        if (isSmartPhone && !bSysMenu) {
            CMyDialog* currentDlg = m_wndView.GetCurrentDialog();
            currentDialog->OnInitMenuPopup(pMenu->m_hMenu, nIndex, bSysMenu);
        }
    }


    Daniel
    Wednesday, June 13, 2007 8:01 AM