Win98 GetMenuItemCount returns -1
-
Hi everyone, I have a project with a menu on it and it notifies me by WM_MENUCOMMAND message.I had to do so,because my menu is dynamically created with values read from registry.Anyway,what I'm doing is theorically easy.This is the code for the WM_MENUCOMMAND event handler:
HMENU menu = (HMENU)lParam; // m_SystemVersionInfo is got with GetVersionEx,no problem if (m_SystemVersionInfo.dwMajorVersion <= 4) // Windows Me or Lower index = (int)(wParam >> 16); else index = (int)wParam; int nItems = GetMenuItemCount(menu); if (index == nItems - 1) // last item on menu { // do something } else { // do some other thing }
the code works fine on Win2K/XP but nItems shows -1 on Win98.the strange thing is GetLastError returns nothing.MSDN says you can not trust GetLastError on Win98 either,so I didn't bother to look up the eroor code (I am unable to debug on Win98). What could make GetMenuItemCount return -1 only on Win98? -
Hi everyone, I have a project with a menu on it and it notifies me by WM_MENUCOMMAND message.I had to do so,because my menu is dynamically created with values read from registry.Anyway,what I'm doing is theorically easy.This is the code for the WM_MENUCOMMAND event handler:
HMENU menu = (HMENU)lParam; // m_SystemVersionInfo is got with GetVersionEx,no problem if (m_SystemVersionInfo.dwMajorVersion <= 4) // Windows Me or Lower index = (int)(wParam >> 16); else index = (int)wParam; int nItems = GetMenuItemCount(menu); if (index == nItems - 1) // last item on menu { // do something } else { // do some other thing }
the code works fine on Win2K/XP but nItems shows -1 on Win98.the strange thing is GetLastError returns nothing.MSDN says you can not trust GetLastError on Win98 either,so I didn't bother to look up the eroor code (I am unable to debug on Win98). What could make GetMenuItemCount return -1 only on Win98?having tried the "excitinnnng" 'MessageBox Debugging' i've come to a conlcusion that the problem is lParam,which supposedly should carry the handle of the menu,does not carry the handle of the menu which it supposedly should carry... to get it clear: win98 can't give the correct menu handle for the message WM_MENUCOMMAND.i am unable to find which handle it shows but certainly it is not the right one. the problem should be that i am creating the menu at runtime,which changes the handle everytime the menu is opened,and dearest win98 can not update the handle.so any function that takes HMENU of the menu returns -1 with GetLastError 0. but i still need to use GetMenuItemInfo to take the string of the menu item at the correct index,but function also requires the HMENU (which win98 can't give correctly). any suggestions,anyone?