0

I need to create some dynamic menus in a VS2010 SDI application I'm writing. I've seen this, but don't really understand it Dynamic menu using mfc

At the moment, I've no idea how to even use GetMenu to get a handle to the menu from my Doc file. I'm trying this, but it says GetMenu doesn't take zero arguments, even though many examples I've seen clearly show this.

CMenu *menu = GetMenu();


        menu->AppendMenu(MF_STRING, ID_HIDE, _T("Text"));

All I want to do is add a list of files underneath a sub-menu, selected from a database (hence the dynamic part), so a user can select the one they want to work on.

Thanks, James

Community
  • 1
  • 1
James
  • 1,764
  • 5
  • 31
  • 49
  • I believe it takes a `HWND` so it knows which menu to get. – chris Jun 20 '12 at 16:34
  • Hi,If you can tell me how I'd go about doing that I'd very grateful? – James Jun 20 '12 at 16:44
  • You could use a variety of things, including `FindWindow` to get the handle. I'm not sure what all mfc offers for that, but then you can just pass the `HWND` in. For the submenus, you can use `GetSubMenu`. – chris Jun 20 '12 at 16:45

1 Answers1

1

If you're calling GetMenu from within a window class derived from CWnd, you'll be calling CWnd::GetMenu and it will not require a window handle. If you're calling it from anywhere else you will get ::GetMenu(HWND) and you will need to pass a window handle. You can get the handle from any CWnd object with its m_hWnd member or by calling GetSafeHwnd() on it.

Mark Ransom
  • 299,747
  • 42
  • 398
  • 622
  • I found this site which is very useful for showing how to get at teh different object types, http://forums.codeguru.com/showthread.php?281430-MFC-Doc-View-How-to-obtain-a-pointer-to-various-objects – James Jun 21 '12 at 08:19