D
David DB
Guest
Hi,
I have discovered a problem with Vista and the DrawText API.
Code (VB6):
Private Declare Function DrawText Lib "user32" Alias "DrawTextA" _
(ByVal hdc As Long, ByVal lpStr As String, ByVal nCount As Long, _
lpRect As RECT, ByVal wFormat As Long) As Long
Private Declare Function SetTextCharacterExtra Lib "gdi32" _
(ByVal hdc As Long, ByVal nCharExtra As Long) As Long
tR.Top = 1
tR.Left = 1
tR.Right = objPic.ScaleWidth \ Screen.TwipsPerPixelX
tR.Bottom = objPic.ScaleHeight \ Screen.TwipsPerPixelY
SetTextCharacterExtra lhDC, iCharSpacing
DrawText lhDC, sText, Len(sText), tR, DT_CENTER or DT_SINGLELINE
lhdc is the HDC of the picturebox
iCharSpacing the the characterspacing
sText is the text to be displayed
On XP this works great. With the text being displayed centered
On Vista it almost centers, but shifts many pixels to the right. This makes
long texts go off the screen to the right. This only happens when having a
character spacing bigger that 0. To me it sems that the center offset has
something to do with the character spacing. Without character spacing it is
centered correctly. The same thing happens when using DrawText with
DT_CALCRECT to calculate the with of the string. I can go around this by
adding the character spacing value for each char in the string to get the
correct result.
Anyone ?
And as I stated it works perfectly on versions up to Vista.
I have discovered a problem with Vista and the DrawText API.
Code (VB6):
Private Declare Function DrawText Lib "user32" Alias "DrawTextA" _
(ByVal hdc As Long, ByVal lpStr As String, ByVal nCount As Long, _
lpRect As RECT, ByVal wFormat As Long) As Long
Private Declare Function SetTextCharacterExtra Lib "gdi32" _
(ByVal hdc As Long, ByVal nCharExtra As Long) As Long
tR.Top = 1
tR.Left = 1
tR.Right = objPic.ScaleWidth \ Screen.TwipsPerPixelX
tR.Bottom = objPic.ScaleHeight \ Screen.TwipsPerPixelY
SetTextCharacterExtra lhDC, iCharSpacing
DrawText lhDC, sText, Len(sText), tR, DT_CENTER or DT_SINGLELINE
lhdc is the HDC of the picturebox
iCharSpacing the the characterspacing
sText is the text to be displayed
On XP this works great. With the text being displayed centered
On Vista it almost centers, but shifts many pixels to the right. This makes
long texts go off the screen to the right. This only happens when having a
character spacing bigger that 0. To me it sems that the center offset has
something to do with the character spacing. Without character spacing it is
centered correctly. The same thing happens when using DrawText with
DT_CALCRECT to calculate the with of the string. I can go around this by
adding the character spacing value for each char in the string to get the
correct result.
Anyone ?
And as I stated it works perfectly on versions up to Vista.