Page 1 of 1
WindowID
Posted: Sat Jan 23, 2010 9:19 am
by braveheart
Hi,
i create 2 windows, how to get the event for windows number 2?
Code: Select all
Procedure fnWindow()
OpenWindow(#window2)
EndProcedure
OpenWindow(#window1)
ButtonGadget(#button1)
Repeat
myEvent = WaitWindowEvent()
If myEvent = #PB_Event_Gadget()
If EventGadget() = #button1
fnWindow()
Re: WindowID
Posted: Sat Jan 23, 2010 9:35 am
by fabio
Something like this:
Code: Select all
Repeat
EventID = WaitWindowEvent()
Window = EventWindow()
Select EventID
Case #PB_Event_CloseWindow
Select Window
Case #Window_1 : Quit = 1
Case #Window_2 : CloseWindow(#Window_2)
EndSelect
EndSelect
Until Quit = 1
Fabio
Re: WindowID
Posted: Sat Jan 23, 2010 10:07 am
by braveheart
Thanks fabio, it works. Do you know how to make #window2 sticky? i tried StickyWindow(#window2,1) but i can still drag #window1.
Re: WindowID
Posted: Sat Jan 23, 2010 10:31 am
by fabio
I'm not sure what do you mean, I gess you want to disable #Window_1 while #Window_2 is running. That's your question?
Fabio
Re: WindowID
Posted: Sat Jan 23, 2010 2:28 pm
by rsts
Got code?
working with the snippets above.
Code: Select all
enumeration
#window1
#window2
#button1
EndEnumeration
Procedure fnWindow()
OpenWindow(#window2,10,10,100,100,"win2")
stickywindow(#window2,1)
DisableWindow((#window1),#True)
EndProcedure
OpenWindow(#window1,200,200,100,100,"Win1")
ButtonGadget(#button1,10,10,60,20,"OK")
fnWindow()
Repeat
EventID = WaitWindowEvent()
Window = EventWindow()
Select EventID
Case #PB_Event_CloseWindow
Select Window
Case #Window1 : Quit = 1
Case #Window2 : DisableWindow((#window1),#False):CloseWindow(#Window2)
EndSelect
EndSelect
Until Quit = 1
cheers
Re: WindowID
Posted: Sat Jan 23, 2010 2:49 pm
by Kaeru Gaman
@braveheart
I guess you mean modal...?
create Window2 as a Child of Window1 and Disable Window1.
Re: WindowID
Posted: Sat Jan 23, 2010 4:20 pm
by braveheart
@Fabio, yes that's what i mean.
@rsts, that's it.
@Kaeru Gaman, I'm not sure for modal, sorry i'm newbie. Can we call this window2 as a child?
Code: Select all
;adapted from @rsts
Enumeration
#window1
#window2
#button1
EndEnumeration
Procedure fnWindow()
OpenWindow(#window2,10,10,100,100,"win2")
StickyWindow(#window2,1)
DisableWindow((#window1),#True)
EndProcedure
OpenWindow(#window1,200,200,100,100,"Win1")
ButtonGadget(#button1,10,10,60,20,"OK")
Repeat
EventID = WaitWindowEvent()
Window = EventWindow()
Select EventID
Case #PB_Event_CloseWindow
Select Window
Case #Window1 : Quit = 1
Case #Window2 : DisableWindow((#window1),#False):CloseWindow(#Window2)
EndSelect
Case #PB_Event_Gadget
Select EventGadget()
Case #button1 : fnWindow()
EndSelect
EndSelect
Until Quit = 1
Re: WindowID
Posted: Sat Jan 23, 2010 4:31 pm
by Kaeru Gaman
seems it's not really necessary to make 2 a child of 1...
if you wanted to do so, this is what the line would look like:
Code: Select all
OpenWindow(#window2,10,10, 120,100,"win2", #PB_Window_SystemMenu | #PB_Window_WindowCentered, WindowID(#window1))
e.g. it allows to open the second window centered to the first.
yes, this is what is called "modal" in MS-Windows terms.
Re: WindowID
Posted: Sat Jan 23, 2010 6:56 pm
by fabio
Hi, a few days ago I was just trying to imitate the behavior of a modal dialog box.
This was the result:
Code: Select all
; DIALOG EMULATION
;- Window Constants
;
Enumeration
#Window_0 = 1
#Window_1
#Window_2
EndEnumeration
;- Gadget Constants
;
Enumeration
#Button_0
#Button_1
#Button_2
#Button_3
EndEnumeration
Procedure Open_Window_0()
If OpenWindow(#Window_0, 237, 44, 519, 410, "Main", #PB_Window_SystemMenu | #PB_Window_SizeGadget | #PB_Window_TitleBar )
ButtonGadget(#Button_0, 200, 360, 140, 30, "Show Dialog!")
EndIf
EndProcedure
Procedure Open_Window_1(parentid)
If OpenWindow(#Window_1, 357, 104, 308, 202, "Dialog", #PB_Window_SystemMenu | #PB_Window_SizeGadget | #PB_Window_TitleBar, WindowID(parentid) )
ButtonGadget(#Button_1, 120, 160, 60, 30, "&OK")
ButtonGadget(#Button_2, 70, 50, 160, 30, "Other Dialog!")
EndIf
EndProcedure
Procedure Open_Window_2(parentid)
If OpenWindow(#Window_2, 403, 117, 226, 179, "Other Dialog", #PB_Window_SystemMenu | #PB_Window_SizeGadget | #PB_Window_TitleBar, WindowID(parentid) )
ButtonGadget(#Button_3, 70, 140, 90, 30, "Close")
EndIf
EndProcedure
Procedure StartModal(diagid, parentid)
Select diagid
Case #Window_1
Open_Window_1(parentid)
Case #Window_2
Open_Window_2(parentid)
EndSelect
DisableWindow(parentid, 1)
EndProcedure
Procedure StopModal(diagid, parentid)
CloseWindow(diagid)
DisableWindow(parentid, 0)
EndProcedure
; ------------------------------------------------------------------
Open_Window_0()
Repeat
EventID = WaitWindowEvent()
Window = EventWindow()
Select EventID
Case #PB_Event_Gadget
Select EventGadget()
Case #Button_0
StartModal(#Window_1, #Window_0)
Case #Button_1
StopModal(#Window_1, #Window_0)
Case #Button_2
StartModal(#Window_2, #Window_1)
Case #Button_3
StopModal(#Window_2, #Window_1)
EndSelect
Case #PB_Event_CloseWindow
Select Window
Case #Window_0 : Quit = 1
Case #Window_1 : StopModal(#Window_1, #Window_0)
Case #Window_2 : StopModal(#Window_2, #Window_1)
EndSelect
EndSelect
Until Quit = 1
Fabio
Re: WindowID
Posted: Sat Jan 23, 2010 9:04 pm
by braveheart
@Kaeru Gaman, thanks.
@Fabio, That's very structured. Great work.