, you can look at the following code, it's pretty simple to add this stuff.
Would be nice to see these commands added in 3v9 final....
Now here it comes...
Code: Select all
; MDI Example by Freak
; Modified by FSW
; Added: the 'Windows' Menu Title is now disabled if no MDI Child Window exists
; Added: Ctrl+F4 for closing MDI Child Windows ; this was very difficult ;)
; *******************************************************************************
; MDIGadget() Description:
; *******************************************************************************
; Syntax:
; MDIGadget(#Gadget, x, y, Width, Height, SubMenu, MenuItem [, Flags])
;
; SubMenu: 0 based index of the window submenu (opened with MenuTitle() ), on which
; to add the MDI window entrys. (Usually, this menu is called "Windows")
;
; MenuItem: the MenuItem number for the first MDI child window in the menu
; more MDI windows will get a number above that one, so numbers
; above MenuItem should be reserved for MDI use.
;
; Note: a MDIGadget can only be put directly on a window, not on a PanelGadget or
; ContainerGadget! The window MUST have a menu, and SubMenu and MenuItem must be set
; correctly, otherwise, there is no minimize button displayed when the user maximizes
; a window, which is pretty bad.
;
; There can only be one MDIGadget per window, as 2 would create a conflict with the
; menu. However, an application can have several MDIGadgets in different windows.
; Gadget flags:
; #PB_MDI_BorderLess - no borders
; #PB_MDI_AutoSize - automatically resize the gadget to fit the window
; #PB_MDI_NoScrollBars - MDI client area is not scrollable
; SetGadgetState() - set active child window number, or one of the following:
; #PB_MDI_Cascade - cascade child windows
; #PB_MDI_TileVertically - arrange child windows
; #PB_MDI_TileHorizontally
; #PB_MDI_Next - focus on next window
; #PB_MDI_Previous - focus on previous window
; #PB_MDI_Arrange - arrange iconic windows
; GetGadgetState() get active child window
; Get/SetGadgetItemState() - get/set a combination of the following:
; #PB_MDI_Normal - normal view (not minimized, not maximized)
; #PB_MDI_Maximize - maximize the window
; #PB_MDI_Minimize - minimize the window
; #PB_MDI_Hide - hide the window
; #PB_MDI_Show - show the window
; attribute types for Get/SetGadgetItemAttribute()
; #PB_MDI_ItemWidth - get/set the height of the child window
; #PB_MDI_ItemHeight - get/set the width of the child window
; attribute type for GetGadgetAttribute(): returns the item after a #PB_Eventtype_SizeItem
; #PB_MDI_SizedItem
; Get/SetGadgetItemText() - change child window titlebar
; RemoveGadgetItem() - close child window
; ClearGadgetItemList() - close all childs
; AddGadgetItem() - create new window
; - Position: numeric identifier for the window
; - Text: window title
; - ImageID: Icon for the window
; if the MDI gadget fires an event, it is one of those:
; #PB_EventType_Focus - the active child window has changed
; #PB_EventType_SizeItem
; the user has resized one of the child windows,
; use GetGadgetState() To find out wich one.
; #PB_EventType_CloseItem
; same as #PB_EventCloseWindow, but For an MDI child
; use GetGadgetState() to find out wich one.
; *******************************************************************************
; Example Code: a MDI ImageViewer:
; *******************************************************************************
; added....
#MIIM_STATE = 1
#MIIM_ID = 2
#MIIM_SUBMENU = 4
#MIIM_CHECKMARKS = 8
#MIIM_TYPE = 16
#MIIM_DATA = 32
Procedure FSW_DisableMenuTitle (hwnd, MenuTitleNumber, State)
mii.MENUITEMINFO
mii\cbSize = SizeOf(mii)
mii\fMask = #MIIM_STATE
If State = 1
mii\fState = #MFS_GRAYED
Else
mii\fState = #MFS_ENABLED
EndIf
Result = SetMenuItemInfo_(hWnd, MenuTitleNumber, #FALSE, @mii)
DrawMenuBar_(WindowID())
ProcedureReturn = Result
EndProcedure
Procedure FSW_MenuTitle(hWnd, MenuTitleNumber, Title$)
MenuTitle(Title$)
ItemCount.l = GetMenuItemCount_(hWnd)-1
mii.MENUITEMINFO
mii\cbSize = SizeOf(mii)
mii\fMask = #MIIM_ID
mii\wID = MenuTitleNumber
SetMenuItemInfo_(hWnd, ItemCount, #TRUE, @mii)
ProcedureReturn GetSubMenu_(hWnd, ItemCount) ;returns handle of it
EndProcedure
Procedure FSW_CheckMDI(hWnd, MenuTitleNumber, MDIChild)
If MDIChild = 0
FSW_DisableMenuTitle (hWnd, MenuTitleNumber, 1)
Else
FSW_DisableMenuTitle (hWnd, MenuTitleNumber, 0)
EndIf
EndProcedure
;---------------------
Structure MDIWindow
; info about the loaded image
Image.l
ImageWidth.l
ImageHeight.l
; gadget numbers
ScrollAreaGadget.l
ImageGadget.l
EndStructure
NewList MDIWindow.MDIWindow()
#WINDOW = 0
#TOOLBAR = 0
#MENU = 0
Enumeration 100
#MENU_File
#MENU_Open
#MENU_Close
#MENU_CloseAll
#MENU_Quit
#MENU_Windows
#MENU_TileV
#MENU_TileH
#MENU_Cascade
#MENU_Arrange
#MENU_Previous
#MENU_Next
#MENU_FirstMDI
EndEnumeration
UseJPEGImageDecoder()
UsePNGImageDecoder()
UseTGAImageDecoder()
UseTIFFImageDecoder()
#GADGET_MDI = 0
#WindowFlags = #PB_Window_Screencentered|#PB_Window_SystemMenu|#PB_Window_MinimizeGadget|#PB_Window_MaximizeGadget|#PB_Window_SizeGadget
If OpenWindow(#WINDOW, 0, 0, 800, 600, #WindowFlags, "MDI ImageViewer")
MenuHWND = CreateMenu(#MENU, WindowID())
If MenuHWND
;MenuTitle("File")
FSW_MenuTitle(MenuHWND, #MENU_File, "File") ; added
MenuItem(#MENU_Open, "Open")
MenuItem(#MENU_Close, "Close")
MenuItem(#MENU_CloseAll, "Close All")
MenuBar()
MenuItem(#MENU_QUit, "Quit")
;MenuTitle("Windows")
FSW_MenuTitle(MenuHWND, #MENU_Windows, "Windows") ; added
MenuItem(#MENU_TileV, "Tile vertically")
MenuItem(#MENU_TileH, "Tile horizontally")
MenuItem(#MENU_Cascade, "Cascade")
MenuItem(#MENU_Previous, "Previous")
MenuItem(#MENU_Next, "Next")
; MDI subwindows will get added here
FSW_DisableMenuTitle (MenuHWND, #MENU_Windows, 1) ; added
EndIf
If CreateToolBar(#TOOLBAR, WindowID())
ToolBarStandardButton(#MENU_Open, #PB_ToolBarIcon_Open)
ToolBarStandardButton(#MENU_Close, #PB_ToolBarIcon_Delete)
ToolBarSeparator()
ToolBarStandardButton(#MENU_Previous, #PB_ToolBarIcon_Undo)
ToolBarStandardButton(#MENU_Next, #PB_ToolBarIcon_Redo)
EndIf
If CreateGadgetList(WindowID())
MDIGadget(#GADGET_MDI, 0, 0, 0, 0, 1, #MENU_FirstMDI, #PB_MDI_Autosize)
AddKeyboardShortcut(#WINDOW, #PB_Shortcut_Control|#PB_Shortcut_F4, #MENU_Close) ; added
EndIf
Quit = 0
Repeat
Event = WaitWindowEvent()
If Event = #PB_Event_CloseWindow
Quit = 1
ElseIf Event = #PB_Event_Menu
Select EventMenuID()
Case #MENU_Open
FileName$ = OpenFileRequester("Open Image", DefautFile$, "Image Files (*.bmp,*.jpg,*.tiff,*.png,*.tga)|*.bmp;*.jpg;*.tiff;*.png;*.tga|All Files (*.*)|*.*", 0, #PB_Requester_MultiSelection)
While FileName$
DefaultFile$ = FileName$
Image = LoadImage(#PB_Any, FileName$)
If Image
LastElement(MDIWindow())
AddElement(MDIWindow())
Item = ListIndex(MDIWindow())
MDIWindow()\Image = Image
MDIWIndow()\ImageWidth = ImageWidth()
MDIWindow()\ImageHeight = ImageHeight()
AddGadgetItem(#GADGET_MDI, Item, FileName$)
SetGadgetItemAttribute(#GADGET_MDI, Item, #PB_MDI_ItemWidth, ImageWidth())
SetGadgetItemAttribute(#GADGET_MDI, Item, #PB_MDI_ItemHeight, ImageHeight())
Width = GetGadgetItemAttribute(#GADGET_MDI, Item, #PB_MDI_ItemWidth)
Height = GetGadgetItemAttribute(#GADGET_MDI, Item, #PB_MDI_ItemHeight)
MDIWindow()\ScrollAreaGadget = ScrollAreaGadget(#PB_Any, 0, 0, Width, Height, MDIWindow()\ImageWidth, MDIWindow()\ImageHeight, 10)
MDIWindow()\ImageGadget = ImageGadget(#PB_Any, 0, 0, MDIWindow()\ImageWidth, MDIWindow()\ImageHeight, ImageID())
CloseGadgetList()
Else
MessageRequester("Image Viewer","Could not load image: "+FileName$)
EndIf
FileName$ = NextSelectedFileName()
Wend
FSW_MDIChild = CountList(MDIWindow()) ; added
FSW_CheckMDI(MenuHWND, #MENU_Windows, FSW_MDIChild) ; added
Case #MENU_Close
Item = GetGadgetState(#GADGET_MDI)
If Item <> -1
RemoveGadgetItem(#GADGET_MDI, Item)
SelectElement(MDIWindow(), Item)
FreeImage(MDIWindow()\Image)
DeleteElement(MDIWindow())
FSW_MDIChild = CountList(MDIWindow()) ; added
FSW_CheckMDI(MenuHWND, #MENU_Windows, FSW_MDIChild) ; added
EndIf
Case #MENU_CloseAll
ClearGadgetItemList(#GADGET_MDI)
ForEach MDIWindow()
FreeImage(MDIWindow()\Image)
Next MDIWindow()
ClearList(MDIWindow())
FSW_MDIChild = CountList(MDIWindow()) ; added
FSW_CheckMDI(MenuHWND, #MENU_Windows, FSW_MDIChild) ; added
Case #MENU_Quit
Quit = 1
Case #MENU_TileV
SetGadgetState(#GADGET_MDI, #PB_MDI_TileVertically)
Case #MENU_TileH
SetGadgetState(#GADGET_MDI, #PB_MDI_TileHorizontally)
Case #MENU_Cascade
SetGadgetState(#GADGET_MDI, #PB_MDI_Cascade)
Case #MENU_Arrange
SetGadgetState(#GADGET_MDI, #PB_MDI_Arrange)
Case #MENU_Previous
SetGadgetState(#GADGET_MDI, #PB_MDI_Previous)
Case #MENU_Next
SetGadgetState(#GADGET_MDI, #PB_MDI_Next)
EndSelect
ElseIf Event = #PB_Event_Gadget
If EventGadgetID() = #GADGET_MDI
Type = EventType()
If Type = #PB_EventType_SizeItem
Item = GetGadgetAttribute(#GADGET_MDI, #PB_MDI_SizedItem)
Width = GetGadgetItemAttribute(#GADGET_MDI, Item, #PB_MDI_ItemWidth)
Height = GetGadgetItemAttribute(#GADGET_MDI, Item, #PB_MDI_ItemHeight)
SelectElement(MDIWindow(), Item)
ResizeGadget(MDIWindow()\ScrollAreaGadget, 0, 0, Width, Height)
ElseIf Type = #PB_EventType_CloseItem
Item = GetGadgetState(#GADGET_MDI)
RemoveGadgetItem(#GADGET_MDI, Item)
SelectElement(MDIWindow(), Item)
FreeImage(MDIWindow()\Image)
DeleteElement(MDIWindow())
FSW_MDIChild = CountList(MDIWindow()) ; added
FSW_CheckMDI(MenuHWND, #MENU_Windows, FSW_MDIChild) ; added
EndIf
EndIf
EndIf
Until Quit = 1
EndIf
Now this example looks pretty professional...