SetParent_() messes up my Child Window alignment

Just starting out? Need help? Post your questions and find answers here.
User avatar
Thunder93
Addict
Addict
Posts: 1788
Joined: Tue Mar 21, 2006 12:31 am
Location: Canada

SetParent_() messes up my Child Window alignment

Post by Thunder93 »

Hi. I suppose It's normal when using SetParent() WinAPI, the child window goes off centered from the parent window?

Code: Select all

If OpenWindow(0, 30, 120, 500, 600, "Parent Window", #PB_Window_SystemMenu | #PB_Window_MinimizeGadget | #PB_Window_SizeGadget |#PB_Window_MaximizeGadget) And
   OpenWindow(1, 0, 0, 200, 200, "Child Window", #PB_Window_WindowCentered)
  
    SetParent_(WindowID(1), WindowID(0))  ; REM Line to see it perfectly centered over initial Window.
  
  Repeat : Event = WaitWindowEvent() : Until Event = #PB_Event_CloseWindow  
EndIf
ʽʽSuccess is almost totally dependent upon drive and persistence. The extra energy required to make another effort or try another approach is the secret of winning.ʾʾ --Dennis Waitley
Julian
Enthusiast
Enthusiast
Posts: 276
Joined: Tue May 24, 2011 1:36 pm

Re: SetParent_() messes up my Child Window alignment

Post by Julian »

When you parent it like this, the x and y positions are then relative to the parent, not the screen. So it will never work, you'll need to re-centre in code after the SetParent_
User avatar
Thunder93
Addict
Addict
Posts: 1788
Joined: Tue Mar 21, 2006 12:31 am
Location: Canada

Re: SetParent_() messes up my Child Window alignment

Post by Thunder93 »

This is what I want though, center to the parent Window and not screen. Using SetParent() makes it fail, without it, works as expected.

You can actually see that using SetParent() actually causes it to jump from the center of the parent window.
ʽʽSuccess is almost totally dependent upon drive and persistence. The extra energy required to make another effort or try another approach is the secret of winning.ʾʾ --Dennis Waitley
User avatar
Thunder93
Addict
Addict
Posts: 1788
Joined: Tue Mar 21, 2006 12:31 am
Location: Canada

Re: SetParent_() messes up my Child Window alignment

Post by Thunder93 »

If the child window is set with borderless flag, no problem. If with system menu flag, then ResizeWindow() to move and center the child window is a requirement after SetParent API call. I was trying to avoid the extra step :twisted:

Code: Select all

If OpenWindow(0, 0, -1, 500, 600, "Parent Window", #PB_Window_SystemMenu | #PB_Window_MinimizeGadget | #PB_Window_SizeGadget |#PB_Window_MaximizeGadget) And
   OpenWindow(1, WindowWidth(0)/2-200/2, WindowHeight(0)/2-200/2, 200, 200, "Child Window", #PB_Window_BorderLess)
  SetWindowColor(1, $DB887E)
  
  SetParent_(WindowID(1), WindowID(0))  
  
  
  If OpenWindow(2, 520, -1, 500, 600, "Parent Window", #PB_Window_SystemMenu | #PB_Window_MinimizeGadget | #PB_Window_SizeGadget |#PB_Window_MaximizeGadget) And
     OpenWindow(3, 0, 0, 200, 200, "Child Window", #PB_Window_SystemMenu)  
    SetWindowColor(3, $DB887E)
    
    SetParent_(WindowID(3), WindowID(2))
    
    ResizeWindow(3, WindowWidth(2)/2-(WindowWidth(3, #PB_Window_FrameCoordinate)/2), WindowHeight(2)/2-(WindowHeight(3, #PB_Window_FrameCoordinate)/2), #PB_Ignore, #PB_Ignore) 
  EndIf
  
  Repeat : Event = WaitWindowEvent() : Until Event = #PB_Event_CloseWindow  
EndIf
ʽʽSuccess is almost totally dependent upon drive and persistence. The extra energy required to make another effort or try another approach is the secret of winning.ʾʾ --Dennis Waitley
Post Reply