GdipDrawString无法正确显示文本

时间:2018-10-28 21:27:45

标签: python ctypes gdi+ system.drawing drawstring

我是GDI +的新手,正在尝试修改程序,以使其在指定对象上绘制一个黑色矩形,然后显示描述所覆盖对象是什么的文本。我已经能够显示黑色矩形,但是在使GdipDrawString正常工作方面非常困扰。我已经到达不再出现任何编译或运行时错误的地步,但文本仍无法清晰显示。

这是该函数的简化版本,其中包含对GdipDrawString的调用:

def doPaint(hwnd):
    rect = RECT()
    windll.user32.GetClientRect(c_int(hwnd), byref(rect))
    ps = PAINTSTRUCT()
    hdc = windll.user32.BeginPaint(c_int(hwnd), byref(ps))
    windll.user32.FillRect(hdc, byref(rect), blackBrush)
    gdiplus.GdipDrawString("TEST", font, whiteBrush, byref(rect)) 
    windll.user32.EndPaint(c_int(hwnd), byref(ps))

以下是一些最相关的部分的定义:

blackBrush = windll.gdi32.CreateSolidBrush(blackColor)
whiteBrush = windll.gdi32.CreateSolidBrush(whiteColor)

class RECT(Structure):
    _fields_ = [('left', c_long),
                ('top', c_long),
                ('right', c_long),
                ('bottom', c_long)]

font = windll.gdi32.CreateFontW(48, 0, 0, 0, weight, False, False, False,
       charSet, outPrecision, clipPrecision, quality, family | pitch, "")

任何指导将不胜感激!为了简化测试,我一直在使用字符串文字,并尝试使用指定的字体值,因为我不确定为什么FillRect会起作用,但DrawString不起作用。交换用于FillRect和DrawString的笔刷会产生一个白色矩形,没有文本。

0 个答案:

没有答案
相关问题