Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/163.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
FindWindow找不到窗口 我有一个计划,用C++编写一个简单的教练机控制台,但是第一步我发现了FunWistOW()/< #包括 #包括 #包括 #包括 #包括 LPCTSTR WindowName=“Mozilla Firefox”; HWND Find=FindWindow(NULL,WindowName); int main(){ 如果(查找) { printf(“找到的”\n); getch(); } 否则{ printf(“未找到”); getch(); } }_C++_Winapi_Visual C++ - Fatal编程技术网

FindWindow找不到窗口 我有一个计划,用C++编写一个简单的教练机控制台,但是第一步我发现了FunWistOW()/< #包括 #包括 #包括 #包括 #包括 LPCTSTR WindowName=“Mozilla Firefox”; HWND Find=FindWindow(NULL,WindowName); int main(){ 如果(查找) { printf(“找到的”\n); getch(); } 否则{ printf(“未找到”); getch(); } }

FindWindow找不到窗口 我有一个计划,用C++编写一个简单的教练机控制台,但是第一步我发现了FunWistOW()/< #包括 #包括 #包括 #包括 #包括 LPCTSTR WindowName=“Mozilla Firefox”; HWND Find=FindWindow(NULL,WindowName); int main(){ 如果(查找) { printf(“找到的”\n); getch(); } 否则{ printf(“未找到”); getch(); } },c++,winapi,visual-c++,C++,Winapi,Visual C++,上面的代码用于尝试命令FindWindow()但在执行时始终显示输出 找不到 我已从替换属性项目上的字符集 使用Unicode字符集 到 使用多字节字符集 及 LPCTSTR 到 LPCSTR 或 LPCWSTR 但是结果总是一样的,我希望任何人都能帮助我。FindWindow仅在窗口具有确切的指定标题时才查找该窗口,而不仅仅是子字符串 HWND Find = ::FindWindowEx(0, 0, "MozillaUIWindowClass", 0); 或者,您可以: 搜索窗口类名称:

上面的代码用于尝试命令FindWindow()但在执行时始终显示输出

找不到

我已从替换属性项目上的字符集

使用Unicode字符集

使用多字节字符集

LPCTSTR

LPCSTR

LPCWSTR


但是结果总是一样的,我希望任何人都能帮助我。

FindWindow
仅在窗口具有确切的指定标题时才查找该窗口,而不仅仅是子字符串

 HWND Find = ::FindWindowEx(0, 0, "MozillaUIWindowClass", 0);
或者,您可以:


搜索窗口类名称:

HWND hWnd = FindWindow("MozillaWindowClass", 0);

所有窗口,并对标题执行自定义模式搜索:

BOOL CALLBACK EnumWindowsProc(HWND hwnd, LPARAM lParam)
{
    char buffer[128];
    int written = GetWindowTextA(hwnd, buffer, 128);
    if (written && strstr(buffer,"Mozilla Firefox") != NULL) {
        *(HWND*)lParam = hwnd;
        return FALSE;
    }
    return TRUE;
}

HWND GetFirefoxHwnd()
{
    HWND hWnd = NULL;
    EnumWindows(EnumWindowsProc, &hWnd);
    return hWnd;
}

您需要使用应用程序的全名(如Windows任务管理器->应用程序选项卡中所示)

例如:

Google-Mozilla Firefox

(在Firefox中打开谷歌标签后)

根据

lpWindowName[输入,可选]

Type: LPCTSTR

The window name (the window's title). If this parameter is NULL, all window names match.
因此,您的WindowName不能是“Mozilla Firefox”,因为Firefox窗口的标题从来不是“Mozilla Firefox”,而是“Mozilla Firefox起始页-Mozilla Firefox”,或者取决于网页的名称。 下面是示例图片

因此,您的代码应该是这样的,(下面的代码只工作-只工作,如果您有确切的窗口标题名称:“Mozilla Firefox起始页-Mozilla Firefox”,如上图所示。我在Windows 8.1上测试过,它工作正常)


您确定窗口标题实际上是
Mozilla Firefox
?这不是书名吗?另外,这可能是
\T(“Mozilla Firefox”)
使用Spy++或其他东西,并确保它真的有这个标题。问题很明显,但实际上有一个窗口有这个确切的标题吗?我启动了Firefox,使用Spy++,但没有看到这样的窗口。此外,按标题搜索窗口充其量也是脆弱的。我不知道确切的标题窗口,但当光标悬停显示Mozilla Firefox时,FindWindow()与FindWindowEx()有什么区别??在C++中我是新的,这是CopsFunkWINDOWEX的任务,也可以搜索子窗口,从父窗口(可选地指定)开始。如果第一个参数为null,则函数将桌面窗口用作父窗口。该函数在作为桌面子窗口的窗口之间进行搜索。
Type: LPCTSTR

The window name (the window's title). If this parameter is NULL, all window names match.
void CaptureWindow()
{


RECT rc;
HWND hwnd = ::FindWindow(0, _T("Mozilla Firefox Start Page - Mozilla Firefox"));//::FindWindow(0,_T("ScreenCapture (Running) - Microsoft Visual Studio"));//::FindWindow(0, _T("Calculator"));//= FindWindow("Notepad", NULL);    //You get the ideal?
if (hwnd == NULL)
{
    return;
}
GetClientRect(hwnd, &rc);

//create
HDC hdcScreen = GetDC(NULL);
HDC hdc = CreateCompatibleDC(hdcScreen);
HBITMAP hbmp = CreateCompatibleBitmap(hdcScreen,
    rc.right - rc.left, rc.bottom - rc.top);
SelectObject(hdc, hbmp);

//Print to memory hdc
PrintWindow(hwnd, hdc, PW_CLIENTONLY);

//copy to clipboard
OpenClipboard(NULL);
EmptyClipboard();
SetClipboardData(CF_BITMAP, hbmp);
CloseClipboard();

//release
DeleteDC(hdc);
DeleteObject(hbmp);
ReleaseDC(NULL, hdcScreen);

//Play(TEXT("photoclick.wav"));//This is just a function to play a sound, you can write it yourself, but it doesn't matter in this example so I comment it out.
}