#c #winapi
Вопрос:
Когда я пытаюсь запустить код, который я нашел в Интернете, я получаю следующие ошибки:
Ошибка C2601 «get_wallpaper_window»: Определения собственных функций недопустимы
Ошибка 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)amp;wallpaper_hwnd);
// Return the handle you're looking for.
return wallpaper_hwnd;
}
}
Спасибо
Комментарии:
1. Это не C . Пожалуйста, используйте правильные теги для вопроса.
2. Снова и снова один и тот же вопрос.
Ответ №1:
Вы определяете свои EnumWindowsProc()
функции и get_wallpaper_window()
внутри button1_Click_2()
функции. C этого не допускает, и именно об этом говорят ошибки компилятора. Функции необходимо перенести за пределы, например
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)amp;wallpaper_hwnd);
// Return the handle you're looking for.
return wallpaper_hwnd;
}
Void button1_Click_2(System::Object^ sender, System::EventArgs^ e)
{
get_wallpaper_window();
}