Tip: MenuWidth() procedure
Posted: Tue Jan 14, 2003 1:10 pm
Code updated For 5.20+
Restored from previous forum. Originally posted by PB.
PureBasic has MenuHeight(), but no MenuWidth(), so here's my own!
Restored from previous forum. Originally posted by PB.
PureBasic has MenuHeight(), but no MenuWidth(), so here's my own!

Code: Select all
; MenuWidth() procedure by PB -- do whatever you want with it. :)
; This example demonstrates a window having the width of its menu.
; (It's not exactly the menu width, due to Windows OS limitations).
;
Procedure MenuWidth()
MyMenu=GetMenu_(WindowID(0)) : ItemSize.RECT
For ItemNum=0 To GetMenuItemCount_(MyMenu)-1
GetMenuItemRect_(WindowID(0),MyMenu,ItemNum,ItemSize)
width+(ItemSize\right-ItemSize\left)
Next
ProcedureReturn width+GetSystemMetrics_(#SM_CYHSCROLL)
EndProcedure
;
If OpenWindow(0,100,200,0,GetSystemMetrics_(#SM_CYCAPTION),"test",#WS_VISIBLE|#PB_Window_SystemMenu) And CreateMenu(0,WindowID(0))
MenuItem(0,"#1") : MenuItem(0,"No. Two") : MenuItem(0,"Number Three") : MenuItem(0,"IV")
ResizeWindow(0,100,200,MenuWidth(),MenuHeight()) : ShowWindow_(WindowID(0),#SW_SHOW)
Repeat : Until WaitWindowEvent()=#PB_Event_CloseWindow
EndIf