Jim Mack
3/25/2012 12:00:00 PM
> Hello, I have a MSHFlexGrid that in a column I display Greek or Hebrew
> words. The MSHFlexGrid properly displays these unicode words (previously
> setting the proper font), but the problem comes when I want to adjust the
> width of the column according to the widest word.
>
> For the other columns, that have normal characters (and font) I use
> Textwidth in an auxiliary picturebox to measure the size, but I can't do
> that with unicode words.
>
> So, researching a bit I found that the API GetTextExtentPoint32W
> supposedly does it. But I can't get it to work.
>
> The declaration:
>
> Private Declare Function GetTextExtentPoint32W _
> Lib "gdi32" (ByVal hdc As Long, ByVal lpsz As _
> String, ByVal cbString As Long, lpSize As POINTAPI) As Long
>
> The ANSI version is the same but with the "A":
>
> Private Declare Function GetTextExtentPoint32A _
> Lib "gdi32" (ByVal hdc As Long, ByVal lpsz As _
> String, ByVal cbString As Long, lpSize As POINTAPI) As Long
>
> The ANSI version works fine, but the unicode version returns greater
> values than the real width of the word.
You need to modify the Declare for the W version (or use a typelib).
Private Declare Function GetTextExtentPoint32W _
Lib "gdi32" (ByVal hdc As Long, ByVal lpsz As _
Long, ByVal cbString As Long, lpSize As POINTAPI) As Long
Note that the second parameter is now ByVal As Long. Pass
StrPtr(Ustring) here, and pass LenB(Ustring) in the third parameter.
That should do what you want.
--
Jim