Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Menu at runtime (dynamic menu)

Menu at runtime (dynamic menu)

Scheduled Pinned Locked Moved C / C++ / MFC
helpc++designquestion
6 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    marcosvpp
    wrote on last edited by
    #1

    Hi, I have a class (CVidCap) that I developed to grab frames from a Webcam and I want to make this a "dialog independent" class. When this class is created it populate a CMenu (MFC) object with all Webcam available in the system and i design a function that append this CMenu object in an application MenuBar. The problem is that when the CMenu object is attached, it is alweys GRAYED, and I can't handle any mouse button press in my class. I'm trying to handle the application events in my independent class without insert any code in the application MESSAGE_MAP. I was clearly? BEGIN_MESSAGE_MAP(CMainFrame, CFrameWnd) //{{AFX_MSG_MAP(CMainFrame) ON_COMMAND(ID_TESTE_B, OnTesteB) //}}AFX_MSG_MAP END_MESSAGE_MAP() I try to add a message map in my class but didn't work. :( If anybody could help, I'll appreciate! Thanks, and sory my english! :) Marcos Vinícius Engenheiro Eletricista

    A 1 Reply Last reply
    0
    • M marcosvpp

      Hi, I have a class (CVidCap) that I developed to grab frames from a Webcam and I want to make this a "dialog independent" class. When this class is created it populate a CMenu (MFC) object with all Webcam available in the system and i design a function that append this CMenu object in an application MenuBar. The problem is that when the CMenu object is attached, it is alweys GRAYED, and I can't handle any mouse button press in my class. I'm trying to handle the application events in my independent class without insert any code in the application MESSAGE_MAP. I was clearly? BEGIN_MESSAGE_MAP(CMainFrame, CFrameWnd) //{{AFX_MSG_MAP(CMainFrame) ON_COMMAND(ID_TESTE_B, OnTesteB) //}}AFX_MSG_MAP END_MESSAGE_MAP() I try to add a message map in my class but didn't work. :( If anybody could help, I'll appreciate! Thanks, and sory my english! :) Marcos Vinícius Engenheiro Eletricista

      A Offline
      A Offline
      Anthony_Yio
      wrote on last edited by
      #2

      Like this?

          //your CFrameWnd / CMDIFrameWnd
          pMDIFrame->GetMenu()->>AppendMenu(MF\_SEPARATOR);
      pMyMDIFrame->DrawMenuBar();
      

      Sonork 100.41263:Anthony_Yio Life is about experiencing ...

      M 1 Reply Last reply
      0
      • A Anthony_Yio

        Like this?

            //your CFrameWnd / CMDIFrameWnd
            pMDIFrame->GetMenu()->>AppendMenu(MF\_SEPARATOR);
        pMyMDIFrame->DrawMenuBar();
        

        Sonork 100.41263:Anthony_Yio Life is about experiencing ...

        M Offline
        M Offline
        marcosvpp
        wrote on last edited by
        #3

        Yes, I try this, but the menu that I append is still grayed!!! CMenu *Menu = Wnd->GetMenu(); hr = Menu->InsertMenu(Position, MF_BYPOSITION | MF_STRING | MF_POPUP | MF_ENABLED, (UINT)DevicesMenu->m_hMenu, TEXT("Devices")); Menu->Detach(); Wnd->DrawMenuBar(); The only way that they work properly is to add in the AppClass file MESSAGE_MAP the code: // file "MyApp.cpp" BEGIN_MESSAGE_MAP(CTe13App, CWinApp) //{{AFX_MSG_MAP(CTe13App) ON_COMMAND(ID_APP_ABOUT, OnAppAbout) ON_COMMAND(ID_PAUSE, OnPause) //}}AFX_MSG_MAP // My message map ON_COMMAND_RANGE(ID_MENU_DIALOG0, ID_MENU_DIALOG9, OnDialog) END_MESSAGE_MAP() but I don't want to do this. I need to be App independent; to be an independent class!! Is there a way that adding a message map in my class, the app message map understand? Like this: // file "MyClass.cpp" BEGIN_MESSAGE_MAP(CVidCap, CWnd) ON_COMMAND_RANGE(ID_MENU_DIALOG0, ID_MENU_DIALOG9, OnDialog) END_MESSAGE_MAP() Thanks Marcos Vinícius Engenheiro Eletricista

        A 1 Reply Last reply
        0
        • M marcosvpp

          Yes, I try this, but the menu that I append is still grayed!!! CMenu *Menu = Wnd->GetMenu(); hr = Menu->InsertMenu(Position, MF_BYPOSITION | MF_STRING | MF_POPUP | MF_ENABLED, (UINT)DevicesMenu->m_hMenu, TEXT("Devices")); Menu->Detach(); Wnd->DrawMenuBar(); The only way that they work properly is to add in the AppClass file MESSAGE_MAP the code: // file "MyApp.cpp" BEGIN_MESSAGE_MAP(CTe13App, CWinApp) //{{AFX_MSG_MAP(CTe13App) ON_COMMAND(ID_APP_ABOUT, OnAppAbout) ON_COMMAND(ID_PAUSE, OnPause) //}}AFX_MSG_MAP // My message map ON_COMMAND_RANGE(ID_MENU_DIALOG0, ID_MENU_DIALOG9, OnDialog) END_MESSAGE_MAP() but I don't want to do this. I need to be App independent; to be an independent class!! Is there a way that adding a message map in my class, the app message map understand? Like this: // file "MyClass.cpp" BEGIN_MESSAGE_MAP(CVidCap, CWnd) ON_COMMAND_RANGE(ID_MENU_DIALOG0, ID_MENU_DIALOG9, OnDialog) END_MESSAGE_MAP() Thanks Marcos Vinícius Engenheiro Eletricista

          A Offline
          A Offline
          Anthony_Yio
          wrote on last edited by
          #4

          It is not neccessary to have your handler in your app class. For instance, you can catch your menu item handler in your View. You can have it in your CDialog , CView or CFrameWnd. Just make sure your menu ID constant to be included in the source. Sonork 100.41263:Anthony_Yio Life is about experiencing ...

          M 1 Reply Last reply
          0
          • A Anthony_Yio

            It is not neccessary to have your handler in your app class. For instance, you can catch your menu item handler in your View. You can have it in your CDialog , CView or CFrameWnd. Just make sure your menu ID constant to be included in the source. Sonork 100.41263:Anthony_Yio Life is about experiencing ...

            M Offline
            M Offline
            marcosvpp
            wrote on last edited by
            #5

            It means that I always have to put some extra-code in my CDialog, CView or CFrameWnd? I can't just make an object that handle the menu messages without put any extra-code? // MyApp.h ... private: CMyClass *MyObject; ... // MyApp.cpp ... BOOL MyApp::InitInstance() { // All I need? - All I want! MyObject = new CMyClass(); ... } Thanks Anthony Marcos Vinícius

            A 1 Reply Last reply
            0
            • M marcosvpp

              It means that I always have to put some extra-code in my CDialog, CView or CFrameWnd? I can't just make an object that handle the menu messages without put any extra-code? // MyApp.h ... private: CMyClass *MyObject; ... // MyApp.cpp ... BOOL MyApp::InitInstance() { // All I need? - All I want! MyObject = new CMyClass(); ... } Thanks Anthony Marcos Vinícius

              A Offline
              A Offline
              Anonymous
              wrote on last edited by
              #6

              Yes, it is possible, just that you need put in some effort. Check Programming Windows by Charles Petzold.

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups