我不需要控件或任何东西,我只需要在HWND上写一些东西,无论是居中的文本还是图像,都表明它已被渲染到.实际的用例是我在一个我尚未准备好处理的地方通过HWND,因此我想在其上显示文本,如"此窗口无法使用",或者悲伤的图形等等.
没有什么花哨的,只是原始的hacky代码,但你所拥有的只是在纯Win32中使用的HWND.
HDC hdc = GetDC(hwnd);
RECT rect;
GetClientRect(hwnd, &rect);
char * text = "this Window cannot be used";
DrawTextA(hdc, text, strlen(text), &rect, DT_CENTER | DT_VCENTER);
ReleaseDC(hdc);
Run Code Online (Sandbox Code Playgroud)
您可能希望在绘制文本之前选择不同的字体,但这将使您开始.
这实际上相当简单.
// 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);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2763 次 |
| 最近记录: |