我正在尝试通过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时
我有这个

发布于 2016-04-12 01:25:18
strlen是用于ANSI的,它不能与Unicode混合。取而代之的是使用wcsxxx的“-c-string”函数。例如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;
}https://stackoverflow.com/questions/36551055
复制相似问题