Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/132.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 单击另一个应用程序的按钮失败_C++_Winapi - Fatal编程技术网

C++ 单击另一个应用程序的按钮失败

C++ 单击另一个应用程序的按钮失败,c++,winapi,C++,Winapi,我正在使用一个对话框窗口,它有三个按钮:“保存…”、“解密”和“确定”。根据Spy++,每个按钮都有类“XButton”。我试图从另一个应用程序中按“解密”,所以我会这样做: // "buffer" below contains dialog's caption hProgramWindow = FindWindowEx(NULL, NULL, NULL, buffer); // "caption" below contains string "Decrypt"

我正在使用一个对话框窗口,它有三个按钮:“保存…”、“解密”和“确定”。根据Spy++,每个按钮都有类“XButton”。我试图从另一个应用程序中按“解密”,所以我会这样做:

    // "buffer" below contains dialog's caption
    hProgramWindow = FindWindowEx(NULL, NULL, NULL, buffer);

    // "caption" below contains string "Decrypt"
    HWND hButton = FindWindowEx(hProgramWindow, NULL, TEXT("XButton"), caption);

    SetFocus(hProgramWindow);
    SetActiveWindow(hProgramWindow);

    PostMessage(hProgramWindow, WM_COMMAND,
            MAKEWORD(GetDlgCtrlID(hButton), BN_CLICKED), (LPARAM)hButton); 

    // After posting the message, GetLastError() returns "5" (Access denied),
    // but the button is clicked
标题
变量的值为“保存…”时,单击“保存…”按钮(仍然是GetLastError()=5),将显示相应的保存对话框。但是当
caption
变量的值为“Decrypt”时,不会单击“Decrypt”按钮,不会出现对话框。有什么建议,为什么会发生


顺便说一下,调用
EnableWindow(hButton,FALSE)
对于“Decrypt”按钮(以及“Save…”按钮)工作正常,它被禁用,这意味着句柄是正确的。

Decrypt按钮应该做什么?它应该打开一个标准的保存对话框窗口来保存解密的文件(实际上与“Save…”按钮相同,但它保存的是日志,而不是解密的文件).当你从第一个应用程序运行它时,它工作正常吗?嗯,当我用鼠标按“解密”(或“保存…”)时,它工作正常。但当我尝试从应用程序中“远程”单击按钮时,“保存…”效果很好,“解密”根本不起作用。从技术上讲,我看不出按钮之间的区别。但其中一个有效,另一个无效(?!)也许这与窗口的默认按钮有关。可以远程单击“确定”按钮吗?