WindowID

Just starting out? Need help? Post your questions and find answers here.
User avatar
braveheart
User
User
Posts: 37
Joined: Mon Jan 04, 2010 5:54 pm

WindowID

Post 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()
fabio
User
User
Posts: 11
Joined: Fri Jan 15, 2010 4:52 pm

Re: WindowID

Post 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
User avatar
braveheart
User
User
Posts: 37
Joined: Mon Jan 04, 2010 5:54 pm

Re: WindowID

Post 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.
fabio
User
User
Posts: 11
Joined: Fri Jan 15, 2010 4:52 pm

Re: WindowID

Post 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
rsts
Addict
Addict
Posts: 2736
Joined: Wed Aug 24, 2005 8:39 am
Location: Southwest OH - USA

Re: WindowID

Post 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
Last edited by rsts on Sat Jan 23, 2010 3:00 pm, edited 1 time in total.
User avatar
Kaeru Gaman
Addict
Addict
Posts: 4826
Joined: Sun Mar 19, 2006 1:57 pm
Location: Germany

Re: WindowID

Post by Kaeru Gaman »

@braveheart
I guess you mean modal...?

create Window2 as a Child of Window1 and Disable Window1.
oh... and have a nice day.
User avatar
braveheart
User
User
Posts: 37
Joined: Mon Jan 04, 2010 5:54 pm

Re: WindowID

Post 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
User avatar
Kaeru Gaman
Addict
Addict
Posts: 4826
Joined: Sun Mar 19, 2006 1:57 pm
Location: Germany

Re: WindowID

Post 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.
oh... and have a nice day.
fabio
User
User
Posts: 11
Joined: Fri Jan 15, 2010 4:52 pm

Re: WindowID

Post 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
User avatar
braveheart
User
User
Posts: 37
Joined: Mon Jan 04, 2010 5:54 pm

Re: WindowID

Post by braveheart »

@Kaeru Gaman, thanks.
@Fabio, That's very structured. Great work.
Post Reply