要解决“BeginDraw()在渲染目标上绘制时会覆盖状态栏 - 不能正确调整渲染目标的大小”的问题,可以尝试以下解决方法:
// 获取窗口的客户区大小
RECT clientRect;
GetClientRect(hWnd, &clientRect);
// 计算所需的渲染目标大小
int renderTargetWidth = clientRect.right - clientRect.left;
int renderTargetHeight = clientRect.bottom - clientRect.top;
// 创建渲染目标
ID2D1HwndRenderTarget* pRenderTarget;
D2D1_RENDER_TARGET_PROPERTIES props = D2D1::RenderTargetProperties();
props.pixelFormat = D2D1::PixelFormat(DXGI_FORMAT_UNKNOWN, D2D1_ALPHA_MODE_PREMULTIPLIED);
props.usage = D2D1_RENDER_TARGET_USAGE_GDI_COMPATIBLE;
D2D1_SIZE_U size = D2D1::SizeU(renderTargetWidth, renderTargetHeight);
D2D1CreateFactory(D2D1_FACTORY_TYPE_SINGLE_THREADED, __uuidof(ID2D1Factory), NULL, reinterpret_cast(&pD2DFactory));
pD2DFactory->CreateHwndRenderTarget(props, D2D1::HwndRenderTargetProperties(hWnd, size), &pRenderTarget);
// 创建渲染目标
ID2D1HwndRenderTarget* pRenderTarget;
D2D1_RENDER_TARGET_PROPERTIES props = D2D1::RenderTargetProperties();
props.pixelFormat = D2D1::PixelFormat(DXGI_FORMAT_UNKNOWN, D2D1_ALPHA_MODE_PREMULTIPLIED);
props.usage = D2D1_RENDER_TARGET_USAGE_GDI_COMPATIBLE;
D2D1CreateFactory(D2D1_FACTORY_TYPE_SINGLE_THREADED, __uuidof(ID2D1Factory), NULL, reinterpret_cast(&pD2DFactory));
pD2DFactory->CreateHwndRenderTarget(props, D2D1::HwndRenderTargetProperties(hWnd, D2D1::SizeU(), D2D1_WINDOW_STATE_NONE), &pRenderTarget);
这些解决方法可以确保渲染目标的大小调整正确,并避免覆盖状态栏。请根据您的实际需求选择适合的解决方法。