Menu at runtime (dynamic menu)
-
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 -
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 EletricistaLike this?
//your CFrameWnd / CMDIFrameWnd pMDIFrame->GetMenu()->>AppendMenu(MF\_SEPARATOR); pMyMDIFrame->DrawMenuBar();
Sonork 100.41263:Anthony_Yio Life is about experiencing ...
-
Like this?
//your CFrameWnd / CMDIFrameWnd pMDIFrame->GetMenu()->>AppendMenu(MF\_SEPARATOR); pMyMDIFrame->DrawMenuBar();
Sonork 100.41263:Anthony_Yio Life is about experiencing ...
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 -
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 EletricistaIt 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 ...
-
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 ...
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 -
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