Restored from previous forum. Originally posted by wayne1.
Global CurSize
Procedure.l SetNewWidth(wID.l, str.s)
hFontOld.l
hDc.l
sz.SIZE
hDc= GetDC_(wID)
hFont=GetStockObject_(#SYSTEM_FONT)
hFontOld=SelectObject_(hDc,hFont)
GetTextExtentPoint32_(hDc,str,Len(str),sz)
If sz\cx > StringWidth:StringWidth=sz\cx : EndIf
SelectObject_(hDc,hFontOld)
DeleteObject_(hFont)
ReleaseDC_(wID,hDc)
If StringWidth > CurSize:CurSize=StringWidth:EndIf
ProcedureReturn CurSize
EndProcedure
If OpenWindow(0, 100, 100, 195, 210, #PB_Window_SystemMenu | #PB_Window_MinimizeGadget | #PB_Window_MaximizeGadget, "Resize ComboBox")
InitGadget(3)
CreateGadgetList(WindowID())
hCbo=ComboBoxGadget(1,33,56,123,455)
ButtonGadget(2,10,120,160,20,"Add an extra long string")
AddGadgetItem(1, -1, "This text fits inside")
Repeat
EventID.l = WaitWindowEvent()
If EventID = #PB_EventGadget
Select EventGadgetID()
Case 2
LongString$="This text is too long to fit the inside the combo box so we extend the box!"
AddGadgetItem(1, -1, LongString$ )
SendMessage_(hCbo,#CB_SETDROPPEDWIDTH,SetNewWidth(WindowID(), LongString$),0)
EndSelect
EndIf
If EventID = #PB_EventCloseWindow
Quit = 1
EndIf
Until Quit = 1
EndIf
End