I'm new to GDI+ and am trying to modify a program so that it draws a black rectangle over a specified object and then display text describing what the covered object is. I've been able to get the black rectangle to display but have gotten very stuck on getting GdipDrawString to work. I've reached a point where I'm no longer getting any compile or runtime errors, but the text still isn't displaying visibly.
Here's a simplified version of the function with the call to 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))
Here are the definitions of some of the most relevant pieces:
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, "")
Any guidance would be much appreciated! I've been using a string literal for simplicity's sake while testing and have played around with the specified font values because I'm not sure why else FillRect would work but not DrawString. Swapping the brushes used for FillRect and DrawString produces a white rectangle and no text.