C++ C++;无法使用FindWindow()找到cmd #包括 #包括 使用名称空间std; int main() { HWND handle=FindWindow(“控制台窗口类”,“C:\WINDOWS\system32\cmd.exe”); if(handle==NULL) cout

C++ C++;无法使用FindWindow()找到cmd #包括 #包括 使用名称空间std; int main() { HWND handle=FindWindow(“控制台窗口类”,“C:\WINDOWS\system32\cmd.exe”); if(handle==NULL) cout,c++,c++11,visual-c++,C++,C++11,Visual C++,对于unicode,请尝试以下代码段: #include<iostream> #include<Windows.h> using namespace std; int main() { HWND handle = FindWindow("ConsoleWindowClass","C:\WINDOWS\system32\cmd.exe"); if (handle == NULL) cout << "Window not fou

对于unicode,请尝试以下代码段:

#include<iostream>
#include<Windows.h>

using namespace std;

int main()
{
    HWND handle = FindWindow("ConsoleWindowClass","C:\WINDOWS\system32\cmd.exe");
    if (handle == NULL)
        cout << "Window not found" << endl;
    else
        cout << "Window found " << endl;

    system("pause");
    return 0;

}

是更好的选择吗?GetConsoleWindow()将返回程序运行的当前cosole(cmd窗口)的句柄。我实际上想找到另一个控制台(cnd窗口)的句柄。你能解释一下为什么用“\\”而不是“\”吗……C++分析器和编译器理解这一方法。backslash@EzioBlaze反斜杠开始转义字符,例如“\n”,它是结束行字符。字符“\”的转义序列是“\ \”(单反斜杠)。如果没有第二个反斜杠,编译器会认为存在一个'\w',一个'\s',和一个'\c',这不是您想要的(单个反斜杠)。
HWND handle = FindWindow(L"ConsoleWindowClass", L"C:\\WINDOWS\\system32\\cmd.exe");