我想通过双向软关闭在窗口上绘制一些文本 [英] I want to draw some texts on a window by Two Way Soft-closing

查看:74
本文介绍了我想通过双向软关闭在窗口上绘制一些文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我首先尝试在内存中绘制文本。然后将内存中的DC复制到具有BitBlt功能的窗口。但这没有效果。什么是错?

这些代码:

I try to draw the texts in memory at first. Then copy the DC in memory to the window with BitBlt function. But this is not effective. What is the fault?
Such these codes:

DCD *pDC = GetDC();
CDC dcMem;
dcMem.CreateCompatibleDC(pDC);
dcMem.SelectObject(&font);
dcMem.SetTextColor(RGB(255, 0, 0));
dcMem.SetBkMode(TRANSPARENT);
dcMem.DrawText(strText, rcWnd, DT_VCENTER | DT_SINGLELINE);
pDC->BitBlt(0, 0, rcWnd.Width(), rcWnd.Height(), &dcMem, 0, 0, SRCCOPY);
dcMem.DeleteDC();





谢谢...



Thanks...

推荐答案

您必须在内存DC中选择一个位图。例如,请参阅 MSDN [ ^ ]: 在应用程序开始绘制之前,必须通过调用SelectObject函数 在DC中选择具有适当宽度和高度的位图。

尝试

You must select a bitmap into your memory DC. See, for instance MSDN[^]: "Before an application can begin drawing, it must select a bitmap with the appropriate width and height into the DC by calling the SelectObject function".
Try
DCD *pDC = GetDC();
CDC dcMem;
Bitmap bmp; // added
dcMem.CreateCompatibleDC(pDC);
bmp.CreateCompatibleBitmap(pDC, rcWnd.Width(), rcWnd.Height()); // added: you must use pDC here
dcMem.SelectObject(&bmp); // added
dcMem.SelectObject(&font);
dcMem.SetTextColor(RGB(255, 0, 0));
dcMem.SetBkMode(TRANSPARENT);
dcMem.DrawText(strText, rcWnd, DT_VCENTER | DT_SINGLELINE);
pDC->BitBlt(0, 0, rcWnd.Width(), rcWnd.Height(), &dcMem, 0, 0, SRCCOPY);
dcMem.DeleteDC();


这篇关于我想通过双向软关闭在窗口上绘制一些文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆