gpt4 book ai didi

c++ - 将文本/图像写入 HWND 的最短代码是什么

转载 作者:太空狗 更新时间:2023-10-29 19:42:31 25 4
gpt4 key购买 nike

我不需要控件或任何东西,我只需要在 HWND 上写一些东西,可以是居中的文本或图像,表明它已被渲染到。实际的用例是我在我还没有准备好处理它的时候通过了一个 HWND,所以我想在它上面显示文本,比如“这个窗口不能使用”,或者一个悲伤的图形等.

没什么特别的,只是原始的 hacky 代码,但您所拥有的只是在纯 Win32 中使用的 HWND。

最佳答案

这实际上相当简单。

// Grab the window dimensions.
RECT bounds;
GetClientRect(hwnd, &bounds);

// Grab a DC to draw with.
HDC hdc = GetDC(hwnd);

// The money shot!
DrawText(hdc, messageText, -1, &bounds, DT_CENTER | DT_VCENTER);

// Now give back the borrowed DC.
ReleaseDC(hdc);

关于c++ - 将文本/图像写入 HWND 的最短代码是什么,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5046758/

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