473,386 Members | 1,823 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

How to get the text of a menu item that's clicked.

Hi,
i m hooking the messages that come whenever any menu item is clicked. This is done on a global scale i.e. it handles all the msgs generated for any appln.
Now i 've to do this thing for only the "Help" menu item, as this is the most common one. I want to check whether the clicked menu item has the "Help" caption or not. This can't be done with the ID, as diff appln have different CtrlIDs. I think it can be done using the GetMenuItemInfo (). Butsomehow i'm not able to fill up MENUITEMINFO struct. Heres the code snippet i'm using.


if (lMsg->message == WM_MENUSELECT)
{
if ((HIWORD(lMsg->wParam) == 1))
{
TCHAR strText[MAX_S] = {0};
HWND hItem = GetDlgItem ((HWND)lMsg->lParam, LOWORD (lMsg->wParam));
GetWindowText(hItem, strText, MAX_S);
if(_tcscmp(strText, _T("&Help")) == 0)
{
MessageBox (NULL, _T("Press F1"), _T("Help Hooked."), MB_OK);
}
}
}

here i always receive "strText" as blank.

I've also tried using GetMenuItemInfo () like this.

PMSG lMsg = (PMSG) (lParam); // lParam is received in SysMsgProc
HMENU hMenu = (HMENU) lMsg->lParam;
MII.cbSize = sizeof (MENUITEMINFO);
bVal = GetMenuItemInfo (hMenu, LOWORD(lMsg->wParam), FALSE, &MII);

but bVal is always zero.

Folks Plz help me out. I m stuck like anything.
Dec 7 '07 #1
2 3124
Studlyami
464 Expert 256MB
MSDN states ". However, GetWindowText cannot retrieve the text of a control in another application".

What does the code look like for trying to grab the menu information?
Did you grab the HMenu item first? HMENU GetMenu(HWND hWnd) in you GetMenuItemInfo?
Dec 8 '07 #2
Hi,

HMENU is the lParam of lMsg.

I am trying to get the clicked menu item's info after obtaining the menu info.

I am done with that. I made GetMenuItemInfo work by the menu item index way.

Thanx.
Dec 11 '07 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: yxq | last post by:
Hi I am build vb6 Context menu extension, but how to determine which popup menu item(popupItem1 and popupItem2) was clicked? Thanks The code ' ' IContextMenu::QueryContextMenu '
3
by: André Nogueira | last post by:
Hi there! I have successfully create my own ownerdrawn menus. However, I decided to add some code for the menus to detect if their parent is a MainMenu object and, if it is, as it is the menuitem...
1
by: Dino Buljubasic | last post by:
Hi, I have a toolbar with several buttons on it, one of which is set up to be as a DropDown button. I also have a context menu with menu items assigend to it so when I click that button, my...
1
by: Elliot | last post by:
The code creates two menu items at runtime and I want to be know which menu item was clicked in the Menuitems_Click procedure. Sender.Gettype.Name returns the value "MenuItem" only. Any help is...
5
by: james | last post by:
Hello, I am having a little trouble creating an event handler for a context menu toolstripmenuitem. I've seen various tutorials and so on, but I keep getting a bit stuck! So far I have a second...
12
by: tim | last post by:
I am using foldoutmenu 3 and am having problems with viewing my menus in firefox. On my sub3 menus i have more than one line of text in some places. firefox does not recognise that there is more...
0
by: EvilProject | last post by:
Hi im writing a class of a context menu where each menu item is linked to a Tree Node. I have a click event (that belongs to the context menu class ,not the menu item class) that it's event...
0
by: JamesOo | last post by:
I have the code below, but I need to make it searchable in query table, below code only allowed seach the table which in show mdb only. (i.e. have 3 table, but only can search either one only,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.