_GDIPlus_GraphicsDrawString 绘制的字符串要如何清除
如题用_GDIPlus_GraphicsDrawString函数绘制的字符串要如何清除呢? 不要直接画到控件上,生成位图,再把位图调入控件GDI+ 与GDI差不多,就这么个思路
Func _DrawString($ContrlID, $sText, $iHeight = 20, $sFace = 'Arial')
Local $hWnd = GUICtrlGetHandle($ContrlID)
Local $aPos = WinGetPos($hWnd)
Local $hDC = _WinAPI_GetDC($hWnd)
Local $hBitmap = _WinAPI_CreateCompatibleBitmap($hDC, $aPos, $aPos)
_WinAPI_ReleaseDC($hWnd, $hDC) ;释放DC
Local $hCDC = _WinAPI_CreateCompatibleDC(0) ;创建兼容DC环境,0是屏幕兼容的内存DC
Local $HoldBitmap = _WinAPI_SelectObject($hCDC, $hBitmap) ;把位图调入DC,那对DC的操作就作用到位图上了
;清空背景,使用0xEEEEEE画刷
Local $tRect = _WinAPI_CreateRect(0, 0, $aPos, $aPos)
Local $hBrush = _WinAPI_CreateSolidBrush(0xEEEEEE)
_WinAPI_FillRect($hCDC, DllStructGetPtr($tRect), $hBrush)
_WinAPI_DeleteObject($hBrush)
Local $hFont = _WinAPI_CreateFont($iHeight, 0, 0, 0, 700, False, False, False, $DEFAULT_CHARSET, _
$OUT_DEFAULT_PRECIS, $CLIP_DEFAULT_PRECIS, $DEFAULT_QUALITY, 0, $sFace)
Local $oldFontObj = _WinAPI_SelectObject($hCDC, $hFont) ;选择新建立的字体,返回值为原来默认字体
;~ _WinAPI_SetTextColor($hDC, Hex(Random(1, 16777215, 1), 6))
_WinAPI_SetBkMode($hCDC, $TRANSPARENT)
_WinAPI_DrawText($hCDC, $sText, $tRect, $DT_END_ELLIPSIS)
;~ _WinAPI_TextOut($hCDC, 0, 0, $sText)
_WinAPI_SelectObject($hCDC, $HoldBitmap)
_WinAPI_SelectObject($hCDC, $oldFontObj)
_WinAPI_DeleteDC($hCDC)
_WinAPI_DeleteObject($hFont) ;释放字体对象
_SetBitmap($hWnd, $hBitmap)
EndFunc ;==>_DrawString 补个函数
Func _SetBitmap($hWnd, $hBitmap)
Local $hObj = _SendMessage($hWnd, 0x0172, 0, $hBitmap) ;$STM_SETIMAGE = 0x0172
_WinAPI_DeleteObject($hObj)
Local $hObj = _SendMessage($hWnd, 0x0173) ;$STM_GETIMAGE = 0x0173
If $hObj <> $hBitmap Then
_WinAPI_DeleteObject($hBitmap)
EndIf
EndFunc ;==>_SetBitmap
tubaba 发表于 2019-1-21 21:39
补个函数
Func _SetBitmap($hWnd, $hBitmap)
Local $hObj = _SendMessage($hWnd, 0x0172, 0, $hBitmap)...
谢谢了,研究一下
页:
[1]