[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 550
  • Last Modified:

HMENU Question

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

File Tools Help

and under Tools

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;
} MENUITEMINFO, *LPMENUITEMINFO;


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


Now what do i do i get some errors also


menu.cpp
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
0
hasokeric
Asked:
hasokeric
  • 2
  • 2
1 Solution
 
enwhyseeCommented:
For starters, you don't need to define MENUITEMINFO thing yourself since #include <windows.h> would already give you that...
0
 
nayernaguibCommented:
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
0
 
enwhyseeCommented:
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.
0
 
nayernaguibCommented:
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now