gpt4 book ai didi

c++ - DXGI 文本输出轨迹

转载 作者:行者123 更新时间:2023-11-28 05:44:09 31 4
gpt4 key购买 nike

我正在尝试通过 TextOut 移动文本

这是代码

IDXGISurface1* g_pSurface1 = NULL;
HRESULT hr = pSwapChain->GetBuffer(0, __uuidof(IDXGISurface1), (void**)&g_pSurface1);

if (SUCCEEDED(hr))
{
hr = g_pSurface1->GetDC(FALSE, &hdc);
if (SUCCEEDED(hr))
{


TextOut(hdc, pos.x, pos.y, L"DXGI's GDI text output works", strlen("DXGI's GDI text output works") + 1);

g_pSurface1->ReleaseDC(NULL);
}
else
{
MessageBox(0,0,0,0);
}
g_pSurface1->Release();
}
else
{
MessageBox(0,0,0,0);
}
pDevContext->OMSetRenderTargets(1, &pRenderTarget, pDepth);

在哪里

 pos.x and pos.y are mouse coordinates

当我移动文本或子窗口时 GDI and DirectX rendering

我有这个enter image description here

最佳答案

strlen 用于 ANSI,不能与 Unicode 混合。而是使用“wide-c-string”函数 wcsxxx。例如wcslen:

const wchar_t* text = L"DXGI's GDI text output works";
TextOut(hdc, pos.x, pos.y, text, wcslen(text));

要去除痕迹,您必须手动删除背景。例如:

case WM_MOUSEMOVE:
{
HDC hdc = GetDC(hWnd);

//erase background:
RECT rc;
GetClientRect(hWnd, &rc);
HBRUSH brush = CreateSolidBrush(RGB(128, 128, 255));
FillRect(hdc, &rc, brush);
DeleteObject(brush);

//draw text:
const wchar_t *text = L"DXGI's GDI text output works";
SetBkMode(hdc, OPAQUE);
SetBkColor(hdc, RGB(255,255,255));
TextOut(hdc, LOWORD(lParam), HIWORD(lParam), text, wcslen(text));
ReleaseDC(hWnd, hdc);
break;
}

编辑,将其与 Direct3D 混合

case WM_MOUSEMOVE:
{
//call directx rendering to reset the background:
Render();

//draw text:
HDC hdc = GetDC(hWnd);
const wchar_t *text = L"DXGI's GDI text output works";
SetBkMode(hdc, OPAQUE);
SetBkColor(hdc, RGB(255,255,255));
TextOut(hdc, LOWORD(lParam), HIWORD(lParam), text, wcslen(text));
ReleaseDC(hWnd, hdc);
break;
}

关于c++ - DXGI 文本输出轨迹,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36551055/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com