我始终没有办法得到另一个程序中的右键菜单的句柄,我真怀疑这个东西是否存在
我的目的是点击另一个程序中右键菜单的某一项,给个demo当然更好了

解决方案 »

  1.   

    when u click the menuitem . the system send a message wm_command,
    so one method is get the menu's id . and send a message wm_command to the wnd.  it's will run
      

  2.   

    你要用spy++先把句柄找到,然后的我就不说了
      

  3.   

    消息又不是发给菜单的...
    你得到菜单项的ID后发wm_command给窗口
      

  4.   

    不会吧,消息不是发给菜单的,使发给窗体的。
    用spyxx来坚试消息,用vc打开exe文件,看看他的菜单id也行。
      

  5.   

    但是有个问题啊,这个菜单是一个从listview子类化后的一个控件,每个条目的右键菜单中的项目是不一样的,我想通过获得菜单上某一个项的文字来判断是选哪一项.能够得到文字吗
     我试过发送wm_command消息到窗口,可以的,很感谢,但是我同样是没有菜单的句柄的.问题解决,马上给分,分不够可以再加
      

  6.   

    是这样的,我看sdk中的菜单函数都需要菜单的句柄来工作(我知道是废话:-))
    我要点击的菜单的条目数和内容都是变化的,如果有菜单句柄我就可以通过它来得到菜单的数目或者是内容,当然如果本来就是创建了很多的右键菜单而是分别显示的话,那就更好.我在msdn和sdk里面都找不到获得contextmemu句柄的办法,不知道是怎么回事
      

  7.   

    1.启动spy++
    2.在另一个程序中选右键菜单的第一项
    3.在spy++中找2中对应的消息(窗口句柄及消息参数)
    4.用SendMessage给3中的窗口发消息
    other:没法监视文字(它可能不是传统意义上的菜单),还是监视消息参数比较好.
      

  8.   

    use resource functions(EnumResourceNames ...) to find menu of an exe
    Creating a Resource List
    The following example creates a list of every resource in the Hand.exe file. The list is written to the Resinfo.txt file. The code demonstrates how to load the executable file, create a file in which to write resource information, and call the EnumResourceTypes function to send each resource type found in the module to the application-defined callback function EnumTypesFunc. See EnumResTypeProc for information on callback functions of this type. This callback function uses the EnumResourceNames function to pass the name of every resource within the specified type to another application-defined callback function, EnumNamesFunc. See EnumResNameProc for information on callback functions of this type. EnumNamesFunc uses the EnumResourceLanguages function to pass the language of every resource of the specified type and name to a third callback function, EnumLangsFunc. See EnumResLangProc for information on callback functions of this type. EnumLangsFunc writes information about the resource of the specified type, name, and language to the Resinfo.txt file. Note that the lpszType in EnumResTypeProc is either a resource ID or a pointer to a string (containing a resource ID or type name); lpszType and lpszName in EnumResNameProc are similar. To use an enumerated resource, take the resource name or ID and call the appropriate function. For example, to load a string resource (RT_STRING), if lpszName in EnumResNameProc gives the resource ID (either directly or in a string that starts with the pound sign (#)), call LoadString. Otherwise, lpszName points to a string containing the resource name, so do the following: call FindResource or FindResourceEx with the resource name to get the resource handle; 
    call LoadResource with the resource handle to get the global handle; 
    call LockResource with the global handle to get a pointer to the resource data. 
    The Updating Resources code follows a similar pattern for a dialog box resource. char szBuffer[80]; // print buffer for EnumResourceTypes 
    DWORD cbWritten;   // number of bytes written to res. info. file 
    int cbString;      // length of string in sprintf 
     
    // Declare callback functions. 
    BOOL EnumTypesFunc( 
        HANDLE hModule, 
        LPTSTR lpType, 
        LONG lParam); 
     
    BOOL EnumNamesFunc( 
        HANDLE hModule, 
        LPCTSTR lpType, 
        LPTSTR lpName, 
        LONG lParam); 
     
    BOOL EnumLangsFunc( 
        HANDLE hModule, 
        LPCTSTR lpType, 
        LPCTSTR lpName, 
        WORD wLang, 
        LONG lParam); 
     
    // Load the .EXE whose resources you want to list. 
    hExe = LoadLibrary("hand.exe"); 
    if (hExe == NULL) 

        ErrorHandler("Could not load .EXE."); 

     
    // Create a file to contain the resource info. 
    hFile = CreateFile("resinfo.txt",      // name of file 
        GENERIC_READ | GENERIC_WRITE,      // access mode 
        0,                                 // share mode 
        (LPSECURITY_ATTRIBUTES) NULL,      // no security 
        CREATE_ALWAYS,                     // create flags 
        FILE_ATTRIBUTE_NORMAL,             // file attributes 
        (HANDLE) NULL);                    // no template 
    if (hFile == INVALID_HANDLE_VALUE) { 
        ErrorHandler("Could not open file."); 

     
    // Find all of the loaded file's resources. 
    cbString = sprintf(szBuffer, 
        "The file contains the following resources:\n\n"); 
    WriteFile(hFile,           // file to hold resource info. 
        szBuffer,              // what to write to the file 
        (DWORD) cbString,      // number of bytes in szBuffer 
        &cbWritten,            // number of bytes written 
        NULL);                 // no overlapped I/O 
     
    EnumResourceTypes(hExe,              // module handle 
        (ENUMRESTYPEPROC)EnumTypesFunc,  // callback function 
        0);                              // extra parameter 
    // Unload the executable file whose resources were 
    // enumerated and close the file created to contain 
    // the resource information. 
    FreeLibrary(hExe); 
    CloseHandle(hFile); 
     
    //    FUNCTION: EnumTypesFunc(HANDLE, LPSTR, LONG) 
    // 
    //    PURPOSE:  Resource type callback 
    BOOL EnumTypesFunc( 
        HANDLE hModule,   // module handle 
        LPTSTR lpType,    // address of resource type 
        LONG lParam)      // extra parameter, could be 
                          // used for error checking 

        int cbString; 
        // Write the resource type to a resource information file. 
        // The type may be a string or an unsigned decimal 
        // integer, so test before printing. 
        if ((ULONG)lpType & 0xFFFF0000) 
        { 
            cbString = sprintf(szBuffer, "Type: %s\n", lpType); 
        } 
        else 
        { 
            cbString = sprintf(szBuffer, "Type: %u\n", (USHORT)lpType); 
        } 
     
        WriteFile(hFile, szBuffer, (DWORD) cbString, 
            &cbWritten, NULL); 
        // Find the names of all resources of type lpType. 
        EnumResourceNames(hModule, 
            lpType, 
            (ENUMRESNAMEPROC)EnumNamesFunc, 
            0); 
     
        return TRUE; 

     
    //    FUNCTION: EnumNamesFunc(HANDLE, LPSTR, LPSTR, LONG) 
    // 
    //    PURPOSE:  Resource name callback 
    BOOL EnumNamesFunc( 
        HANDLE hModule,   // module handle 
        LPCTSTR lpType,   // address of resource type 
        LPTSTR lpName,    // address of resource name 
        LONG lParam)      // extra parameter, could be 
                          // used for error checking 

        int cbString; 
         // Write the resource name to a resource information file. 
         // The name may be a string or an unsigned decimal 
         // integer, so test before printing. 
        if ((ULONG)lpName & 0xFFFF0000) 
        { 
            cbString = sprintf(szBuffer, "\tName: %s\n", lpName); 
        } 
        else 
        { 
            cbString = sprintf(szBuffer, "\tName: %u\n", 
                (USHORT)lpName); 
        } 
     
        WriteFile(hFile, szBuffer, (DWORD) cbString, 
            &cbWritten, NULL); 
         // Find the languages of all resources of type 
         // lpType and name lpName. 
        EnumResourceLanguages(hModule, 
            lpType, 
            lpName, 
            (ENUMRESLANGPROC)EnumLangsFunc, 
            0); 
     
        return TRUE; 

     
    //    FUNCTION: EnumLangsFunc(HANDLE, LPSTR, LPSTR, WORD, LONG) 
    // 
    //    PURPOSE:  Resource language callback 
    BOOL EnumLangsFunc( 
        HANDLE hModule,  // module handle 
        LPCTSTR lpType,  // address of resource type 
        LPCTSTR lpName,  // address of resource name 
        WORD wLang,      // resource language 
        LONG lParam)     // extra parameter, could be 
                         // used for error checking 

        HANDLE hResInfo; 
        char szBuffer[80]; 
        int cbString = 0; 
     
        hResInfo = FindResourceEx(hModule, lpType, lpName, wLang); 
        // Write the resource language to the resource information file. 
        cbString = sprintf(szBuffer, "\t\tLanguage: %u\n", (USHORT)wLang); 
        WriteFile(hFile, szBuffer, (DWORD) cbString, 
            &cbWritten, NULL); 
        // Write the resource handle and size to buffer. 
        cbString = sprintf(szBuffer, 
            "\t\thResInfo == %lx,  Size == %lu\n\n", 
            hResInfo, 
            SizeofResource(hModule, hResInfo)); 
        WriteFile(hFile, szBuffer, (DWORD) cbString, 
            &cbWritten, NULL); 
        return TRUE;