C Board  

Go Back   C Board > Platform Specific Boards > Windows Programming

Reply
 
LinkBack Thread Tools Display Modes
Old 01-23-2010, 07:59 AM   #1
TmX
Registered User
 
Join Date: Sep 2006
Posts: 11
How to use CreateMenu and AppendMenu

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?
TmX is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Forum Jump


All times are GMT -6. The time now is 12:14 PM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.2

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22