5 Attachment(s)
[RESOLVED] DrawText draws Segoe UI font texts with unremovable artifacts
In one of our VB6 ActiveX projects we use the DrawText WinAPI call to output strings in a treeview-like grid control. When the user expands a tree node and the vertical scroll bar appears, some artefacts are drawn at the left of the scroll bar. They are not removed if we draw in that area using any WinAPI calls and remain visible until the vertical scroll bar is hidden again:
Attachment 119915
Attachment 119917
Attachment 119919
Attachment 119921
As i can judge, these artifacts are some points 'captured' when the scroll bar becomes visible. Here is the enlarged screenshot:
Attachment 119923
What is strange is that this happens only for the Segoe UI font. Using other traditional fonts like MS Sans Serif does not have this effect.
What it could be and how to overcome this strange problem?
Re: DrawText draws Segoe UI font texts with unremovable artifacts
Are the scrollbars created by your active X via CreateWindow APIs? Or does the window/uc create these automatically? Looks as though the view port device context (minus the scrollbars) may need to be clipped?
Re: DrawText draws Segoe UI font texts with unremovable artifacts
You can use CreateRectRgn,GetClipRgn,SelectClipRgn,DeleteObject API to create clipregion to draw text or else to avoid beyond boundary.
Re: DrawText draws Segoe UI font texts with unremovable artifacts
Wisecat, if you drag it off the screen and then back again, does it clear up the problem? If so, using a bit of the following should clear it up. (I'll let you rework that code, but it should be fairly obvious.) That'll tell Windows to redraw that portion of the screen.
Code:
Private Declare Function GetClientRect Lib "user32.dll" (ByVal hWnd As Long, lpRect As RECT) As Long
Private Declare Function InvalidateRect Lib "user32.dll" (ByVal hWnd As Long, lpRect As RECT, ByVal bErase As Long) As Long
GetClientRect ctrl.hWnd, uRect
InvalidateRect ctrl.hWnd, uRect, 1&
EDIT: Ahhh, and here's your Rect UDT:
Code:
Private Type RECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type
EDIT2: Also, where'd you put that code might be a bit tricky, possibly in whatever AddItem method you have for your control. Or, if the user can resize it, possibly in the resize event.
Re: DrawText draws Segoe UI font texts with unremovable artifacts
I've found the source of the problem - I did not calculate the client rectangle properly in some situations. My fault :)