c++ - 错误 C2664 'HWND FindWindowExW (HWND, HWND, LPCWSTR, LPCWSTR)':参数 4 不能从 'bool' 转换为 'LPCWSTR'
问题描述
我在互联网上找到并稍作编辑的代码中出现此错误的原因是什么?
代码在这里:
#include <windows.h>
#include <windowsx.h>
#include <winuser.h>
#include <tchar.h>
BOOL CALLBACK EnumWindowsProc(HWND hwnd, LPARAM lParam)
{
HWND p = FindWindowEx(hwnd, NULL, _T("SHELLDLL_DefView"), false);
HWND* ret = (HWND*)lParam;
if (p) {
// Gets the WorkerW Window after the current one.
*ret = FindWindowEx(NULL, hwnd, _T("WorkerW"), NULL);
}
return true;
}
HWND get_wallpaper_window()
{
// Fetch the Progman window
HWND progman = FindWindow(_T("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, NULL);
// 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 = NULL;
EnumWindows(EnumWindowsProc, (LPARAM)&wallpaper_hwnd);
// Return the handle you're looking for.
return wallpaper_hwnd;
}
解决方案
错误消息抱怨您将 a 传递bool
给 的第四个参数FindWindowEx()
,这是一个LPCWSTR
( const wchar_t*
) 指针。Abool
不能隐式转换为指针。
当调用FindWindowEx()
查找窗口时,您正在"SHELLDLL_DefView"
传递参数。你所有的其他电话和正在通过。false
lpszWindow
FindWindow()
FindWindowEx()
NULL
所以简单地改变这个:
HWND p = FindWindowEx(hwnd, NULL, _T("SHELLDLL_DefView"), false);
为此:
HWND p = FindWindowEx(hwnd, NULL, _T("SHELLDLL_DefView"), NULL);
推荐阅读
- python - 使用列表理解和条件进行元素比较
- spring-boot - Spring Boot 服务器突然关闭
- apache - “RewriteRule ^.* /sitename:::144.html?[L,R=301]”实际上在做什么?
- r - 运行包“xlsx”时出现问题
- excel - 有没有办法在MS Word中插入包含UDF的excel而不会出错
- c++ - 我们如何准备小型内存池,其中每个线程可以独立访问特定范围的位置?
- php - 如何在 PHP 中操作文本以具有单引号和逗号
- json - 带双引号的 JSON 数据
- elasticsearch - 在具有多个节点的弹性搜索中创建快照时出现“只读文件系统”错误
- php - 文件获取内容花费太多时间