如题,我现在可以找到各菜单类似记事本中的“文件”“编辑”的句柄,现在只想对一个菜单项进行操作。类似于对记事本中的“文件”的新建进行操作。
及我点击,父窗体的某个按钮,就有点击子窗体中的某一菜单项的效果。
大家说说 可以实现吗?

解决方案 »

  1.   

    这个标准的方法是发WM_COMMAND消息,如果那菜单是在EXE资源里定义的,那你找个能查看资源的软件看下相应项的ID号是多少就行了.否则的话,用GetMenu,GetMenuItemID这些API好像也可得到.或者你用SPYXX HOOK一下那个WM_COMMAND试试MSDN中关于WM_COMMAND的部分:
    WM_COMMAND
    The WM_COMMAND message is sent when the user selects a command item from a menu, when a control sends a notification message to its parent window, or when an accelerator keystroke is translated. WM_COMMAND 
    wNotifyCode = HIWORD(wParam); // notification code 
    wID = LOWORD(wParam);         // item, control, or accelerator identifier 
    hwndCtl = (HWND) lParam;      // handle of control 
     
    Parameters
    wNotifyCode 
    Value of the high-order word of wParam. Specifies the notification code if the message is from a control. If the message is from an accelerator, this parameter is 1. If the message is from a menu, this parameter is 0. 
    wID 
    Value of the low-order word of wParam. Specifies the identifier of the menu item, control, or accelerator. 
    hwndCtl 
    Value of lParam. Handle to the control sending the message if the message is from a control. Otherwise, this parameter is NULL. 
    Return Values
    If an application processes this message, it should return zero. Res
    Accelerator keystrokes that select items from the window menu are translated into WM_SYSCOMMAND messages. If an accelerator keystroke occurs that corresponds to a menu item when the window that owns the menu is minimized, no WM_COMMAND message is sent. However, if an accelerator keystroke occurs that does not match any of the items in the window's menu or in the window menu, a WM_COMMAND message is sent, even if the window is minimized. If an application enables a menu separator, the system sends a WM_COMMAND message with the low-word of the wParam parameter set to zero when the user selects the separator.QuickInfo
      Windows NT: Requires version 3.1 or later.
      Windows: Requires Windows 95 or later.
      Windows CE: Requires version 1.0 or later.
      Header: Declared in winuser.h.See Also
    Edit Controls Overview, Edit Control Messages, WM_SYSCOMMAND  
      

  2.   

    顶一楼.另外二楼的自绘菜单应该不能使用标准方法获取.因为其并不是属于EXE中的静态资源,是动态生成的.具体没弄过,等待弄过的来吼一句.
      

  3.   

    我现在想这样做,如果正常运行该应用程序,
    1.用鼠标单击菜单中的“文件”会弹出下拉菜单,
    2.然后按键盘“向下键”一下
    3.然后按“ENTER键”
    就可以打开文件的框了,并且这就是我想要的。所以,当设置应用程序的窗体为子窗体后,我是不是可以这样:
    先获得“文件”的句柄,
    让子窗体获得焦点
    然后用windows消息,执行单击操作,
    然后发送键盘消息,是不是可以达到目的了?