簡體   English   中英

如何使用pywin32設置lfFaceName

[英]How to set lfFaceName by using pywin32

我有一個微型MFC程序,它將被移植到pywin32
但是我無法處理LOGFONT對象的lfFaceName
lfWidthlfHeight可以很容易地處理,而lfFaceName則不容易。
我嘗試了幾種不同的lfFaceName,但結果似乎一樣嗎?
這是我嘗試過的示例python代碼片段。

lf            = win32gui.LOGFONT()
lf.lfFaceName = "Arial"    #Is this the correct way???

if iWidth < 16:
    lf.lfWidth = iWidth
else:
    lf.lfWidth = iWidth/2
if lf.lfHeight > iHeight:
    lf.lfHeight = iHeight
if lf.lfHeight < iHeight-1:
    lf.lfHeight = iHeight-1

s_Font = win32gui.CreateFontIndirect(lf)
win32gui.SelectObject (s_DC, s_Font)
win32gui.DrawText(s_DC, sText, len(sText),(0, 0, iWidth, iHeight), DT_VCENTER|DT_SINGLELINE|DT_CENTER)

如果分配了錯誤的lfFaceName,將不會顯示任何錯誤,但將使用默認的FaceName。因此此應用程序需要FaceName枚舉。 我們可以通過FaceName []獲得完整的lfFaceName列表。

import win32gui


def callback(font, tm, fonttype, fonts):
    fonts.append(font)
    FaceName.append(font.lfFaceName)
    return True


FaceName = []
fonts    = []
hdc = win32gui.CreateDC('DISPLAY','Display',None)
win32gui.EnumFontFamilies(hdc, None, callback, fonts)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM