HMENU Question

Posted on 2006-03-26
Last Modified: 2008-01-09
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
Question by:hasokeric
    LVL 6

    Expert Comment

    For starters, you don't need to define MENUITEMINFO thing yourself since #include <windows.h> would already give you that...
    LVL 14

    Expert Comment

    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
    LVL 6

    Accepted Solution

    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.
    LVL 14

    Expert Comment


    Featured Post

    IT, Stop Being Called Into Every Meeting

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    Join & Write a Comment

    Suggested Solutions

    Entering a date in Microsoft Access can be tricky. A typo can cause month and day to be shuffled, entering the day only causes an error, as does entering, say, day 31 in June. This article shows how an inputmask supported by code can help the user a…
    Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
    An introduction to basic programming syntax in Java by creating a simple program. Viewers can follow the tutorial as they create their first class in Java. Definitions and explanations about each element are given to help prepare viewers for future …
    Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

    755 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    17 Experts available now in Live!

    Get 1:1 Help Now