I'm trying to write a simple hook (a harmless one, though).
Code:
#include <windows.h>
#include <stdio.h>
int main(){
HWND hwnd;
HMENU menu;
HMENU subMenu;
hwnd = FindWindow("Notepad","Untitled - Notepad");
if (!hwnd) {
printf("Notepad is not running yet!!\n");
exit(0);
}
else {
ShowWindow(hwnd,SW_SHOWNORMAL);
SetForegroundWindow(hwnd);
menu = GetMenu(hwnd);
subMenu = CreateMenu();
AppendMenu(subMenu, MF_STRING | MF_POPUP, 100, "Bar");
AppendMenu(menu, MF_STRING, (UINT)subMenu, "Foo");
}
return 0;
}
The code manages to append the menu "Foo" to notepad.
Unfortunately, the "Bar" submenu (under "Foo") is not shown.
What's wrong here?