Я пытаюсь создать hwnd win32, а затем использовать Direct2D для его рисования (в приложении UWP), но получаю 0x887a0022 при вызове d2dFactory->CreateHwndRenderTarget. >
Тот же код работает и в обычном Win32-приложении, я не знаю, что конкретно для UWP, так как я включил недостающие lib.
Просто добавьте вызов функции Show() в событие Button.Click в MainPage.xaml, и это выполнение. Для простоты проигнорируйте, что он не использует шаблон RAII
#include "pch.h"
#include "D2DWindow.h"
#include
#pragma comment(lib, "d2d1.lib")
#pragma comment(lib, "gdi32.lib")
#pragma comment(lib, "user32.lib")
ID2D1Factory* d2dFactory{};
ID2D1SolidColorBrush* redBrush{};
ID2D1HwndRenderTarget* renderTarget{};
ID2D1PathGeometry* trianglePath{};
ID2D1GeometrySink* sink{};
inline void AssertHResult(HRESULT hr)
{
bool const succeed = SUCCEEDED(hr);
assert(succeed);
}
LRESULT CALLBACK WindowProc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
{
switch (msg)
{
case WM_CREATE:
{
AssertHResult(D2D1CreateFactory(D2D1_FACTORY_TYPE::D2D1_FACTORY_TYPE_SINGLE_THREADED, &d2dFactory));
RECT clientRect{};
GetClientRect(hwnd, &clientRect);
AssertHResult(d2dFactory->CreateHwndRenderTarget( //error here
D2D1::RenderTargetProperties(),
D2D1::HwndRenderTargetProperties(
hwnd,
{
.width = static_cast(clientRect.right - clientRect.left),
.height = static_cast(clientRect.bottom - clientRect.top)
}
),
&renderTarget
));
AssertHResult(renderTarget->CreateSolidColorBrush(D2D1::ColorF{ D2D1::ColorF::Red }, &redBrush));
AssertHResult(d2dFactory->CreatePathGeometry(&trianglePath));
AssertHResult(trianglePath->Open(&sink));
D2D1_POINT_2F const points[]
{
{0.f, 400.f},
{400.f, 400.f},
{200.f, 0.f}
};
sink->BeginFigure(points[0], D2D1_FIGURE_BEGIN::D2D1_FIGURE_BEGIN_FILLED);
sink->AddLines(points + 1, std::size(points) - 1);
sink->EndFigure(D2D1_FIGURE_END::D2D1_FIGURE_END_CLOSED);
sink->Close();
}
case WM_SIZE:
if (renderTarget)
renderTarget->Resize({ .width = LOWORD(lparam), .height = HIWORD(lparam) });
return 0;
case WM_PAINT:
renderTarget->BeginDraw();
renderTarget->Clear(D2D1::ColorF{ D2D1::ColorF::White });
renderTarget->FillGeometry(trianglePath, redBrush);
AssertHResult(renderTarget->EndDraw());
ValidateRect(hwnd, nullptr);
return 0;
case WM_DESTROY:
PostQuitMessage(0);
return 0;
default:
return DefWindowProc(hwnd, msg, wparam, lparam);
}
}
void D2DWindow::Create()
{
WNDCLASS const windowClass
{
.lpfnWndProc = WindowProc,
.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH),
.lpszClassName = L"UWP Win32"
};
RegisterClass(&windowClass);
int const width = 800;
int const height = 600;
HWND const hwnd = CreateWindowEx(
0,
windowClass.lpszClassName,
L"UWP Win32 window",
WS_OVERLAPPEDWINDOW,
0, 0,
width, height,
nullptr,
nullptr,
nullptr,
nullptr
);
ShowWindow(hwnd, SW_SHOW);
}
Подробнее здесь: https://stackoverflow.com/questions/793 ... t2d-in-uwp
Получите 0x887a0022 для CreateHwndRenderTarget с помощью Direct2D в UWP. ⇐ C++
-
- Похожие темы
- Ответы
- Просмотры
- Последнее сообщение
-
-
Как создать наложение, невидимое на скриншоте, с помощью DirectComposition и Direct2D в C++?
Anonymous » » в форуме C++ - 0 Ответы
- 37 Просмотры
-
Последнее сообщение Anonymous
-