找回密码
 加入
搜索
查看: 1499|回复: 3

[图形处理] _GDIPlus_GraphicsDrawString 绘制的字符串要如何清除

  [复制链接]
发表于 2019-1-20 22:21:17 | 显示全部楼层 |阅读模式
如题用_GDIPlus_GraphicsDrawString函数绘制的字符串要如何清除呢?
发表于 2019-1-21 21:36:11 | 显示全部楼层
不要直接画到控件上,生成位图,再把位图调入控件
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
发表于 2019-1-21 21:39:28 | 显示全部楼层
补个函数
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
 楼主| 发表于 2019-1-26 18:33:24 | 显示全部楼层
tubaba 发表于 2019-1-21 21:39
补个函数
Func _SetBitmap($hWnd, $hBitmap)
        Local $hObj = _SendMessage($hWnd, 0x0172, 0, $hBitmap)  ...

谢谢了,研究一下
您需要登录后才可以回帖 登录 | 加入

本版积分规则

QQ|手机版|小黑屋|AUTOIT CN ( 鲁ICP备19019924号-1 )谷歌 百度

GMT+8, 2024-11-16 12:54 , Processed in 0.095311 second(s), 19 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表