HMENU Question

Ok i would like to Simulate a Menu Click the menu is

File Tools Help

and under Tools

   | Something
   | Something
   | Something

I would like to Simulate the Cliciking of the 2nd button. Im stuck i dont know how to do it i got this so far

#include <windows.h>
#include <stdio.h>

typedef struct tagMENUITEMINFO {
  UINT    cbSize;
  UINT    fMask;
  UINT    fType;
  UINT    fState;
  UINT    wID;
  HMENU   hSubMenu;
  HBITMAP hbmpChecked;
  HBITMAP hbmpUnchecked;
  ULONG_PTR dwItemData;
  LPTSTR  dwTypeData;
  UINT    cch;
  HBITMAP hbmpItem;

int main(void) {
      int idk;
      HWND mWnd = FindWindow(NULL,"mIRC");
      HMENU mymenu = GetMenu(mWnd);
      return 1;

Now what do i do i get some errors also

C:\Documents and Settings\Haso\Desktop\menu\menu.cpp(17) : error C2371: 'MENUITEMINFO' : redefinition; different basic types
        c:\program files\microsoft visual studio\vc98\include\winuser.h(5167) : see declaration of 'MENUITEMINFO'
C:\Documents and Settings\Haso\Desktop\menu\menu.cpp(17) : error C2371: 'LPMENUITEMINFO' : redefinition; different basic types
        c:\program files\microsoft visual studio\vc98\include\winuser.h(5168) : see declaration of 'LPMENUITEMINFO'
C:\Documents and Settings\Haso\Desktop\menu\menu.cpp(24) : error C2664: 'GetMenuItemInfoA' : cannot convert parameter 4 from 'int' to 'struct tagMENUITEMINFOA *'
        Conversion from integral type to pointer type requires reinterpret_cast, C-style cast or function-style cast
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

For starters, you don't need to define MENUITEMINFO thing yourself since #include <windows.h> would already give you that...
The first two errors are generated because windows.h already includes winuser.h, which contains the definition of the tagMENUITEMINFO structure. Therefore, you need to remove the definition from your source.

The last error is because the fourth parameter passed to GetMenuItemInfoA should be a pointer to a MENUITEMINFO structure that specifies the information to retrieve and receives information about the menu item.


  Nayer Naguib
The basic technique is to get the ID of the menu item you'd like to click, and then send a WM_COMMAND message to the main window with this ID. For example:

  HWND mWnd = FindWindow(NULL,"mIRC");
  HMENU pMenu = GetMenu(mWnd); // gets the menu handle
  HMENU pSubMenu = GetSubMenu(pMenu, 1);   // get "Tools" submenu ( 0 = File, 1 = Tools, 2 = Help, ...etc)
  UINT menuID = GetMenuItemID(pSubMenu, 0); // get first item under tools (0 means first item)
  SendMessage(mWnd, WM_COMMAND, menuID, 0);

This code will of course only work if you know exactly which item # you need to click.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.