Hi,
1) I am creating new MFC application using the Visual Studio "Add New Project" Wizard.
2) I run the created application without any changes.
Application has a main menu (File, Edit, View, Help).
3) When calling "GetMenu(HWND hWnd)" from another process, I get no menu.
It does works on other applications, like windows notepad.
* I use VS 2017 and 2008 - both same results. I tried MDI and SDI application - also the same.
This is my code.
#include <Windows.h>
#include <commctrl.h>
#include <stdio.h>
BOOL CALLBACK EnumWindowsProc(HWND hwnd, LPARAM lParam)
{
char class_name[80];
char title[80];
GetClassName(hwnd, class_name, sizeof(class_name));
GetWindowText(hwnd, title, sizeof(title));
HMENU hMenu = (HMENU)::GetMenu(hwnd);
int nMenuCount = GetMenuItemCount(hMenu);
if (nMenuCount > -1)
{
printf("Window title: %s\n", title);
printf("Class name: %s\n", class_name);
printf("Menu count is %d\n", nMenuCount);
printf("--------------------------------------\n");
}
return TRUE;
}
int main(int cargs, char** args)
{
EnumWindows(EnumWindowsProc, NULL);
return 0;
}
It will show the list of several programs, e.g.:
------------------------------------
Window title: Untitled - Notepad
Class name: Notepad
Menu count is 5
----------------------------------
But the MFC sample - no.
![]()
Regards,
Moti Wertheimer
Product Engineer