Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/134.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++ 错误C2601';EnumWindowsProc';:本地函数定义无效_C++_Winapi - Fatal编程技术网

C++ 错误C2601';EnumWindowsProc';:本地函数定义无效

C++ 错误C2601';EnumWindowsProc';:本地函数定义无效,c++,winapi,C++,Winapi,当我尝试运行从internet上找到的代码时,出现以下错误: 错误C2601“获取壁纸窗口”:本机函数定义无效 错误C2601“EnumWindowsProc”:本地函数定义无效 错误C2065“EnumWindowsProc”:未声明的标识符 错误(活动)E0065应为“;” 我没有太多的编码知识,所以我真的不理解错误,如果你能帮助我,我将不胜感激。 代码如下: Void button1_Click_2(System::Object^ sender, System::EventArgs^ e)

当我尝试运行从internet上找到的代码时,出现以下错误:

错误C2601“获取壁纸窗口”:本机函数定义无效

错误C2601“EnumWindowsProc”:本地函数定义无效

错误C2065“EnumWindowsProc”:未声明的标识符

错误(活动)E0065应为“;”

我没有太多的编码知识,所以我真的不理解错误,如果你能帮助我,我将不胜感激。 代码如下:

Void button1_Click_2(System::Object^ sender, System::EventArgs^ e) {
BOOL CALLBACK EnumWindowsProc(HWND hwnd, LPARAM lParam)
{
    HWND p = FindWindowEx(hwnd, NULL, L"SHELLDLL_DefView", NULL);
    HWND* ret = (HWND*)lParam;

    if (p)
    {
        // Gets the WorkerW Window after the current one.
        *ret = FindWindowEx(NULL, hwnd, L"WorkerW", NULL);
    }
    return true;
}

HWND get_wallpaper_window()
{
    // Fetch the Progman window
    HWND progman = FindWindow(L"ProgMan", NULL);
    // Send 0x052C to Progman. This message directs Progman to spawn a 
    // WorkerW behind the desktop icons. If it is already there, nothing 
    // happens.
    SendMessageTimeout(progman, 0x052C, 0, 0, SMTO_NORMAL, 1000, nullptr);
    // We enumerate all Windows, until we find one, that has the SHELLDLL_DefView 
    // as a child. 
    // If we found that window, we take its next sibling and assign it to workerw.
    HWND wallpaper_hwnd = nullptr;
    EnumWindows(EnumWindowsProc, (LPARAM)&wallpaper_hwnd);
    // Return the handle you're looking for.
    return wallpaper_hwnd;
}
}

谢谢

您正在定义
EnumWindowsProc()
get\u wallpaper\u window()
函数
按钮1\u Click\u 2()
函数的内部。C++不允许,这正是编译器错误所说的。这些功能需要移到外面,例如

BOOL回调EnumWindowsProc(HWND-HWND,LPARAM-LPARAM)
{
HWND p=FindWindowEx(HWND,NULL,L“SHELLDLL_devview”,NULL);
HWND*ret=(HWND*)LPRAM;
如果(p)
{
//获取当前窗口之后的WorkerW窗口。
*ret=FindWindowEx(NULL,hwnd,L“WorkerW”,NULL);
}
返回true;
}
HWND获得壁纸和窗口()
{
//从Progman窗口取回
HWND progman=FindWindow(L“progman”,NULL);
//将0x052C发送给Progman。此消息指示Progman生成
//WorkerW位于桌面图标后面。如果它已经在那里,则什么也没有
//发生了。
SendMessageTimeout(progman,0x052C,0,0,SMTO_NORMAL,1000,nullptr);
//我们枚举所有窗口,直到找到一个具有SHELLDLL\u deView的窗口
//小时候。
//如果我们找到了那个窗口,我们就把它的下一个兄弟节点分配给workerw。
HWND墙纸_HWND=nullptr;
EnumWindows(EnumWindowsProc,(LPRAM)和墙纸);
//把你要找的把手还给我。
归还壁纸;
}
无效按钮1\u单击\u 2(系统::对象^sender,系统::事件参数^e)
{
获取壁纸和窗口();
}

<代码>这不是C++。请对问题使用正确的标签。一次又一次地回答同一个问题。