Here is a working example script from a command button's Clicked event that calls the PFC's of_GetTextSize function of the Platform service. The command button resides in a window, not on a tab page. The single line of text is taken from a Single-Line Edit control in the window named sle_textsize.
Boolean lb_bold, lb_ital, lb_undr
Integer li_rc, li_w, li_h, li_fontsize
String ls_fontface, ls_text
Window lw_parent
n_cst_platform lnv_platform
ls_text = sle_textsize.Text
lw_parent = Parent // Obtain reference to parent window.
ls_fontface = sle_textsize.Facename
li_fontsize = Abs(sle_textsize.Textsize)
If sle_textsize.Weight = 400 Then
lb_bold = False
Else
lb_bold = True
End If
lb_ital = sle_textsize.Italic
lb_undr = sle_textsize.Underline
f_SetPlatform(lnv_platform,True)
li_rc = lnv_platform.of_GetTextSize(lw_parent,ls_text, &
ls_fontface,li_fontsize,lb_bold,lb_ital, &
lb_undr,li_h,li_w)
f_SetPlatform(lnv_platform,False)
MessageBox('of_GetTextSize Results', &
'RC = ' + String(li_rc) + &
', Height = ' + String(li_h) + &
', Width = ' + String(li_w))
A limitation of the of_GetTextSize function (and the Windows API function that it calls) is that it can only calculate the size of a single line of text. Please note the underlying Windows API function this PFC function calls returns the height and width in PIXELS, not PowerBuilderUnits. If you need PBU's, you'll need to use the PowerScript PixelsToUnits conversion function to perform the translation.
If you're experiencing difficulties getting this PFC Platform service's function to work, then frankly I'm doubtful you will be able to get an example of the Windows API DrawTextEx function to work, as it is a more complex API function and there is not a PFC-supplied interface to utilize it... you would have to call the API function directly from PB.
I encourage you to consider Chris' suggestion and if possible, avail yourself of the functionality of the PB Picture Button control.