不要直接画到控件上,生成位图,再把位图调入控件
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[2], $aPos[3])
_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[2], $aPos[3])
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 |