funcs_any_win.py 文件源码

python
阅读 24 收藏 0 点赞 0 评论 0

项目:petronia 作者: groboclown 项目源码 文件源码
def paint__draw_text(hdc, hfont, text, pos_x, pos_y, width, height, fg_color, bg_color):
    old_hfont = None
    try:
        old_hfont = windll.gdi32.SelectObject(hdc, hfont)
        if fg_color:
            fg = wintypes.RGB((fg_color >> 16) & 0xff, (fg_color >> 8) & 0xff, fg_color & 0xff)
            windll.gdi32.SetTextColor(hdc, fg)
        if bg_color:
            bg = wintypes.RGB((bg_color >> 16) & 0xff, (bg_color >> 8) & 0xff, bg_color & 0xff)
            windll.gdi32.SetBkColor(hdc, bg)
            windll.gdi32.SetBkMode(hdc, OPAQUE)
        else:
            bg = wintypes.RGB(0, 0, 0)
            windll.gdi32.SetBkColor(hdc, bg)
            windll.gdi32.SetBkMode(hdc, TRANSPARENT)

        rect = wintypes.RECT()
        rect.left = pos_x
        rect.top = pos_y
        rect.right = pos_x + width
        rect.bottom = pos_y + height

        ret = windll.user32.DrawTextW(
            hdc, create_unicode_buffer(text), len(text), byref(rect),
            DT_LEFT | DT_TOP | DT_NOPREFIX)
        if ret == 0:
            raise WinError()
    finally:
        # To prevent a memory leak
        if old_hfont is not None:
            windll.gdi32.SelectObject(hdc, old_hfont)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号