I just updated the previous demo (I did not notice The gadgets behavior before)
Office-style menus (full include) - 20Feb2013 [x86 / x64]
Re: Office-style menus (full include) - 16Oct2012
Sorry Inf0Byt3
I just updated the previous demo (I did not notice The gadgets behavior before)
I just updated the previous demo (I did not notice The gadgets behavior before)
Egypt my love
Re: Office-style menus (full include) - 16Oct2012
Much better solution
It may need in Windows 7 to deactivate the animation effect
It may need in Windows 7 to deactivate the animation effect
Code: Select all
;- DEMO for BE_OfficeMenus
;{ Includes
XIncludeFile "BE_OfficeMenu.pbi"
;}
;{ Variables
Define AddIcons, Image, WindowHandle, Event, PopupEvent
;}
;{ Create an array and put some icons into it
Dim Icons(9)
For AddIcons = 0 To 9
Icons(AddIcons) = ExtractIcon_(GetModuleHandle_(0), "Shell32.dll", 15 + AddIcons)
Next
;}
Procedure WndProc(hwnd, uMsg, wParam, lParam)
Select uMsg
Case #WM_SIZE,#WM_MOVE,#WM_PAINT
If OSVersion() > #PB_OS_Windows_Vista
ResizeWindow(1,WindowX(0)+8,WindowY(0)+49,WindowWidth(0),2)
Else
ResizeWindow(1,WindowX(0)+4,WindowY(0)+49,WindowWidth(0),2)
EndIf
EndSelect
ProcedureReturn #PB_ProcessPureBasicEvents
EndProcedure
;{ Create an image here
Image = CreateImage(#PB_Any, 200, 20)
If IsImage(Image)
StartDrawing(ImageOutput(Image))
Box(0, 0, 200, 20, RGB(0, 128, 255))
DrawingMode(#PB_2DDrawing_Transparent)
DrawText(6, 2, "Image gadget (right click me)", 0)
DrawText(7, 3, "Image gadget (right click me)", RGB(255, 255, 255))
StopDrawing()
EndIf
;}
If OpenWindow(0, 0, 0, 400, 280, "OfficeMenu Test", #PB_Window_MinimizeGadget | #PB_Window_ScreenCentered | #PB_Window_Invisible|#PB_Window_SizeGadget)
;{ Init
SetWindowColor(0, RGB(128,128,128))
OpenWindow(1,WindowX(0)+8,WindowY(0)+48,410,20,"",#PB_Window_BorderLess)
SetWindowColor(1,RGB(128,128,128))
SetWindowLongPtr_(WindowID(1), #GWL_STYLE, GetWindowLongPtr_(WindowID(1), #GWL_STYLE)|#WS_CLIPSIBLINGS)
SetWindowPos_(WindowID(1), #HWND_TOPMOST , -1, -1, -1, -1,#SWP_NOSIZE| #SWP_NOMOVE| #SWP_SHOWWINDOW| #SWP_NOACTIVATE)
DisableWindow(1,1)
SetActiveWindow(0) ;
OfficeMenu_Init(WindowID(0)) ;This will hook the main window, must be called before adding OfficeMenus!
;}
;{ Gadgets
UseGadgetList(WindowID(0))
ButtonGadget(0, 100, 20, 200, 20, "Change menu theme")
ImageGadget(1, 100, 70, 200, 20, ImageID(Image))
StringGadget(2, 100, 120, 200, 20, "My context menu is left alone :P")
ButtonGadget(3, 100, 170, 200, 20, "Change items")
ButtonGadget(4, 100, 220, 200, 20, "Change titles")
;}
;{ Create menus
WindowHandle = WindowID(0)
If OfficeMenu_CreateMenu(0, WindowHandle, #OfficeMenu_Style_Blue) <> 0
OfficeMenu_Title(0, "&File")
OfficeMenu_Item(0, 0, "New" + Chr(9) + "Ctrl N")
OfficeMenu_Item(0, 1, "&Open..." + Chr(9 ) + "Ctrl O")
OfficeMenu_Item(0, 2, "Save" + Chr(9) + "Ctrl S", Icons(1))
OfficeMenu_Item(0, 3, "Save As...", Icons(2))
OfficeMenu_Item(0, 4, "Save All")
OfficeMenu_Item(0, 5, "&Close" + Chr(9) + "Ctrl W", Icons(3))
OfficeMenu_Item(0, 6, "Close All")
OfficeMenu_Bar(0)
OfficeMenu_Item(0, 7, "Sort &Sources...", Icons(4))
OfficeMenu_Bar(0)
OfficeMenu_Item(0, 8, "Preferences...", Icons(5))
OfficeMenu_Bar(0)
If OfficeMenu_OpenSubMenu(0, "Recent Files", Icons(8))
OfficeMenu_Item(0, 9, "file1.pb")
OfficeMenu_Item(0, 10, "file2.pb")
OfficeMenu_Item(0, 11, "file3.pb", Icons(6))
OfficeMenu_Bar(0)
If OfficeMenu_OpenSubMenu(0, "More Files", Icons(1))
OfficeMenu_Item(0, 12, "file4.pb")
OfficeMenu_Item(0, 13, "file5.pb", Icons(7))
OfficeMenu_Item(0, 14, "file6.pb")
OfficeMenu_Item(0, 15, "file7.pb", Icons(8))
OfficeMenu_Item(0, 16, "file8.pb")
OfficeMenu_CloseSubMenu(0)
EndIf
OfficeMenu_Bar(0)
OfficeMenu_Item(0, 17, "&Another item!", Icons(9))
OfficeMenu_CloseSubMenu(0)
EndIf
OfficeMenu_Bar(0)
OfficeMenu_Item(0, 18, "Exit" + Chr(9) + "Alt + F4")
OfficeMenu_Title(0, "&Edit")
OfficeMenu_Item(0, 19, "&Undo" + Chr(9)+ "Ctrl + Z", Icons(2))
OfficeMenu_Item(0, 20, "&Redo" + Chr(9)+ "Ctrl + Y")
OfficeMenu_Bar(0)
OfficeMenu_Item(0, 21, "&Cut" + Chr(9)+ "Ctrl + X")
OfficeMenu_Item(0, 22, "Co&py" + Chr(9)+ "Ctrl + C", Icons(5))
OfficeMenu_Item(0, 23, "Pas&te" + Chr(9)+ "Ctrl + V", Icons(6))
OfficeMenu_Bar(0)
OfficeMenu_Item(0, 24, "Select &All" + Chr(9)+ "Ctrl + A")
OfficeMenu_Bar(0)
OfficeMenu_Item(0, 25, "&Find" + Chr(9)+ "Ctrl + F", Icons(8))
OfficeMenu_Title(0, "&Help")
If OfficeMenu_OpenSubMenu(0, "I want", Icons(4))
OfficeMenu_Item(0, 26, "some")
If OfficeMenu_OpenSubMenu(0, "help", Icons(7))
OfficeMenu_Item(0, 27, "please!" + Chr(9)+ "F1", Icons(3))
OfficeMenu_CloseSubMenu(0)
EndIf
OfficeMenu_CloseSubMenu(0)
EndIf
Else
Debug "Error creating main menu"
EndIf
If OfficeMenu_CreatePopupMenu(1, #OfficeMenu_Style_Standard) <> 0
OfficeMenu_Item(1, 1000, "&This is", Icons(1))
OfficeMenu_Item(1, 1001, "A &cool")
OfficeMenu_Item(1, 1002, "Popup &menu!")
OfficeMenu_Bar(1)
If OfficeMenu_OpenSubMenu(1, "&Submenu", Icons(5))
OfficeMenu_Item(1, 1003, "&Here")
OfficeMenu_Bar(1)
If OfficeMenu_OpenSubMenu(1, "And &another", Icons(2))
OfficeMenu_Item(1, 1004, "&Here!")
OfficeMenu_CloseSubMenu(1)
EndIf
OfficeMenu_CloseSubMenu(1)
EndIf
OfficeMenu_Bar(1)
OfficeMenu_Item(1, 1005, "Co&nfiguration")
Else
Debug "Error creating popup menu"
EndIf
;}
;{ Configure the menu
OfficeMenu_SetItemState(0, 0, #MFS_CHECKED)
OfficeMenu_SetItemState(0, 1, #MFS_CHECKED | #MFS_DISABLED)
OfficeMenu_SetItemState(0, 10, #MFS_CHECKED)
OfficeMenu_SetItemState(1, 1002, #MFS_CHECKED)
OfficeMenu_SetItemState(1, 1004, #MFS_CHECKED)
;}
;{ Show the window
HideWindow(0, 0)
;}
EndIf
SetWindowCallback(@WndProc())
Repeat
Event = WaitWindowEvent()
Select Event
Case #PB_Event_Gadget ;{
Select EventGadget()
Case 0 ;{ Change theme
If OfficeMenu_GetStyle(0) = #OfficeMenu_Style_Standard
OfficeMenu_SetStyle(0, #OfficeMenu_Style_Blue)
OfficeMenu_SetStyle(1, #OfficeMenu_Style_Standard)
Else
OfficeMenu_SetStyle(0, #OfficeMenu_Style_Standard)
OfficeMenu_SetStyle(1, #OfficeMenu_Style_Blue)
EndIf
;}
Case 1 ;{ Image gadget
If EventType() = #PB_EventType_RightClick
PopupEvent = OfficeMenu_DisplayPopupMenu(1, WindowID(0), 0, 0, 1) ;Also return the selected item
If PopupEvent <> 0
MessageRequester("Menu event!","Popup event menu: "+Str(PopupEvent))
EndIf
EndIf
;}
Case 3 ;{ Change items
OfficeMenu_SetItemText(0, 6, "Looooooooooooooooooooooooooooooooong STRING :P "+Str(Random(1024)))
Debug "New text for item 6: "+OfficeMenu_GetItemText(0, 6)
OfficeMenu_SetItemIcon(0, 7, Icons(Random(9)))
OfficeMenu_SetItemIcon(0, 8, Icons(Random(9)))
OfficeMenu_SetItemIcon(1, 1000, Icons(Random(9)))
OfficeMenu_SetItemIcon(1, 1003, Icons(Random(9)))
;}
Case 4 ;{ Change titles
OfficeMenu_SetTitleText(0, 0, "&What File !?")
OfficeMenu_SetTitleText(0, 1, "&Tools are cool")
Debug "New text for title 0: "+OfficeMenu_GetTitleText(0, 0)
Debug "New text for title 1: "+OfficeMenu_GetTitleText(0, 1)
If OfficeMenu_GetTitleState(0, 1) & #MFS_GRAYED
OfficeMenu_SetTitleState(0, 1, #MFS_ENABLED)
Else
OfficeMenu_SetTitleState(0, 1, #MFS_GRAYED)
EndIf
;}
EndSelect
;}
Case #PB_Event_Menu ;{
MessageRequester("Menu event!","Event menu: "+Str(EventMenu()))
;}
EndSelect
Until Event = #PB_Event_CloseWindow
;Manually free the menus!
OfficeMenu_FreeMenu(0)
OfficeMenu_FreeMenu(1)
;And uninit from the window
OfficeMenu_UnInit(WindowID(0))
Egypt my love
Re: Office-style menus (full include) - 16Oct2012
It does not work in W7-64. I suspect it is due to the heavy use of Integer variable types within the Windows API calls. Some of those calls are in a User32.lib.
Re: Office-style menus (full include) - 16Oct2012
@RASHAD: Much better, thanks. Works well here.
@Tenaja: Yes, that's what's wrong with it. I used integers all over the place, even where longs should have been used. On x86 there's no risk, but it needs some work for x64.
@Tenaja: Yes, that's what's wrong with it. I used integers all over the place, even where longs should have been used. On x86 there's no risk, but it needs some work for x64.
None are more hopelessly enslaved than those who falsely believe they are free. (Goethe)
Re: Office-style menus (full include) - 16Oct2012
Added support for x64. The link remains the same (see the first post). Let me know if it misbehaves
.
None are more hopelessly enslaved than those who falsely believe they are free. (Goethe)
Re: Office-style menus (full include) - 20Feb2013 [x86 / x64
Code updated (see the first post for details and download link).
None are more hopelessly enslaved than those who falsely believe they are free. (Goethe)

