Listing 1
Estimating width of Windows controls based on the length of the text they are supposed to display.

Input parameters:

Dragobject ado_object (the object that displays the text)
String as_text (the text it needs to display)
Long (by REFERENCE) the returned width required to display the text

The code:

integer li_return = 1, li_len, li_new_width, li_width, li_extra_width
integer li_WM_GETFONT = 49 // hex 0x0031
ULong lul_Hdc, lul_Handle, lul_hFont
s_os_size lstr_Size
statictext lst_temp

//get a handle to the object and create a device context for it
lul_Handle = Handle(ado_object)
lul_Hdc = This.GetDC(lul_Handle)

// Get the font in use on the Text
lul_hFont = Send(lul_Handle, li_WM_GETFONT, 0, 0)

// Select it into the device context
This.SelectObject(lul_Hdc, lul_hFont)

// Get the size of the text.
li_Len = Len(as_text)
IF NOT This.GetTextExtentPoint32A(lul_Hdc,as_text,li_Len,lstr_Size ) Then 
Return -1
END IF

//release the device context
This.ReleaseDC(lul_Handle, lul_Hdc) 

//get the size in Pixels
li_width = lstr_Size.l_cx

//resize by translating Pixels to PBUs
li_new_width = PixelsToUnits ( li_width, XPixelsToUnits! )

//depending on particular type of controls will need to add extra width to account for graphic objects
//embedded in the control besides just the text label
CHOOSE CASE ado_object.TypeOf()
CASE CheckBox!
li_extra_width = 94
CASE RadioButton!
li_extra_width = 94
CASE Statictext!
//only need to add if label has a 3D lowered border
lst_temp = ado_object
IF lst_temp.Border = TRUE AND lst_temp.BorderStyle = StyleLowered! THEN
li_extra_width = 22
END IF
CASE ELSE
li_extra_width = 0
END CHOOSE

//return the value
al_width = li_new_width + li_extra_width

Return 1



Listing 2
Sample code from the constructor of an internationalization-enabled check box ancestor object:
ss
long ll_width 

//get internationalized text based on resource ID embedded
//in dev-time description
This.Text = language.inv_language.of_translate_label(This.Text)

//resize to display full text
IF language.inv_language.of_get_object_size_specs(This,This.Text,ll_width) = 1 THEN
This.Width = ll_width
END IF