Retrieves the outline or bitmap for a character in the TrueType font.
#Include <WinAPIEx.au3>
_WinAPI_GetGlyphOutline ( $hDC, $sChar, $iFormat, ByRef $pBuffer [, $tMAT2] )
$hDC | A handle to the device context which font is selected. |
$sChar | The character for which data is to be returned. |
$iFormat | The format of the data that the function retrieves. This parameter can be one of the following values. $GGO_BEZIER $GGO_BITMAP $GGO_GLYPH_INDEX $GGO_GRAY2_BITMAP $GGO_GRAY4_BITMAP $GGO_GRAY8_BITMAP $GGO_METRICS $GGO_NATIVE $GGO_UNHINTED |
$pBuffer | A pointer to a memory block (buffer) that receives the outline or bitmap data. Optionaly, you can set this parameter to 0 before function call, then the function will allocate the required memory block itself. Otherwise, it must be a valid memory pointer returned by the _WinAPI_CreateBuffer() function, or by previously calling this function. If the $GGO_METRICS is specified, this parameter is ignored, and function only returns the information about a glyph (see below). |
$tMAT2 | [可选参数] $tagMAT2 structure specifying a transformation matrix for the character. If this parameter is 0 or omitted, the transformation will not be used (it is identity matrix). |
Success | $tagGLYPHMETRICS structure containing information about the placement and orientation of a glyph, |
失败: | 返回 0 并设置 @error 标志为非 0 值. |
在MSDN中搜索
#Include <APIConstants.au3>
#Include <WinAPIEx.au3>
Opt('MustDeclareVars', 1)
Global Const $STM_SETIMAGE = 0x0172
Global Const $STM_GETIMAGE = 0x0173
Global $hForm, $Pic, $hPic, $tGM, $W, $H, $hDC, $hSv, $hBmp, $hDib, $hFont, $pData = 0
Global $aColorTable[2] = [0xFFFFFF, 0xC00000]
; Creates logical font ("Times") and retrieve bitmap bits for a random character
$hDC = _WinAPI_CreateCompatibleDC(0)
$hFont = _WinAPI_CreateFont(512, 0, 0, 0, 400, False, False, False, $DEFAULT_CHARSET, $OUT_DEFAULT_PRECIS,$CLIP_DEFAULT_PRECIS, $DEFAULT_QUALITY, 0, 'Times')
$hSv = _WinAPI_SelectObject($hDC, $hFont)
$tGM = _WinAPI_GetGlyphOutline($hDC, ChrW(Random(65, 90, 1)), $GGO_BITMAP, $pData)
$W = DllStructGetData($tGM, 'BlackBoxX')
$H = DllStructGetData($tGM, 'BlackBoxY')
_WinAPI_SelectObject($hDC, $hSv)
_WinAPI_DeleteObject($hFont)
; Create 1 bits-per-pixel bitmap
$hBmp = _WinAPI_CreateBitmap(32 * Ceiling($W / 32), $H, 1, 1, $pData)
; Crop bitmap to the required size and colorize it
$hDib = _WinAPI_CreateDIB($W, $H, 1, _WinAPI_CreateDIBColorTable($aColorTable), 2)
$hSv = _WinAPI_SelectObject($hDC, $hDib)
_WinAPI_DrawBitmap($hDC, 0, 0, $hBmp, $MERGEPAINT)
_WinAPI_SelectObject($hDC, $hSv)
_WinAPI_DeleteObject($hBmp)
; Free unnecessary resources
_WinAPI_FreeMemory($pData)
_WinAPI_DeleteDC($hDC)
; 创建 GUI
$hForm = GUICreate('MyGUI', $W, $H)
$Pic = GUICtrlCreatePic('', 0, 0, $W, $H)
$hPic = GUICtrlGetHandle($Pic)
; Set bitmap to control
_SendMessage($hPic, $STM_SETIMAGE, 0, $hDib)
$hBmp = _SendMessage($hPic, $STM_GETIMAGE)
If $hBmp <> $hDib Then
_WinAPI_DeleteObject($hDib)
EndIf
; Show GUI
GUISetState()
Do
Until GUIGetMsg() = -3