Get the parent window (cross platform)

Just starting out? Need help? Post your questions and find answers here.
mestnyi
Addict
Addict
Posts: 1102
Joined: Mon Nov 25, 2013 6:41 am

Get the parent window (cross platform)

Post by mestnyi »

Last edited by mestnyi on Thu Mar 03, 2022 7:11 pm, edited 1 time in total.
User avatar
ts-soft
Always Here
Always Here
Posts: 5756
Joined: Thu Jun 24, 2004 2:44 pm
Location: Berlin - Germany

Re: Get the parent window (cross platform)

Post by ts-soft »

Code: Select all

Debug UseGadgetList(0)
PureBasic 5.73 | SpiderBasic 2.30 | Windows 10 Pro (x64) | Linux Mint 20.1 (x64)
Old bugs good, new bugs bad! Updates are evil: might fix old bugs and introduce no new ones.
Image
mestnyi
Addict
Addict
Posts: 1102
Joined: Mon Nov 25, 2013 6:41 am

Re: Get the parent window (cross platform)

Post by mestnyi »

^
Last edited by mestnyi on Thu Mar 03, 2022 7:14 pm, edited 1 time in total.
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8452
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Re: Get the parent window (cross platform)

Post by netmaestro »

if you call this procedure right after you create a gadget, it will return the root window it was created on regardless of how deep it is. Then you can store it for future use. I can't come up with a crossplatform way to pass a gadget# to the procedure.

Code: Select all

Procedure GetRootWindow()
  savedgadgetlist = UseGadgetList(0)
  result = savedgadgetlist
  While (result<>lastresult) And result<>0
    result=UseGadgetList(result)
    If result
      lastresult=result
    EndIf
  Wend
  UseGadgetList(savedgadgetlist)
  ProcedureReturn lastresult
EndProcedure
BERESHEIT
mestnyi
Addict
Addict
Posts: 1102
Joined: Mon Nov 25, 2013 6:41 am

Re: Get the parent window (cross platform)

Post by mestnyi »

^
Last edited by mestnyi on Thu Mar 03, 2022 7:12 pm, edited 1 time in total.
mestnyi
Addict
Addict
Posts: 1102
Joined: Mon Nov 25, 2013 6:41 am

Re: Get the parent window (cross platform)

Post by mestnyi »

^
Last edited by mestnyi on Thu Mar 03, 2022 7:13 pm, edited 1 time in total.
User avatar
Bisonte
Addict
Addict
Posts: 1320
Joined: Tue Oct 09, 2007 2:15 am

Re: Get the parent window (cross platform)

Post by Bisonte »

I think he means : How to get the PB Object number crossplatform.... from a windows-handle ... to use e.g. PostEvent()
PureBasic 6.21 (Windows x64) | Windows 11 Pro | AsRock B850 Steel Legend Wifi | R7 9800x3D | 64GB RAM | RTX 5080 | ThermaltakeView 270 TG ARGB | build by vannicom​​
English is not my native language... (I often use DeepL.)
uweb
User
User
Posts: 98
Joined: Wed Mar 15, 2006 9:40 am
Location: Germany

Re: Get the parent window (cross platform)

Post by uweb »

I saw your question yesterday, but my englisch is not so good and ts-soft was quicker as i with a other interpretation of you question.
today i am again unsure. it is too simple, but may ...

Code: Select all

OpenWindow(1, 100, 200, 200, 100, "Window 1")
ButtonGadget  (101, 10, 10, 180, 20, "Hello")
ButtonGadget  (102, 10, 40, 180, 20, "World")


OpenWindow(2, 310, 200, 200, 100, "Window 2")
ButtonGadget  (201, 10, 10, 180, 20, "Hello")
ButtonGadget  (202, 10, 40, 180, 20, "World")


UseGadgetList(WindowID(1))
ButtonGadget  (103, 10, 70, 180, 20, "!")
UseGadgetList(WindowID(2))
ButtonGadget  (203, 10, 70, 180, 20, "?")


Repeat
  Event = WaitWindowEvent()
  If Event = #PB_Event_Gadget : GadgetEvent = EventGadget()
    If GadgetEvent > 200 : Debug WindowID(2) : ElseIf GadgetEvent > 100 : Debug WindowID(1) : EndIf
  EndIf
Until Event = #PB_Event_CloseWindow
Please pardon my English, my native tongue is German.
mestnyi
Addict
Addict
Posts: 1102
Joined: Mon Nov 25, 2013 6:41 am

Re: Get the parent window (cross platform)

Post by mestnyi »

^
Last edited by mestnyi on Thu Mar 03, 2022 7:12 pm, edited 1 time in total.
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4991
Joined: Sun Apr 12, 2009 6:27 am

Re: Get the parent window (cross platform)

Post by RASHAD »

Code: Select all

ExamineDesktops()


OpenWindow(1, 100, 200, 200, 100, "Window 1")
    ButtonGadget  (1, 10, 10, 180, 20, "1")
    SetGadgetData(1,1)
    ButtonGadget  (2, 10, 40, 180, 20, "2")
    SetGadgetData(2,1)

OpenWindow(2, 310, 200, 200, 100, "Window 2")
    ButtonGadget  (3, 10, 10, 180, 20, "3")
    SetGadgetData(3,2)
    ButtonGadget  (4, 10, 40, 180, 20, "4")
    SetGadgetData(4,2)

UseGadgetList(WindowID(1))
ButtonGadget  (5, 10, 70, 180, 20, "5")
SetGadgetData(5,1)


UseGadgetList(WindowID(2))
ButtonGadget  (6, 10, 70, 180, 20, "6")
SetGadgetData(6,2)


Repeat
  
  Select WaitWindowEvent()
      
      Case #PB_Event_CloseWindow
            Quit = 1
      
      Case #PB_Event_Gadget
          Select EventGadget()
           Case 1            
          EndSelect
          
      Default
         x = DesktopMouseX()
         y = DesktopMouseY()

        For g = 1 To 6
            If x >= GadgetX(g,#PB_Gadget_ScreenCoordinate) And x < GadgetX(g,#PB_Gadget_ScreenCoordinate) + GadgetWidth(g) And y >= GadgetY(g,#PB_Gadget_ScreenCoordinate) And y < GadgetY(g,#PB_Gadget_ScreenCoordinate) + GadgetHeight(g)
               If g <> oldg
                  Debug "Parent Window is : Window "+Str(GetGadgetData(g))
                  oldg = g  
               EndIf
              ; MessageRequester("Info","Parent Window is : Window "+Str(GetGadgetData(g)),#PB_MessageRequester_Ok)
            EndIf
        Next         

             
  EndSelect 

Until Quit = 1
End
Egypt my love
IdeasVacuum
Always Here
Always Here
Posts: 6426
Joined: Fri Oct 23, 2009 2:33 am
Location: Wales, UK
Contact:

Re: Get the parent window (cross platform)

Post by IdeasVacuum »

That is something worth knowing - I always thought SetGadgetData() was Windows only. It is certainly very handy for this purpose, as Rashad has shown.
IdeasVacuum
If it sounds simple, you have not grasped the complexity.
davido
Addict
Addict
Posts: 1890
Joined: Fri Nov 09, 2012 11:04 pm
Location: Uttoxeter, UK

Re: Get the parent window (cross platform)

Post by davido »

@RASHAD

Very nice. Thank you for sharing. :D
DE AA EB
mestnyi
Addict
Addict
Posts: 1102
Joined: Mon Nov 25, 2013 6:41 am

Re: Set parent and get parent for the all gadgets (cross platform)

Post by mestnyi »

^
Post Reply